@nu-art/commando 0.204.17 → 0.204.19

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.
@@ -1,14 +1,14 @@
1
1
  import { ResolvableContent } from '@nu-art/ts-common';
2
2
  import { BoxOptions, ScreenOptions, WidgetTypes } from './types';
3
- import * as blessed from 'neo-blessed';
4
- export declare abstract class Screen<State extends object> {
3
+ export declare abstract class ConsoleScreen<State extends object> {
5
4
  protected state: State;
6
5
  private screen;
7
- protected readonly widgets: blessed.Widgets.Node[];
6
+ protected readonly widgets: any[];
8
7
  constructor(props?: ScreenOptions);
9
- setState(state: ResolvableContent<Partial<State>>): void;
8
+ setState(state: ResolvableContent<Partial<State>>): this;
10
9
  createWidget(type: WidgetTypes, props: Omit<BoxOptions, 'parent'>): any;
11
10
  getFocusedWidget(): any;
11
+ private _render;
12
12
  protected abstract render(): void;
13
13
  enable(): void;
14
14
  disable(): void;
@@ -23,11 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.Screen = void 0;
27
- const ts_common_1 = require("@nu-art/ts-common");
26
+ exports.ConsoleScreen = void 0;
28
27
  // @ts-ignore
29
28
  const blessed = __importStar(require("neo-blessed"));
30
- class Screen {
29
+ const ts_common_1 = require("@nu-art/ts-common");
30
+ class ConsoleScreen {
31
31
  constructor(props) {
32
32
  var _a;
33
33
  this.widgets = [];
@@ -37,8 +37,9 @@ class Screen {
37
37
  });
38
38
  }
39
39
  setState(state) {
40
- this.state = Object.freeze((0, ts_common_1.mergeObject)(this.state, state));
41
- this.render();
40
+ this.state = (0, ts_common_1.mergeObject)(this.state, state);
41
+ this._render();
42
+ return this;
42
43
  }
43
44
  createWidget(type, props) {
44
45
  const widget = blessed[type](Object.assign(Object.assign({}, props), { parent: this.screen }));
@@ -48,30 +49,31 @@ class Screen {
48
49
  getFocusedWidget() {
49
50
  return this.screen.focused;
50
51
  }
52
+ _render() {
53
+ this.screen.render();
54
+ this.render();
55
+ }
51
56
  enable() {
52
57
  this.widgets.forEach(widget => {
53
58
  widget.focusable = true;
54
59
  widget.interactive = true;
55
60
  });
56
- this.screen.render();
61
+ this._render();
57
62
  }
58
63
  disable() {
59
64
  this.widgets.forEach(widget => {
60
65
  widget.focusable = false;
61
66
  widget.interactive = false;
62
67
  });
63
- this.screen.render();
68
+ this._render();
64
69
  }
65
70
  /**
66
71
  * Clears all widgets from the screen and optionally clears the screen.
67
72
  */
68
73
  clearScreen(clearContent = true) {
69
74
  this.widgets.forEach(widget => widget.detach());
70
- this.widgets.forEach(widget => (0, ts_common_1.removeFromArray)(this.widgets, widget));
71
- if (clearContent) {
72
- this.screen.clear();
73
- }
74
- this.screen.render();
75
+ // @ts-ignore
76
+ this.widgets = [];
75
77
  }
76
78
  }
77
- exports.Screen = Screen;
79
+ exports.ConsoleScreen = ConsoleScreen;
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- import * as blessed from 'neo-blessed';
3
2
  /**
4
3
  * Styles configuration for the box component.
5
4
  */
@@ -50,7 +49,7 @@ export type BoxStyle = {
50
49
  */
51
50
  export type BoxOptions = {
52
51
  /** Parent screen object. */
53
- parent?: blessed.Widgets.Screen;
52
+ parent?: any;
54
53
  /** Top position (can be in pixels or percentage). */
55
54
  top?: number | string;
56
55
  /** Left position (can be in pixels or percentage). */
@@ -139,7 +138,7 @@ export type ScreenOptions = {
139
138
  output?: NodeJS.WritableStream;
140
139
  /** Time in milliseconds to wait after a resize event before redrawing the screen. */
141
140
  resizeTimeout?: number;
142
- keyBinding: {
141
+ keyBinding?: {
143
142
  keys: string[];
144
143
  callback: VoidFunction;
145
144
  }[];
package/core/cli.d.ts CHANGED
@@ -18,6 +18,7 @@ export declare class BaseCLI extends Logger {
18
18
  private indentation;
19
19
  protected _debug: boolean;
20
20
  protected option: Options;
21
+ protected uid: string;
21
22
  /**
22
23
  * Constructs a CLI instance with given options.
23
24
  * @param {Options} options - Configuration options for the CLI instance.
@@ -33,6 +34,7 @@ export declare class BaseCLI extends Logger {
33
34
  * @returns {this} - The Cli instance for method chaining.
34
35
  */
35
36
  readonly append: (command: string) => this;
37
+ setUID(uuid: string): void;
36
38
  }
37
39
  export declare class CliInteractive extends BaseCLI {
38
40
  private shell;
@@ -68,6 +70,7 @@ export declare class Commando {
68
70
  setOptions: (options: ExecOptions) => this;
69
71
  debug: (debug?: boolean) => this;
70
72
  append: (command: string) => this;
73
+ setUID: (uid: string) => this;
71
74
  execute: () => Promise<{
72
75
  stdout: string;
73
76
  stderr: string;
@@ -93,6 +96,7 @@ export declare class Commando {
93
96
  export declare class CommandoInteractive {
94
97
  cli: CliInteractive;
95
98
  static create<T extends Constructor<CliWrapper>[]>(...plugins: T): CommandoInteractive & Commando & import("./class-merger").MergeTypes<T>;
99
+ setUID: (uid: string) => this;
96
100
  close: () => this;
97
101
  }
98
102
  export {};
package/core/cli.js CHANGED
@@ -23,6 +23,7 @@ class BaseCLI extends ts_common_1.Logger {
23
23
  this.commands = [];
24
24
  this.indentation = 0;
25
25
  this._debug = false;
26
+ this.uid = (0, ts_common_1.generateHex)((8));
26
27
  this.getIndentation = () => {
27
28
  return ' '.repeat(this.option.indentation * this.indentation);
28
29
  };
@@ -48,6 +49,9 @@ class BaseCLI extends ts_common_1.Logger {
48
49
  this._debug = debug !== null && debug !== void 0 ? debug : !this._debug;
49
50
  return this._debug;
50
51
  }
52
+ setUID(uuid) {
53
+ this.setTag(uuid);
54
+ }
51
55
  }
52
56
  exports.BaseCLI = BaseCLI;
53
57
  class CliInteractive extends BaseCLI {
@@ -59,7 +63,7 @@ class CliInteractive extends BaseCLI {
59
63
  this.logDebug(`executing: `, `"""\n${command}\n"""`);
60
64
  this.shell.stdin.write(command + this.option.newlineDelimiter, 'utf-8', (err) => {
61
65
  if (err)
62
- ts_common_1.StaticLogger.logError('error', err);
66
+ this.logError(`error`, err);
63
67
  });
64
68
  this.commands = [];
65
69
  };
@@ -72,7 +76,7 @@ class CliInteractive extends BaseCLI {
72
76
  const message = data.toString().trim();
73
77
  if (!message.length)
74
78
  return;
75
- ts_common_1.StaticLogger.logInfo(message);
79
+ this.logInfo(`${message}`);
76
80
  };
77
81
  this.shell.stdout.on('data', printer);
78
82
  this.shell.stderr.on('data', printer);
@@ -80,7 +84,7 @@ class CliInteractive extends BaseCLI {
80
84
  this.shell.on('data', printer);
81
85
  // Handle shell exit
82
86
  this.shell.on('close', (code) => {
83
- ts_common_1.StaticLogger.logInfo(`child process exited with code ${code}`);
87
+ this.logInfo(`child process exited with code ${code}`);
84
88
  });
85
89
  }
86
90
  }
@@ -168,6 +172,10 @@ class Commando {
168
172
  commando.cli.append(command);
169
173
  return commando;
170
174
  };
175
+ commando.setUID = (uid) => {
176
+ commando.cli.setUID(uid);
177
+ return commando;
178
+ };
171
179
  return commando;
172
180
  }
173
181
  constructor() {
@@ -175,6 +183,7 @@ class Commando {
175
183
  this.setOptions = (options) => this;
176
184
  this.debug = (debug) => this;
177
185
  this.append = (command) => this;
186
+ this.setUID = (uid) => this;
178
187
  this.execute = async () => ({ stdout: '', stderr: '', }); // placeholder
179
188
  /**
180
189
  * Executes a given file.
@@ -191,6 +200,7 @@ class Commando {
191
200
  exports.Commando = Commando;
192
201
  class CommandoInteractive {
193
202
  constructor() {
203
+ this.setUID = (uid) => this;
194
204
  this.close = () => this;
195
205
  }
196
206
  static create(...plugins) {
@@ -199,6 +209,10 @@ class CommandoInteractive {
199
209
  const cli = new CliInteractive();
200
210
  cli.setMinLevel(ts_common_1.LogLevel.Verbose);
201
211
  commando.cli = cli;
212
+ commando.setUID = (uid) => {
213
+ commando.cli.setUID(uid);
214
+ return commando;
215
+ };
202
216
  commando.close = () => {
203
217
  return commando;
204
218
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/commando",
3
- "version": "0.204.17",
3
+ "version": "0.204.19",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",
File without changes