@@ -13,6 +13,7 @@ export class NodeKernel {
13
13
private nodeRuntime : cp . ChildProcess | undefined ;
14
14
private outputBuffer = '' ; // collect output here
15
15
private hasRuntimeError = false ;
16
+ private outputKeys = '' ;
16
17
private tmpDirectory ?: string ;
17
18
18
19
public async start ( ) {
@@ -32,6 +33,9 @@ export class NodeKernel {
32
33
} else if ( dataStr . includes ( '\nUncaught' ) ) {
33
34
this . hasRuntimeError = true ;
34
35
this . outputBuffer += dataStr ;
36
+ } else if ( dataStr . includes ( '#keys#' ) ) {
37
+ this . outputKeys = dataStr . substring ( 7 ) ;
38
+ console . log ( 'outputKeys ======' , this . outputKeys ) ;
35
39
} else {
36
40
this . outputBuffer += dataStr ;
37
41
}
@@ -53,12 +57,19 @@ export class NodeKernel {
53
57
const cellPath = cell . document . languageId === 'xpath' ? this . dumpCell ( cell ) : this . dumpCell ( cell ) ; // TODO: dumpJSCell
54
58
if ( cellPath && this . nodeRuntime && this . nodeRuntime . stdin ) {
55
59
this . outputBuffer = '' ;
60
+ this . outputKeys = '' ;
56
61
this . hasRuntimeError = false ;
57
62
58
63
this . nodeRuntime . stdin . write ( `.load ${ cellPath } \n` ) ;
59
64
while ( this . outputBuffer === '' ) {
60
65
await this . sleep ( 100 ) ;
61
66
}
67
+ if ( ! this . hasRuntimeError ) {
68
+ this . nodeRuntime . stdin . write ( `globalVariables.getKeysJSON()\n` ) ;
69
+ while ( this . outputKeys === '' ) {
70
+ await this . sleep ( 100 ) ;
71
+ }
72
+ }
62
73
63
74
if ( this . hasRuntimeError ) {
64
75
return Promise . reject ( this . outputBuffer ) ;
@@ -173,6 +184,9 @@ console.log(prevResult);
173
184
getKeys = () => {
174
185
return this.keys;
175
186
}
187
+ getKeysJSON = () => {
188
+ return '#keys#' + JSON.stringify(this.keys);
189
+ }
176
190
getVariables = () => {
177
191
return this.variables;
178
192
}
0 commit comments