greybel-interpreter 2.0.2 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts +3 -1
- package/dist/context.js +6 -2
- package/dist/handler/output.d.ts +11 -10
- package/dist/handler/output.js +5 -5
- package/package.json +1 -1
package/dist/context.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ASTBase } from 'greyscript-core';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
2
4
|
import { CPS } from './cps';
|
|
3
5
|
import { HandlerContainer } from './handler-container';
|
|
4
6
|
import { Operation } from './operations/operation';
|
|
@@ -37,7 +39,7 @@ export declare class Debugger {
|
|
|
37
39
|
resume(): Promise<void>;
|
|
38
40
|
interact(ctx: OperationContext, _ast: ASTBase, _op: Operation): void;
|
|
39
41
|
}
|
|
40
|
-
export declare class ProcessState {
|
|
42
|
+
export declare class ProcessState extends EventEmitter {
|
|
41
43
|
isExit: boolean;
|
|
42
44
|
isPending: boolean;
|
|
43
45
|
last: OperationContext;
|
package/dist/context.js
CHANGED
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.OperationContext = exports.FunctionState = exports.LoopState = exports.ProcessState = exports.Debugger = exports.Scope = exports.ContextState = exports.ContextType = void 0;
|
|
13
|
+
const events_1 = require("events");
|
|
13
14
|
const handler_container_1 = require("./handler-container");
|
|
14
15
|
const noop_1 = require("./operations/noop");
|
|
15
16
|
const operation_1 = require("./operations/operation");
|
|
@@ -115,8 +116,9 @@ class Debugger {
|
|
|
115
116
|
}
|
|
116
117
|
}
|
|
117
118
|
exports.Debugger = Debugger;
|
|
118
|
-
class ProcessState {
|
|
119
|
+
class ProcessState extends events_1.EventEmitter {
|
|
119
120
|
constructor() {
|
|
121
|
+
super(...arguments);
|
|
120
122
|
this.isExit = false;
|
|
121
123
|
this.isPending = false;
|
|
122
124
|
/* eslint-disable no-use-before-define */
|
|
@@ -174,6 +176,7 @@ class OperationContext {
|
|
|
174
176
|
this.target = op.target || this.target;
|
|
175
177
|
this.setLastActive(this);
|
|
176
178
|
if (this.debugger.getBreakpoint(this)) {
|
|
179
|
+
this.processState.emit('breakpoint');
|
|
177
180
|
this.debugger.interact(this, op.item, op);
|
|
178
181
|
yield this.debugger.resume();
|
|
179
182
|
}
|
|
@@ -220,6 +223,7 @@ class OperationContext {
|
|
|
220
223
|
exit() {
|
|
221
224
|
if (this.processState.isPending) {
|
|
222
225
|
this.processState.isExit = true;
|
|
226
|
+
this.processState.emit('exit');
|
|
223
227
|
return new Promise((resolve) => {
|
|
224
228
|
const check = () => {
|
|
225
229
|
if (!this.processState.isPending) {
|
|
@@ -227,7 +231,7 @@ class OperationContext {
|
|
|
227
231
|
resolve(this);
|
|
228
232
|
}
|
|
229
233
|
else {
|
|
230
|
-
setTimeout(check);
|
|
234
|
+
setTimeout(check, 0);
|
|
231
235
|
}
|
|
232
236
|
};
|
|
233
237
|
check();
|
package/dist/handler/output.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { OperationContext } from '../context';
|
|
1
2
|
export interface KeyEvent {
|
|
2
3
|
keyCode: number;
|
|
3
4
|
code: string;
|
|
@@ -7,16 +8,16 @@ export interface PrintOptions {
|
|
|
7
8
|
replace: boolean;
|
|
8
9
|
}
|
|
9
10
|
export declare abstract class OutputHandler {
|
|
10
|
-
abstract print(message: string, options?: Partial<PrintOptions>): void;
|
|
11
|
-
abstract progress(timeout: number): PromiseLike<void>;
|
|
12
|
-
abstract waitForInput(isPassword: boolean, message?: string): PromiseLike<string>;
|
|
13
|
-
abstract waitForKeyPress(message?: string): PromiseLike<KeyEvent>;
|
|
14
|
-
abstract clear(): void;
|
|
11
|
+
abstract print(ctx: OperationContext, message: string, options?: Partial<PrintOptions>): void;
|
|
12
|
+
abstract progress(ctx: OperationContext, timeout: number): PromiseLike<void>;
|
|
13
|
+
abstract waitForInput(ctx: OperationContext, isPassword: boolean, message?: string): PromiseLike<string>;
|
|
14
|
+
abstract waitForKeyPress(ctx: OperationContext, message?: string): PromiseLike<KeyEvent>;
|
|
15
|
+
abstract clear(ctx: OperationContext): void;
|
|
15
16
|
}
|
|
16
17
|
export declare class DefaultOutputHandler extends OutputHandler {
|
|
17
|
-
print(message: string, { appendNewLine }?: Partial<PrintOptions>): void;
|
|
18
|
-
progress(timeout: number): PromiseLike<void>;
|
|
19
|
-
waitForInput(_isPassword: boolean, _message?: string): PromiseLike<string>;
|
|
20
|
-
waitForKeyPress(_message?: string): PromiseLike<KeyEvent>;
|
|
21
|
-
clear(): void;
|
|
18
|
+
print(_ctx: OperationContext, message: string, { appendNewLine }?: Partial<PrintOptions>): void;
|
|
19
|
+
progress(_ctx: OperationContext, timeout: number): PromiseLike<void>;
|
|
20
|
+
waitForInput(_ctx: OperationContext, _isPassword: boolean, _message?: string): PromiseLike<string>;
|
|
21
|
+
waitForKeyPress(_ctx: OperationContext, _message?: string): PromiseLike<KeyEvent>;
|
|
22
|
+
clear(_ctx: OperationContext): void;
|
|
22
23
|
}
|
package/dist/handler/output.js
CHANGED
|
@@ -5,7 +5,7 @@ class OutputHandler {
|
|
|
5
5
|
}
|
|
6
6
|
exports.OutputHandler = OutputHandler;
|
|
7
7
|
class DefaultOutputHandler extends OutputHandler {
|
|
8
|
-
print(message, { appendNewLine = true } = {}) {
|
|
8
|
+
print(_ctx, message, { appendNewLine = true } = {}) {
|
|
9
9
|
if (appendNewLine) {
|
|
10
10
|
process.stdout.write(message + '\n');
|
|
11
11
|
}
|
|
@@ -13,21 +13,21 @@ class DefaultOutputHandler extends OutputHandler {
|
|
|
13
13
|
process.stdout.write(message);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
progress(timeout) {
|
|
16
|
+
progress(_ctx, timeout) {
|
|
17
17
|
return new Promise((resolve, _reject) => {
|
|
18
18
|
setTimeout(resolve, timeout);
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
waitForInput(_isPassword, _message) {
|
|
21
|
+
waitForInput(_ctx, _isPassword, _message) {
|
|
22
22
|
return Promise.resolve('test');
|
|
23
23
|
}
|
|
24
|
-
waitForKeyPress(_message) {
|
|
24
|
+
waitForKeyPress(_ctx, _message) {
|
|
25
25
|
return Promise.resolve({
|
|
26
26
|
keyCode: 13,
|
|
27
27
|
code: 'Enter'
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
-
clear() {
|
|
30
|
+
clear(_ctx) {
|
|
31
31
|
console.clear();
|
|
32
32
|
}
|
|
33
33
|
}
|