@nu-art/commando 0.204.24 → 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.
- package/console/ConsoleScreen.d.ts +11 -8
- package/console/ConsoleScreen.js +54 -28
- package/console/types.d.ts +4 -0
- package/package.json +1 -1
|
@@ -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
|
-
|
|
14
|
-
|
|
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
|
}
|
package/console/ConsoleScreen.js
CHANGED
|
@@ -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
|
-
|
|
32
|
+
super(props === null || props === void 0 ? void 0 : props.title);
|
|
33
|
+
this.enabled = false;
|
|
34
|
+
this.state = {};
|
|
33
35
|
this.widgets = [];
|
|
34
|
-
this.
|
|
35
|
-
|
|
36
|
-
this.
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
this.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
this.
|
|
58
|
-
|
|
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
|
-
|
|
64
|
-
this.widgets.
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
this.
|
|
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;
|
package/console/types.d.ts
CHANGED
|
@@ -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). */
|