@nu-art/commando 0.204.13 → 0.204.14
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/package.json +2 -1
- package/screen/Screen.d.ts +19 -0
- package/screen/Screen.js +77 -0
- package/screen/types.d.ts +193 -0
- package/screen/types.js +47 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nu-art/commando",
|
|
3
|
-
"version": "0.204.
|
|
3
|
+
"version": "0.204.14",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"TacB0sS",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"build": "tsc"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
+
"neo-blessed": "^0.2.0",
|
|
34
35
|
"@nu-art/ts-common": "~0.204.0"
|
|
35
36
|
},
|
|
36
37
|
"devDependencies": {
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ResolvableContent } from '@nu-art/ts-common';
|
|
2
|
+
import { BoxOptions, ScreenOptions, WidgetTypes } from './types';
|
|
3
|
+
import * as blessed from 'neo-blessed';
|
|
4
|
+
export declare abstract class Screen<State extends object> {
|
|
5
|
+
protected state: State;
|
|
6
|
+
private screen;
|
|
7
|
+
protected readonly widgets: blessed.Widgets.Node[];
|
|
8
|
+
constructor(props?: ScreenOptions);
|
|
9
|
+
setState(state: ResolvableContent<Partial<State>>): void;
|
|
10
|
+
createWidget(type: WidgetTypes, props: Omit<BoxOptions, 'parent'>): any;
|
|
11
|
+
getFocusedWidget(): any;
|
|
12
|
+
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;
|
|
19
|
+
}
|
package/screen/Screen.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.Screen = void 0;
|
|
27
|
+
const ts_common_1 = require("@nu-art/ts-common");
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
const blessed = __importStar(require("neo-blessed"));
|
|
30
|
+
class Screen {
|
|
31
|
+
constructor(props) {
|
|
32
|
+
var _a;
|
|
33
|
+
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
|
+
});
|
|
38
|
+
}
|
|
39
|
+
setState(state) {
|
|
40
|
+
this.state = Object.freeze((0, ts_common_1.mergeObject)(this.state, state));
|
|
41
|
+
this.render();
|
|
42
|
+
}
|
|
43
|
+
createWidget(type, props) {
|
|
44
|
+
const widget = blessed[type](Object.assign(Object.assign({}, props), { parent: this.screen }));
|
|
45
|
+
this.widgets.push(widget);
|
|
46
|
+
return widget;
|
|
47
|
+
}
|
|
48
|
+
getFocusedWidget() {
|
|
49
|
+
return this.screen.focused;
|
|
50
|
+
}
|
|
51
|
+
enable() {
|
|
52
|
+
this.widgets.forEach(widget => {
|
|
53
|
+
widget.focusable = true;
|
|
54
|
+
widget.interactive = true;
|
|
55
|
+
});
|
|
56
|
+
this.screen.render();
|
|
57
|
+
}
|
|
58
|
+
disable() {
|
|
59
|
+
this.widgets.forEach(widget => {
|
|
60
|
+
widget.focusable = false;
|
|
61
|
+
widget.interactive = false;
|
|
62
|
+
});
|
|
63
|
+
this.screen.render();
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Clears all widgets from the screen and optionally clears the screen.
|
|
67
|
+
*/
|
|
68
|
+
clearScreen(clearContent = true) {
|
|
69
|
+
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
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.Screen = Screen;
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import * as blessed from 'neo-blessed';
|
|
3
|
+
/**
|
|
4
|
+
* Styles configuration for the box component.
|
|
5
|
+
*/
|
|
6
|
+
export type BoxStyle = {
|
|
7
|
+
/** Foreground color. */
|
|
8
|
+
fg?: string;
|
|
9
|
+
/** Background color. */
|
|
10
|
+
bg?: string;
|
|
11
|
+
/** Make text bold. */
|
|
12
|
+
bold?: boolean;
|
|
13
|
+
/** Underline text. */
|
|
14
|
+
underline?: boolean;
|
|
15
|
+
/** Make text blink. */
|
|
16
|
+
blink?: boolean;
|
|
17
|
+
/** Border styling. */
|
|
18
|
+
border?: {
|
|
19
|
+
/** Border type, can be line or background color. */
|
|
20
|
+
type?: 'line' | 'bg';
|
|
21
|
+
/** Border color. */
|
|
22
|
+
fg?: string;
|
|
23
|
+
};
|
|
24
|
+
/** Style when hovered over. */
|
|
25
|
+
hover?: {
|
|
26
|
+
fg?: string;
|
|
27
|
+
bg?: string;
|
|
28
|
+
border?: {
|
|
29
|
+
fg?: string;
|
|
30
|
+
bg?: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
/** Style when focused. */
|
|
34
|
+
focus?: {
|
|
35
|
+
fg?: string;
|
|
36
|
+
bg?: string;
|
|
37
|
+
border?: {
|
|
38
|
+
fg?: string;
|
|
39
|
+
bg?: string;
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
/** Scrollbar styling. */
|
|
43
|
+
scrollbar?: {
|
|
44
|
+
bg?: string;
|
|
45
|
+
fg?: string;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* Options for configuring a box component in neo-blessed.
|
|
50
|
+
*/
|
|
51
|
+
export type BoxOptions = {
|
|
52
|
+
/** Parent screen object. */
|
|
53
|
+
parent?: blessed.Widgets.Screen;
|
|
54
|
+
/** Top position (can be in pixels or percentage). */
|
|
55
|
+
top?: number | string;
|
|
56
|
+
/** Left position (can be in pixels or percentage). */
|
|
57
|
+
left?: number | string;
|
|
58
|
+
/** Width of the box (can be in pixels or percentage). */
|
|
59
|
+
width?: number | string;
|
|
60
|
+
/** Height of the box (can be in pixels or percentage). */
|
|
61
|
+
height?: number | string;
|
|
62
|
+
/** Text content of the box. */
|
|
63
|
+
content?: string;
|
|
64
|
+
/** Enables processing of inline tags. */
|
|
65
|
+
tags?: boolean;
|
|
66
|
+
/** Enables key handling for this component. */
|
|
67
|
+
keys?: boolean;
|
|
68
|
+
/** Enables vi-like navigation. */
|
|
69
|
+
vi?: boolean;
|
|
70
|
+
/** Enables mouse interaction. */
|
|
71
|
+
mouse?: boolean;
|
|
72
|
+
/** Makes the box scrollable. */
|
|
73
|
+
scrollable?: boolean;
|
|
74
|
+
/** Always show the scrollbar if the box is scrollable. */
|
|
75
|
+
alwaysScroll?: boolean;
|
|
76
|
+
/** Border configuration. */
|
|
77
|
+
border?: {
|
|
78
|
+
/** Type of border ('line' for lines, 'bg' for background). */
|
|
79
|
+
type: 'line' | 'bg';
|
|
80
|
+
/** Color of the border. */
|
|
81
|
+
fg?: string;
|
|
82
|
+
};
|
|
83
|
+
/** Label text displayed at the top or next to the widget. */
|
|
84
|
+
label?: string;
|
|
85
|
+
/** Styling options for the box. */
|
|
86
|
+
style?: BoxStyle;
|
|
87
|
+
/** Vertical alignment of the content. */
|
|
88
|
+
valign?: 'top' | 'middle' | 'bottom';
|
|
89
|
+
/** Horizontal alignment of the content. */
|
|
90
|
+
align?: 'left' | 'center' | 'right';
|
|
91
|
+
/** Whether the box should respond to input. */
|
|
92
|
+
interactive?: boolean;
|
|
93
|
+
/** Configuration for the scrollbar. */
|
|
94
|
+
scrollbar?: {
|
|
95
|
+
/** Character used to display the scrollbar. */
|
|
96
|
+
ch?: string;
|
|
97
|
+
/** Styling for the track of the scrollbar. */
|
|
98
|
+
track?: {
|
|
99
|
+
bg?: string;
|
|
100
|
+
};
|
|
101
|
+
/** Style adjustments for the scrollbar. */
|
|
102
|
+
style?: {
|
|
103
|
+
inverse?: boolean;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
/** Optional children components, allowing nested structures. */
|
|
107
|
+
children?: BoxOptions[];
|
|
108
|
+
};
|
|
109
|
+
export type ScreenOptions = {
|
|
110
|
+
/** Enables smart cursor routing, optimizing re-rendering. */
|
|
111
|
+
smartCSR?: boolean;
|
|
112
|
+
/** Enables a faster version of smartCSR for high performance rendering. */
|
|
113
|
+
fastCSR?: boolean;
|
|
114
|
+
/** Uses background color erase for reducing flickering. */
|
|
115
|
+
useBCE?: boolean;
|
|
116
|
+
/** Specifies the terminal type. Useful for consistent behavior across terminal types. */
|
|
117
|
+
terminal?: string;
|
|
118
|
+
/** Allows for full Unicode support. */
|
|
119
|
+
fullUnicode?: boolean;
|
|
120
|
+
/** Enables debugging, which logs information about screen operations. */
|
|
121
|
+
debug?: boolean;
|
|
122
|
+
/** Path to a file where debug logs will be written. */
|
|
123
|
+
log?: string;
|
|
124
|
+
/** Sets the terminal window title (not supported by all terminals). */
|
|
125
|
+
title?: string;
|
|
126
|
+
/** Automatically adds padding around the screen content. */
|
|
127
|
+
autoPadding?: boolean;
|
|
128
|
+
/** Controls cursor visibility and behavior. */
|
|
129
|
+
cursor?: {
|
|
130
|
+
artificial?: boolean;
|
|
131
|
+
blink?: boolean;
|
|
132
|
+
shape?: 'block' | 'underline' | 'line';
|
|
133
|
+
};
|
|
134
|
+
/** Enables mouse interaction support. */
|
|
135
|
+
mouse?: boolean;
|
|
136
|
+
/** Custom input stream for the screen, often used in testing. */
|
|
137
|
+
input?: NodeJS.ReadableStream;
|
|
138
|
+
/** Custom output stream for the screen, often used in testing. */
|
|
139
|
+
output?: NodeJS.WritableStream;
|
|
140
|
+
/** Time in milliseconds to wait after a resize event before redrawing the screen. */
|
|
141
|
+
resizeTimeout?: number;
|
|
142
|
+
keyBinding: {
|
|
143
|
+
keys: string[];
|
|
144
|
+
callback: VoidFunction;
|
|
145
|
+
}[];
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Documentation object simulating an enumeration for widget types.
|
|
149
|
+
*/
|
|
150
|
+
declare const WidgetDocs: {
|
|
151
|
+
/** A generic container that can hold other widgets or text. */
|
|
152
|
+
box: null;
|
|
153
|
+
/** Displays static text on the screen. */
|
|
154
|
+
text: null;
|
|
155
|
+
/** Shows a list of selectable items. */
|
|
156
|
+
list: null;
|
|
157
|
+
/** Designed for logging continuous text data. */
|
|
158
|
+
log: null;
|
|
159
|
+
/** A multi-line text input area for user input. */
|
|
160
|
+
textarea: null;
|
|
161
|
+
/** A single-line text input area for user input. */
|
|
162
|
+
textbox: null;
|
|
163
|
+
/** Holds input fields, buttons, and other form-related widgets. */
|
|
164
|
+
form: null;
|
|
165
|
+
/** Displays a progress bar for showing task progress. */
|
|
166
|
+
progressbar: null;
|
|
167
|
+
/** Displays tabular data. */
|
|
168
|
+
table: null;
|
|
169
|
+
/** Extends `list` with table-like functionality. */
|
|
170
|
+
listtable: null;
|
|
171
|
+
/** Prompts the user to input data. */
|
|
172
|
+
prompt: null;
|
|
173
|
+
/** Displays a message box for notifications or alerts. */
|
|
174
|
+
message: null;
|
|
175
|
+
/** Shows a loading spinner or message during operations. */
|
|
176
|
+
loading: null;
|
|
177
|
+
/** For creating groups of radio buttons for options. */
|
|
178
|
+
radioset: null;
|
|
179
|
+
/** A selectable radio button within a radioset. */
|
|
180
|
+
radiobutton: null;
|
|
181
|
+
/** Displays a checkbox that users can toggle. */
|
|
182
|
+
checkbox: null;
|
|
183
|
+
/** A single-line text input for user data. */
|
|
184
|
+
input: null;
|
|
185
|
+
/** A clickable button that can trigger actions. */
|
|
186
|
+
button: null;
|
|
187
|
+
/** A visual separator line. */
|
|
188
|
+
line: null;
|
|
189
|
+
/** A box that supports vertical scrolling of its content. */
|
|
190
|
+
scrollablebox: null;
|
|
191
|
+
};
|
|
192
|
+
export type WidgetTypes = keyof typeof WidgetDocs;
|
|
193
|
+
export {};
|
package/screen/types.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* Documentation object simulating an enumeration for widget types.
|
|
5
|
+
*/
|
|
6
|
+
const WidgetDocs = {
|
|
7
|
+
/** A generic container that can hold other widgets or text. */
|
|
8
|
+
box: null,
|
|
9
|
+
/** Displays static text on the screen. */
|
|
10
|
+
text: null,
|
|
11
|
+
/** Shows a list of selectable items. */
|
|
12
|
+
list: null,
|
|
13
|
+
/** Designed for logging continuous text data. */
|
|
14
|
+
log: null,
|
|
15
|
+
/** A multi-line text input area for user input. */
|
|
16
|
+
textarea: null,
|
|
17
|
+
/** A single-line text input area for user input. */
|
|
18
|
+
textbox: null,
|
|
19
|
+
/** Holds input fields, buttons, and other form-related widgets. */
|
|
20
|
+
form: null,
|
|
21
|
+
/** Displays a progress bar for showing task progress. */
|
|
22
|
+
progressbar: null,
|
|
23
|
+
/** Displays tabular data. */
|
|
24
|
+
table: null,
|
|
25
|
+
/** Extends `list` with table-like functionality. */
|
|
26
|
+
listtable: null,
|
|
27
|
+
/** Prompts the user to input data. */
|
|
28
|
+
prompt: null,
|
|
29
|
+
/** Displays a message box for notifications or alerts. */
|
|
30
|
+
message: null,
|
|
31
|
+
/** Shows a loading spinner or message during operations. */
|
|
32
|
+
loading: null,
|
|
33
|
+
/** For creating groups of radio buttons for options. */
|
|
34
|
+
radioset: null,
|
|
35
|
+
/** A selectable radio button within a radioset. */
|
|
36
|
+
radiobutton: null,
|
|
37
|
+
/** Displays a checkbox that users can toggle. */
|
|
38
|
+
checkbox: null,
|
|
39
|
+
/** A single-line text input for user data. */
|
|
40
|
+
input: null,
|
|
41
|
+
/** A clickable button that can trigger actions. */
|
|
42
|
+
button: null,
|
|
43
|
+
/** A visual separator line. */
|
|
44
|
+
line: null,
|
|
45
|
+
/** A box that supports vertical scrolling of its content. */
|
|
46
|
+
scrollablebox: null
|
|
47
|
+
};
|