@nu-art/commando 0.204.25 → 0.204.26

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,6 +1,8 @@
1
- import { ResolvableContent } from '@nu-art/ts-common';
1
+ import { Logger, ResolvableContent } from '@nu-art/ts-common';
2
2
  import { BoxOptions, ScreenOptions, WidgetTypes } from './types';
3
- export declare abstract class ConsoleScreen<State extends object> {
3
+ export declare abstract class ConsoleScreen<State extends object> extends Logger {
4
+ private readonly screenProps;
5
+ private enabled;
4
6
  protected state: State;
5
7
  private screen;
6
8
  protected readonly widgets: any[];
@@ -8,12 +10,13 @@ export declare abstract class ConsoleScreen<State extends object> {
8
10
  setState(state: ResolvableContent<Partial<State>>): this;
9
11
  createWidget(type: WidgetTypes, props: Omit<BoxOptions, 'parent'>): any;
10
12
  getFocusedWidget(): any;
13
+ private createScreen;
14
+ private _createWidgets;
15
+ protected abstract createWidgets(): void;
16
+ readonly create: () => this;
17
+ readonly resume: () => this;
11
18
  private _render;
12
19
  protected abstract render(): void;
13
- enable(): void;
14
- disable(): void;
15
- /**
16
- * Clears all widgets from the screen and optionally clears the screen.
17
- */
18
- clearScreen(clearContent?: boolean): void;
20
+ readonly pause: () => this;
21
+ readonly dispose: () => this;
19
22
  }
@@ -27,14 +27,46 @@ exports.ConsoleScreen = void 0;
27
27
  // @ts-ignore
28
28
  const blessed = __importStar(require("neo-blessed"));
29
29
  const ts_common_1 = require("@nu-art/ts-common");
30
- class ConsoleScreen {
30
+ class ConsoleScreen extends ts_common_1.Logger {
31
31
  constructor(props) {
32
- var _a;
32
+ super(props === null || props === void 0 ? void 0 : props.title);
33
+ this.enabled = false;
34
+ this.state = {};
33
35
  this.widgets = [];
34
- this.screen = blessed.screen(props);
35
- (_a = props === null || props === void 0 ? void 0 : props.keyBinding) === null || _a === void 0 ? void 0 : _a.map(keyBinding => {
36
- this.screen.key(keyBinding.keys, keyBinding.callback);
37
- });
36
+ this.create = () => {
37
+ this.createScreen();
38
+ this._createWidgets();
39
+ if (!this.enabled)
40
+ this.resume();
41
+ return this;
42
+ };
43
+ this.resume = () => {
44
+ this.enabled = true;
45
+ this.widgets.forEach(widget => {
46
+ widget.focusable = true;
47
+ widget.interactive = true;
48
+ });
49
+ this._render();
50
+ return this;
51
+ };
52
+ this.pause = () => {
53
+ this.enabled = false;
54
+ this.widgets.forEach(widget => {
55
+ widget.focusable = false;
56
+ widget.interactive = false;
57
+ });
58
+ return this;
59
+ };
60
+ this.dispose = () => {
61
+ this.widgets.forEach(widget => widget.detach());
62
+ // @ts-ignore
63
+ this.widgets = [];
64
+ this._render();
65
+ if (this.enabled)
66
+ this.pause();
67
+ return this;
68
+ };
69
+ this.screenProps = props;
38
70
  }
39
71
  setState(state) {
40
72
  this.state = (0, ts_common_1.mergeObject)(this.state, state);
@@ -49,31 +81,25 @@ class ConsoleScreen {
49
81
  getFocusedWidget() {
50
82
  return this.screen.focused;
51
83
  }
52
- _render() {
53
- this.screen.render();
54
- this.render();
55
- }
56
- enable() {
57
- this.widgets.forEach(widget => {
58
- widget.focusable = true;
59
- widget.interactive = true;
84
+ createScreen() {
85
+ var _a, _b;
86
+ if (this.screen)
87
+ return this.logWarning(`will not create screen, already exists!`);
88
+ this.screen = blessed.screen(this.screenProps);
89
+ (_b = (_a = this.screenProps) === null || _a === void 0 ? void 0 : _a.keyBinding) === null || _b === void 0 ? void 0 : _b.map(keyBinding => {
90
+ this.screen.key(keyBinding.keys, keyBinding.callback);
60
91
  });
61
- this._render();
62
92
  }
63
- disable() {
64
- this.widgets.forEach(widget => {
65
- widget.focusable = false;
66
- widget.interactive = false;
67
- });
68
- this._render();
93
+ _createWidgets() {
94
+ if (this.widgets.length > 0)
95
+ return this.logWarning(`will not create widgets, already have ${this.widgets.length} widgets!`);
96
+ this.createWidgets();
69
97
  }
70
- /**
71
- * Clears all widgets from the screen and optionally clears the screen.
72
- */
73
- clearScreen(clearContent = true) {
74
- this.widgets.forEach(widget => widget.detach());
75
- // @ts-ignore
76
- this.widgets = [];
98
+ _render() {
99
+ if (!this.enabled)
100
+ return;
101
+ this.screen.render();
102
+ this.render();
77
103
  }
78
104
  }
79
105
  exports.ConsoleScreen = ConsoleScreen;
@@ -52,6 +52,10 @@ export type BoxOptions = {
52
52
  parent?: any;
53
53
  /** Top position (can be in pixels or percentage). */
54
54
  top?: number | string;
55
+ /** Right position (can be in pixels or percentage). */
56
+ right?: number | string;
57
+ /** Bottom position (can be in pixels or percentage). */
58
+ bottom?: number | string;
55
59
  /** Left position (can be in pixels or percentage). */
56
60
  left?: number | string;
57
61
  /** Width of the box (can be in pixels or percentage). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nu-art/commando",
3
- "version": "0.204.25",
3
+ "version": "0.204.26",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "TacB0sS",