greybel-interpreter 4.1.3 → 4.2.1

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.
@@ -8,8 +8,13 @@ export interface PrintOptions {
8
8
  appendNewLine: boolean;
9
9
  replace: boolean;
10
10
  }
11
+ export interface UpdateOptions {
12
+ appendNewLine: boolean;
13
+ replace: boolean;
14
+ }
11
15
  export declare abstract class OutputHandler {
12
16
  abstract print(vm: VM, message: string, options?: Partial<PrintOptions>): void;
17
+ abstract update(vm: VM, message: string, options?: Partial<UpdateOptions>): void;
13
18
  abstract progress(vm: VM, timeout: number): PromiseLike<void>;
14
19
  abstract waitForInput(vm: VM, isPassword: boolean, message?: string): PromiseLike<string>;
15
20
  abstract waitForKeyPress(vm: VM, message?: string): PromiseLike<KeyEvent>;
@@ -17,6 +22,7 @@ export declare abstract class OutputHandler {
17
22
  }
18
23
  export declare class DefaultOutputHandler extends OutputHandler {
19
24
  print(_vm: VM, message: string, { appendNewLine }?: Partial<PrintOptions>): void;
25
+ update(_vm: VM, message: string, { appendNewLine, replace }?: Partial<UpdateOptions>): void;
20
26
  progress(_vm: VM, timeout: number): PromiseLike<void>;
21
27
  waitForInput(_vm: VM, _isPassword: boolean, _message?: string): PromiseLike<string>;
22
28
  waitForKeyPress(_vm: VM, _message?: string): PromiseLike<KeyEvent>;
@@ -13,6 +13,14 @@ class DefaultOutputHandler extends OutputHandler {
13
13
  process.stdout.write(message);
14
14
  }
15
15
  }
16
+ update(_vm, message, { appendNewLine = false, replace = false } = {}) {
17
+ if (replace) {
18
+ process.stdout.write('\x1b[2K\r' + message + (appendNewLine ? '\n' : ''));
19
+ }
20
+ else {
21
+ process.stdout.write(message + (appendNewLine ? '\n' : ''));
22
+ }
23
+ }
16
24
  progress(_vm, timeout) {
17
25
  return new Promise((resolve, _reject) => {
18
26
  setTimeout(resolve, timeout);
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export { ContextForkOptions, ContextOptions, ContextType, OperationContext, Scope } from './context';
2
2
  export { DefaultErrorHandler, ErrorHandler } from './handler/error';
3
- export { DefaultOutputHandler, KeyEvent, OutputHandler, PrintOptions } from './handler/output';
3
+ export { DefaultOutputHandler, KeyEvent, OutputHandler, PrintOptions, UpdateOptions } from './handler/output';
4
4
  export { DefaultResourceHandler, ResourceHandler } from './handler/resource';
5
5
  export { HandlerContainer } from './handler-container';
6
6
  export { Interpreter, InterpreterOptions } from './interpreter';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "greybel-interpreter",
3
- "version": "4.1.3",
3
+ "version": "4.2.1",
4
4
  "description": "Interpreter",
5
5
  "main": "dist/index",
6
6
  "typings": "dist/index",