@nu-art/commando 0.204.18 → 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.
@@ -5,7 +5,7 @@ export declare abstract class ConsoleScreen<State extends object> {
5
5
  private screen;
6
6
  protected readonly widgets: any[];
7
7
  constructor(props?: ScreenOptions);
8
- setState(state: ResolvableContent<Partial<State>>): void;
8
+ setState(state: ResolvableContent<Partial<State>>): this;
9
9
  createWidget(type: WidgetTypes, props: Omit<BoxOptions, 'parent'>): any;
10
10
  getFocusedWidget(): any;
11
11
  private _render;
@@ -1,14 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.ConsoleScreen = void 0;
4
27
  // @ts-ignore
5
- const neo_blessed_1 = require("neo-blessed");
28
+ const blessed = __importStar(require("neo-blessed"));
6
29
  const ts_common_1 = require("@nu-art/ts-common");
7
30
  class ConsoleScreen {
8
31
  constructor(props) {
9
32
  var _a;
10
33
  this.widgets = [];
11
- this.screen = neo_blessed_1.blessed.screen(props);
34
+ this.screen = blessed.screen(props);
12
35
  (_a = props === null || props === void 0 ? void 0 : props.keyBinding) === null || _a === void 0 ? void 0 : _a.map(keyBinding => {
13
36
  this.screen.key(keyBinding.keys, keyBinding.callback);
14
37
  });
@@ -16,9 +39,10 @@ class ConsoleScreen {
16
39
  setState(state) {
17
40
  this.state = (0, ts_common_1.mergeObject)(this.state, state);
18
41
  this._render();
42
+ return this;
19
43
  }
20
44
  createWidget(type, props) {
21
- const widget = neo_blessed_1.blessed[type](Object.assign(Object.assign({}, props), { parent: this.screen }));
45
+ const widget = blessed[type](Object.assign(Object.assign({}, props), { parent: this.screen }));
22
46
  this.widgets.push(widget);
23
47
  return widget;
24
48
  }
@@ -26,8 +50,8 @@ class ConsoleScreen {
26
50
  return this.screen.focused;
27
51
  }
28
52
  _render() {
29
- this.render();
30
53
  this.screen.render();
54
+ this.render();
31
55
  }
32
56
  enable() {
33
57
  this.widgets.forEach(widget => {
@@ -48,11 +72,8 @@ class ConsoleScreen {
48
72
  */
49
73
  clearScreen(clearContent = true) {
50
74
  this.widgets.forEach(widget => widget.detach());
51
- this.widgets.forEach(widget => (0, ts_common_1.removeFromArray)(this.widgets, widget));
52
- if (clearContent) {
53
- this.screen.clear();
54
- }
55
- this._render();
75
+ // @ts-ignore
76
+ this.widgets = [];
56
77
  }
57
78
  }
58
79
  exports.ConsoleScreen = ConsoleScreen;
@@ -138,7 +138,7 @@ export type ScreenOptions = {
138
138
  output?: NodeJS.WritableStream;
139
139
  /** Time in milliseconds to wait after a resize event before redrawing the screen. */
140
140
  resizeTimeout?: number;
141
- keyBinding: {
141
+ keyBinding?: {
142
142
  keys: string[];
143
143
  callback: VoidFunction;
144
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.18",
3
+ "version": "0.204.19",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",