@nan0web/ui-cli 1.1.1 → 2.1.0
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/README.md +153 -203
- package/bin/cli.js +11 -0
- package/bin/nan0cli.js +86 -0
- package/package.json +27 -13
- package/src/CLI.js +22 -30
- package/src/CLiMessage.js +2 -3
- package/src/Command.js +26 -24
- package/src/CommandError.js +3 -5
- package/src/CommandHelp.js +40 -36
- package/src/CommandMessage.js +56 -40
- package/src/CommandParser.js +27 -25
- package/src/InputAdapter.js +630 -90
- package/src/OutputAdapter.js +7 -8
- package/src/README.md.js +241 -312
- package/src/components/Alert.js +3 -6
- package/src/components/prompt/Autocomplete.js +12 -0
- package/src/components/prompt/Confirm.js +29 -0
- package/src/components/prompt/DateTime.js +26 -0
- package/src/components/prompt/Input.js +15 -0
- package/src/components/prompt/Mask.js +12 -0
- package/src/components/prompt/Multiselect.js +26 -0
- package/src/components/prompt/Next.js +8 -0
- package/src/components/prompt/Password.js +13 -0
- package/src/components/prompt/Pause.js +9 -0
- package/src/components/prompt/ProgressBar.js +16 -0
- package/src/components/prompt/Select.js +29 -0
- package/src/components/prompt/Slider.js +16 -0
- package/src/components/prompt/Spinner.js +29 -0
- package/src/components/prompt/Toggle.js +13 -0
- package/src/components/prompt/Tree.js +17 -0
- package/src/components/view/Alert.js +78 -0
- package/src/components/view/Badge.js +11 -0
- package/src/components/view/Nav.js +23 -0
- package/src/components/view/Table.js +12 -0
- package/src/components/view/Toast.js +9 -0
- package/src/core/Component.js +79 -0
- package/src/core/PropValidation.js +138 -0
- package/src/core/render.js +37 -0
- package/src/index.js +85 -40
- package/src/test/PlaygroundTest.js +37 -25
- package/src/test/index.js +2 -4
- package/src/ui/alert.js +58 -0
- package/src/ui/autocomplete.js +86 -0
- package/src/ui/badge.js +35 -0
- package/src/ui/confirm.js +49 -0
- package/src/ui/date-time.js +45 -0
- package/src/ui/form.js +120 -55
- package/src/ui/index.js +18 -4
- package/src/ui/input.js +79 -152
- package/src/ui/mask.js +132 -0
- package/src/ui/multiselect.js +59 -0
- package/src/ui/nav.js +74 -0
- package/src/ui/next.js +18 -13
- package/src/ui/progress.js +88 -0
- package/src/ui/select.js +49 -72
- package/src/ui/slider.js +154 -0
- package/src/ui/spinner.js +65 -0
- package/src/ui/table.js +163 -0
- package/src/ui/toast.js +34 -0
- package/src/ui/toggle.js +34 -0
- package/src/ui/tree.js +393 -0
- package/src/utils/parse.js +1 -1
- package/types/CLI.d.ts +5 -5
- package/types/CLiMessage.d.ts +1 -1
- package/types/Command.d.ts +2 -2
- package/types/CommandHelp.d.ts +3 -3
- package/types/CommandMessage.d.ts +8 -8
- package/types/CommandParser.d.ts +3 -3
- package/types/InputAdapter.d.ts +149 -15
- package/types/OutputAdapter.d.ts +1 -1
- package/types/README.md.d.ts +1 -1
- package/types/UiMessage.d.ts +31 -29
- package/types/components/prompt/Autocomplete.d.ts +6 -0
- package/types/components/prompt/Confirm.d.ts +6 -0
- package/types/components/prompt/DateTime.d.ts +6 -0
- package/types/components/prompt/Input.d.ts +6 -0
- package/types/components/prompt/Mask.d.ts +6 -0
- package/types/components/prompt/Multiselect.d.ts +6 -0
- package/types/components/prompt/Next.d.ts +6 -0
- package/types/components/prompt/Password.d.ts +6 -0
- package/types/components/prompt/Pause.d.ts +6 -0
- package/types/components/prompt/ProgressBar.d.ts +12 -0
- package/types/components/prompt/Select.d.ts +18 -0
- package/types/components/prompt/Slider.d.ts +6 -0
- package/types/components/prompt/Spinner.d.ts +21 -0
- package/types/components/prompt/Toggle.d.ts +6 -0
- package/types/components/prompt/Tree.d.ts +6 -0
- package/types/components/view/Alert.d.ts +21 -0
- package/types/components/view/Badge.d.ts +5 -0
- package/types/components/view/Nav.d.ts +15 -0
- package/types/components/view/Table.d.ts +10 -0
- package/types/components/view/Toast.d.ts +5 -0
- package/types/core/Component.d.ts +34 -0
- package/types/core/PropValidation.d.ts +48 -0
- package/types/core/render.d.ts +6 -0
- package/types/index.d.ts +47 -15
- package/types/test/PlaygroundTest.d.ts +12 -8
- package/types/test/index.d.ts +1 -1
- package/types/ui/alert.d.ts +14 -0
- package/types/ui/autocomplete.d.ts +20 -0
- package/types/ui/badge.d.ts +8 -0
- package/types/ui/confirm.d.ts +21 -0
- package/types/ui/date-time.d.ts +19 -0
- package/types/ui/form.d.ts +43 -12
- package/types/ui/index.d.ts +17 -2
- package/types/ui/input.d.ts +31 -74
- package/types/ui/mask.d.ts +29 -0
- package/types/ui/multiselect.d.ts +25 -0
- package/types/ui/nav.d.ts +27 -0
- package/types/ui/progress.d.ts +43 -0
- package/types/ui/select.d.ts +25 -64
- package/types/ui/slider.d.ts +23 -0
- package/types/ui/spinner.d.ts +28 -0
- package/types/ui/table.d.ts +28 -0
- package/types/ui/toast.d.ts +8 -0
- package/types/ui/toggle.d.ts +17 -0
- package/types/ui/tree.d.ts +48 -0
package/types/ui/select.d.ts
CHANGED
|
@@ -1,74 +1,35 @@
|
|
|
1
|
-
/** @typedef {import("./input.js").Input} Input */
|
|
2
|
-
/** @typedef {import("./input.js").InputFn} InputFn */
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {Object} ConsoleLike
|
|
5
|
-
* @property {(...args: any[]) => void} debug
|
|
6
|
-
* @property {(...args: any[]) => void} log
|
|
7
|
-
* @property {(...args: any[]) => void} info
|
|
8
|
-
* @property {(...args: any[]) => void} warn
|
|
9
|
-
* @property {(...args: any[]) => void} error
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {Object} SelectConfig
|
|
13
|
-
* @property {string} title – Title displayed above the options list.
|
|
14
|
-
* @property {string} prompt – Prompt displayed for the answer.
|
|
15
|
-
* @property {Array|Map} options – Collection of selectable items.
|
|
16
|
-
* @property {ConsoleLike} console – Console‑like object with an `info` method.
|
|
17
|
-
* @property {string[]} [stops=[]] Words that trigger cancellation.
|
|
18
|
-
* @property {InputFn} [ask] Custom ask function (defaults to {@link createInput}).
|
|
19
|
-
* @property {string} [invalidPrompt="Invalid choice, try again: "] Message shown on invalid input.
|
|
20
|
-
*/
|
|
21
1
|
/**
|
|
22
2
|
* Configuration object for {@link select}.
|
|
23
3
|
*
|
|
24
|
-
* @param {
|
|
25
|
-
* @
|
|
4
|
+
* @param {Object} input
|
|
5
|
+
* @param {string} input.title - Title displayed above the options list.
|
|
6
|
+
* @param {string} [input.prompt] - Prompt displayed for the answer.
|
|
7
|
+
* @param {Array|Map} input.options - Collection of selectable items.
|
|
8
|
+
* @param {Object} [input.console] - Deprecated. Ignored in new implementation.
|
|
9
|
+
* @param {string[]} [input.stops=[]] - Deprecated. Ignored in new implementation.
|
|
10
|
+
* @param {any} [input.ask] - Deprecated. Ignored in new implementation.
|
|
11
|
+
* @param {string} [input.invalidPrompt] - Deprecated. Ignored in new implementation.
|
|
12
|
+
* @param {number} [input.limit=10] - Max visible items.
|
|
13
|
+
* @param {string} [input.hint] - Hint text.
|
|
14
|
+
* @param {Function} [input.t] - Translation function.
|
|
15
|
+
* @returns {Promise<{index:number,value:any,cancelled:boolean}>} Resolves with the selected index and its value.
|
|
26
16
|
*
|
|
27
17
|
* @throws {CancelError} When the user cancels the operation.
|
|
28
|
-
* @throws {Error} When options are missing or an incorrect value is supplied and no
|
|
29
|
-
* `invalidPrompt` is defined.
|
|
30
18
|
*/
|
|
31
|
-
export function select(input:
|
|
32
|
-
index: number;
|
|
33
|
-
value: any;
|
|
34
|
-
}>;
|
|
35
|
-
export default select;
|
|
36
|
-
export type Input = import("./input.js").Input;
|
|
37
|
-
export type InputFn = typeof import("./input.js").InputFn;
|
|
38
|
-
export type ConsoleLike = {
|
|
39
|
-
debug: (...args: any[]) => void;
|
|
40
|
-
log: (...args: any[]) => void;
|
|
41
|
-
info: (...args: any[]) => void;
|
|
42
|
-
warn: (...args: any[]) => void;
|
|
43
|
-
error: (...args: any[]) => void;
|
|
44
|
-
};
|
|
45
|
-
export type SelectConfig = {
|
|
46
|
-
/**
|
|
47
|
-
* – Title displayed above the options list.
|
|
48
|
-
*/
|
|
19
|
+
export function select(input: {
|
|
49
20
|
title: string;
|
|
50
|
-
|
|
51
|
-
* – Prompt displayed for the answer.
|
|
52
|
-
*/
|
|
53
|
-
prompt: string;
|
|
54
|
-
/**
|
|
55
|
-
* – Collection of selectable items.
|
|
56
|
-
*/
|
|
21
|
+
prompt?: string | undefined;
|
|
57
22
|
options: any[] | Map<any, any>;
|
|
58
|
-
|
|
59
|
-
* – Console‑like object with an `info` method.
|
|
60
|
-
*/
|
|
61
|
-
console: ConsoleLike;
|
|
62
|
-
/**
|
|
63
|
-
* Words that trigger cancellation.
|
|
64
|
-
*/
|
|
23
|
+
console?: any;
|
|
65
24
|
stops?: string[] | undefined;
|
|
66
|
-
|
|
67
|
-
* Custom ask function (defaults to {@link createInput }).
|
|
68
|
-
*/
|
|
69
|
-
ask?: typeof import("./input.js").InputFn | undefined;
|
|
70
|
-
/**
|
|
71
|
-
* Message shown on invalid input.
|
|
72
|
-
*/
|
|
25
|
+
ask?: any;
|
|
73
26
|
invalidPrompt?: string | undefined;
|
|
74
|
-
|
|
27
|
+
limit?: number | undefined;
|
|
28
|
+
hint?: string | undefined;
|
|
29
|
+
t?: Function | undefined;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
index: number;
|
|
32
|
+
value: any;
|
|
33
|
+
cancelled: boolean;
|
|
34
|
+
}>;
|
|
35
|
+
export default select;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Object} config
|
|
3
|
+
* @param {string} config.message
|
|
4
|
+
* @param {number} [config.initial]
|
|
5
|
+
* @param {number} [config.min=0]
|
|
6
|
+
* @param {number} [config.max=100]
|
|
7
|
+
* @param {number} [config.step=1]
|
|
8
|
+
* @param {number} [config.jump]
|
|
9
|
+
* @param {Function} [config.t] - Optional translation function.
|
|
10
|
+
* @returns {Promise<{value:number, cancelled:boolean}>}
|
|
11
|
+
*/
|
|
12
|
+
export function slider(config: {
|
|
13
|
+
message: string;
|
|
14
|
+
initial?: number | undefined;
|
|
15
|
+
min?: number | undefined;
|
|
16
|
+
max?: number | undefined;
|
|
17
|
+
step?: number | undefined;
|
|
18
|
+
jump?: number | undefined;
|
|
19
|
+
t?: Function | undefined;
|
|
20
|
+
}): Promise<{
|
|
21
|
+
value: number;
|
|
22
|
+
cancelled: boolean;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Functional helper for spinner.
|
|
3
|
+
* @param {string} message
|
|
4
|
+
* @returns {Spinner}
|
|
5
|
+
*/
|
|
6
|
+
export function spinner(message: string): Spinner;
|
|
7
|
+
/**
|
|
8
|
+
* Spinner module – loading indicators.
|
|
9
|
+
* @module ui/spinner
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Visual spinner for async operations.
|
|
13
|
+
*/
|
|
14
|
+
export class Spinner {
|
|
15
|
+
static FRAMES: string[];
|
|
16
|
+
/**
|
|
17
|
+
* @param {string} [message]
|
|
18
|
+
*/
|
|
19
|
+
constructor(message?: string);
|
|
20
|
+
message: string;
|
|
21
|
+
frameIndex: number;
|
|
22
|
+
interval: NodeJS.Timeout | null;
|
|
23
|
+
startTime: number;
|
|
24
|
+
start(): void;
|
|
25
|
+
stop(status?: string): void;
|
|
26
|
+
success(msg: any): void;
|
|
27
|
+
error(msg: any): void;
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders an interactive table.
|
|
3
|
+
*
|
|
4
|
+
* @param {Object} input
|
|
5
|
+
* @param {Array<Object>} input.data - Data to display.
|
|
6
|
+
* @param {Array<string>} [input.columns] - Columns to include.
|
|
7
|
+
* @param {string} [input.title] - Table title.
|
|
8
|
+
* @param {boolean} [input.interactive=true] - Whether to allow filtering.
|
|
9
|
+
* @param {boolean} [input.instant=false] - Whether to use instant search (char-by-char).
|
|
10
|
+
* @param {(val:string)=>string} [input.t] - Translation function.
|
|
11
|
+
* @param {Logger} [input.logger] - Logger instance.
|
|
12
|
+
* @param {Function} [input.prompt] - Prompt function.
|
|
13
|
+
* @returns {Promise<{value:any, cancelled:boolean}>} Selected row (if interactive) or last state.
|
|
14
|
+
*/
|
|
15
|
+
export function table(input: {
|
|
16
|
+
data: Array<any>;
|
|
17
|
+
columns?: string[] | undefined;
|
|
18
|
+
title?: string | undefined;
|
|
19
|
+
interactive?: boolean | undefined;
|
|
20
|
+
instant?: boolean | undefined;
|
|
21
|
+
t?: ((val: string) => string) | undefined;
|
|
22
|
+
logger?: Logger | undefined;
|
|
23
|
+
prompt?: Function | undefined;
|
|
24
|
+
}): Promise<{
|
|
25
|
+
value: any;
|
|
26
|
+
cancelled: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
import Logger from '@nan0web/log';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Renders a toast message.
|
|
3
|
+
*
|
|
4
|
+
* @param {string} message - Message content.
|
|
5
|
+
* @param {'info'|'success'|'warning'|'error'} [variant='info']
|
|
6
|
+
* @returns {string} Styled string.
|
|
7
|
+
*/
|
|
8
|
+
export function toast(message: string, variant?: "info" | "success" | "warning" | "error"): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @param {Object} config
|
|
3
|
+
* @param {string} config.message
|
|
4
|
+
* @param {boolean} [config.initial=false]
|
|
5
|
+
* @param {string} [config.active='yes']
|
|
6
|
+
* @param {string} [config.inactive='no']
|
|
7
|
+
* @returns {Promise<{value:boolean, cancelled:boolean}>}
|
|
8
|
+
*/
|
|
9
|
+
export function toggle(config: {
|
|
10
|
+
message: string;
|
|
11
|
+
initial?: boolean | undefined;
|
|
12
|
+
active?: string | undefined;
|
|
13
|
+
inactive?: string | undefined;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
value: boolean;
|
|
16
|
+
cancelled: boolean;
|
|
17
|
+
}>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {Object} TreeNode
|
|
3
|
+
* @property {string} name
|
|
4
|
+
* @property {'file'|'dir'} type
|
|
5
|
+
* @property {TreeNode[]} [children] -- If undefined, might be loaded async
|
|
6
|
+
* @property {any} [payload] -- Custom data
|
|
7
|
+
* @property {any} [value] -- Result value (usually same as path or name)
|
|
8
|
+
* @property {string} [path] -- File path
|
|
9
|
+
* @property {boolean} [expanded] -- Internal state
|
|
10
|
+
* @property {boolean} [checked] -- Internal state
|
|
11
|
+
* @property {number} [depth] -- Calculated
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Tree Prompt
|
|
15
|
+
*/
|
|
16
|
+
export function tree(config: any): Promise<any>;
|
|
17
|
+
export type TreeNode = {
|
|
18
|
+
name: string;
|
|
19
|
+
type: "file" | "dir";
|
|
20
|
+
/**
|
|
21
|
+
* -- If undefined, might be loaded async
|
|
22
|
+
*/
|
|
23
|
+
children?: TreeNode[] | undefined;
|
|
24
|
+
/**
|
|
25
|
+
* -- Custom data
|
|
26
|
+
*/
|
|
27
|
+
payload?: any;
|
|
28
|
+
/**
|
|
29
|
+
* -- Result value (usually same as path or name)
|
|
30
|
+
*/
|
|
31
|
+
value?: any;
|
|
32
|
+
/**
|
|
33
|
+
* -- File path
|
|
34
|
+
*/
|
|
35
|
+
path?: string | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* -- Internal state
|
|
38
|
+
*/
|
|
39
|
+
expanded?: boolean | undefined;
|
|
40
|
+
/**
|
|
41
|
+
* -- Internal state
|
|
42
|
+
*/
|
|
43
|
+
checked?: boolean | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* -- Calculated
|
|
46
|
+
*/
|
|
47
|
+
depth?: number | undefined;
|
|
48
|
+
};
|