@reliverse/relinka 1.1.10 → 1.2.1
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/LICENSE +21 -0
- package/README.md +38 -42
- package/dist-npm/components/core/core.d.ts +2 -0
- package/dist-npm/components/core/core.js +2 -0
- package/dist-npm/{utils/constants.d.ts → components/levels/levels.d.ts} +1 -1
- package/dist-npm/components/{prompts/create.d.ts → modes/basic.d.ts} +3 -3
- package/dist-npm/components/{instance → modes}/basic.js +4 -4
- package/dist-npm/components/{instance → modes}/browser.d.ts +2 -2
- package/dist-npm/components/modes/browser.js +12 -0
- package/dist-npm/components/modes/shared.d.ts +5 -0
- package/dist-npm/components/modes/shared.js +2 -0
- package/dist-npm/components/{prompts → relinka}/relinka.d.ts +2 -4
- package/dist-npm/components/{prompts → relinka}/relinka.js +1 -7
- package/dist-npm/components/{instance/reporter → reporters}/basic.d.ts +1 -1
- package/dist-npm/components/{instance/reporter → reporters}/basic.js +2 -2
- package/dist-npm/components/{instance/reporter → reporters}/browser.d.ts +1 -1
- package/dist-npm/components/{instance/reporter → reporters}/fancy.d.ts +3 -3
- package/dist-npm/components/{instance/reporter → reporters}/fancy.js +5 -7
- package/dist-npm/main.d.ts +8 -1
- package/dist-npm/main.js +34 -1
- package/dist-npm/types/mod.d.ts +42 -0
- package/dist-npm/utils/color.js +4 -1
- package/dist-npm/utils/mod.d.ts +3 -0
- package/dist-npm/utils/mod.js +9 -0
- package/package.json +3 -2
- package/dist-npm/components/anykey/index.d.ts +0 -7
- package/dist-npm/components/anykey/index.js +0 -61
- package/dist-npm/components/block/block.d.ts +0 -10
- package/dist-npm/components/block/block.js +0 -52
- package/dist-npm/components/checkbox/index.d.ts +0 -3
- package/dist-npm/components/checkbox/index.js +0 -217
- package/dist-npm/components/confirm/confirm-main.d.ts +0 -3
- package/dist-npm/components/confirm/confirm-main.js +0 -98
- package/dist-npm/components/confirm/confirm-three.d.ts +0 -13
- package/dist-npm/components/confirm/confirm-three.js +0 -26
- package/dist-npm/components/confirm/index.d.ts +0 -2
- package/dist-npm/components/confirm/index.js +0 -41
- package/dist-npm/components/core/Separator.d.ts +0 -6
- package/dist-npm/components/core/Separator.js +0 -18
- package/dist-npm/components/core/create-prompt.d.ts +0 -4
- package/dist-npm/components/core/create-prompt.js +0 -107
- package/dist-npm/components/core/errors.d.ts +0 -20
- package/dist-npm/components/core/errors.js +0 -21
- package/dist-npm/components/core/hook-engine.d.ts +0 -23
- package/dist-npm/components/core/hook-engine.js +0 -109
- package/dist-npm/components/core/index.d.ts +0 -13
- package/dist-npm/components/core/index.js +0 -12
- package/dist-npm/components/core/key.d.ts +0 -10
- package/dist-npm/components/core/key.js +0 -16
- package/dist-npm/components/core/lines.d.ts +0 -14
- package/dist-npm/components/core/lines.js +0 -52
- package/dist-npm/components/core/make-theme.d.ts +0 -3
- package/dist-npm/components/core/make-theme.js +0 -28
- package/dist-npm/components/core/position.d.ts +0 -12
- package/dist-npm/components/core/position.js +0 -29
- package/dist-npm/components/core/promise-polyfill.d.ts +0 -7
- package/dist-npm/components/core/promise-polyfill.js +0 -13
- package/dist-npm/components/core/screen-manager.d.ts +0 -14
- package/dist-npm/components/core/screen-manager.js +0 -67
- package/dist-npm/components/core/theme.d.ts +0 -21
- package/dist-npm/components/core/theme.js +0 -24
- package/dist-npm/components/core/use-effect.d.ts +0 -2
- package/dist-npm/components/core/use-effect.js +0 -11
- package/dist-npm/components/core/use-keypress.d.ts +0 -3
- package/dist-npm/components/core/use-keypress.js +0 -21
- package/dist-npm/components/core/use-memo.d.ts +0 -1
- package/dist-npm/components/core/use-memo.js +0 -12
- package/dist-npm/components/core/use-pagination.d.ts +0 -11
- package/dist-npm/components/core/use-pagination.js +0 -34
- package/dist-npm/components/core/use-prefix.d.ts +0 -5
- package/dist-npm/components/core/use-prefix.js +0 -42
- package/dist-npm/components/core/use-ref.d.ts +0 -6
- package/dist-npm/components/core/use-ref.js +0 -4
- package/dist-npm/components/core/use-state.d.ts +0 -4
- package/dist-npm/components/core/use-state.js +0 -17
- package/dist-npm/components/core/useKeyPress.d.ts +0 -4
- package/dist-npm/components/core/useKeyPress.js +0 -16
- package/dist-npm/components/core/usePromptState.d.ts +0 -6
- package/dist-npm/components/core/usePromptState.js +0 -10
- package/dist-npm/components/core/utils.d.ts +0 -2
- package/dist-npm/components/core/utils.js +0 -11
- package/dist-npm/components/date/date.d.ts +0 -6
- package/dist-npm/components/date/date.js +0 -210
- package/dist-npm/components/editor/index.d.ts +0 -2
- package/dist-npm/components/editor/index.js +0 -78
- package/dist-npm/components/expand/index.d.ts +0 -3
- package/dist-npm/components/expand/index.js +0 -119
- package/dist-npm/components/figures/index.d.ts +0 -465
- package/dist-npm/components/figures/index.js +0 -299
- package/dist-npm/components/input/index.d.ts +0 -2
- package/dist-npm/components/input/index.js +0 -66
- package/dist-npm/components/input/text-main.d.ts +0 -3
- package/dist-npm/components/input/text-main.js +0 -103
- package/dist-npm/components/input/text.d.ts +0 -11
- package/dist-npm/components/input/text.js +0 -26
- package/dist-npm/components/instance/basic.d.ts +0 -8
- package/dist-npm/components/instance/browser.js +0 -18
- package/dist-npm/components/instance/shared.d.ts +0 -6
- package/dist-npm/components/instance/shared.js +0 -2
- package/dist-npm/components/mono/mono.d.ts +0 -5
- package/dist-npm/components/mono/mono.js +0 -64
- package/dist-npm/components/mono/monoTwo.d.ts +0 -30
- package/dist-npm/components/mono/monoTwo.js +0 -37
- package/dist-npm/components/multiselect/group-multiselect.d.ts +0 -23
- package/dist-npm/components/multiselect/group-multiselect.js +0 -58
- package/dist-npm/components/multiselect/multi-select-two.d.ts +0 -3
- package/dist-npm/components/multiselect/multi-select-two.js +0 -111
- package/dist-npm/components/multiselect/multi-select.d.ts +0 -21
- package/dist-npm/components/multiselect/multi-select.js +0 -45
- package/dist-npm/components/multiselect/multiselect-main.d.ts +0 -18
- package/dist-npm/components/multiselect/multiselect-main.js +0 -166
- package/dist-npm/components/multiselect/num-multi-select.d.ts +0 -3
- package/dist-npm/components/multiselect/num-multi-select.js +0 -111
- package/dist-npm/components/multiselect/num-multiselect-main.d.ts +0 -6
- package/dist-npm/components/multiselect/num-multiselect-main.js +0 -28
- package/dist-npm/components/next-steps/next-steps.d.ts +0 -2
- package/dist-npm/components/next-steps/next-steps.js +0 -24
- package/dist-npm/components/number/index.d.ts +0 -2
- package/dist-npm/components/number/index.js +0 -100
- package/dist-npm/components/number/number-main.d.ts +0 -3
- package/dist-npm/components/number/number-main.js +0 -95
- package/dist-npm/components/password/index.d.ts +0 -2
- package/dist-npm/components/password/index.js +0 -59
- package/dist-npm/components/password/password-main.d.ts +0 -3
- package/dist-npm/components/password/password-main.js +0 -119
- package/dist-npm/components/password/password-three.d.ts +0 -13
- package/dist-npm/components/password/password-three.js +0 -28
- package/dist-npm/components/progressbar/ProgressBar.d.ts +0 -22
- package/dist-npm/components/progressbar/ProgressBar.js +0 -53
- package/dist-npm/components/progressbar/helper.d.ts +0 -6
- package/dist-npm/components/progressbar/helper.js +0 -38
- package/dist-npm/components/progressbar/index.d.ts +0 -2
- package/dist-npm/components/progressbar/index.js +0 -1
- package/dist-npm/components/prompts/create.js +0 -35
- package/dist-npm/components/prompts/index.d.ts +0 -49
- package/dist-npm/components/prompts/index.js +0 -46
- package/dist-npm/components/prompts/prompt.d.ts +0 -36
- package/dist-npm/components/prompts/prompt.js +0 -232
- package/dist-npm/components/prompts/promptTwo.d.ts +0 -92
- package/dist-npm/components/prompts/promptTwo.js +0 -653
- package/dist-npm/components/range/range.d.ts +0 -62
- package/dist-npm/components/range/range.js +0 -270
- package/dist-npm/components/rawlist/index.d.ts +0 -3
- package/dist-npm/components/rawlist/index.js +0 -104
- package/dist-npm/components/results/results.d.ts +0 -10
- package/dist-npm/components/results/results.js +0 -34
- package/dist-npm/components/search/index.d.ts +0 -3
- package/dist-npm/components/search/index.js +0 -186
- package/dist-npm/components/select/index.d.ts +0 -3
- package/dist-npm/components/select/index.js +0 -176
- package/dist-npm/components/select/num-select-main.d.ts +0 -8
- package/dist-npm/components/select/num-select-main.js +0 -30
- package/dist-npm/components/select/num-select.d.ts +0 -5
- package/dist-npm/components/select/num-select.js +0 -125
- package/dist-npm/components/select/select-key.d.ts +0 -15
- package/dist-npm/components/select/select-key.js +0 -26
- package/dist-npm/components/select/select-main.d.ts +0 -19
- package/dist-npm/components/select/select-main.js +0 -151
- package/dist-npm/components/select/select-three.d.ts +0 -18
- package/dist-npm/components/select/select-three.js +0 -35
- package/dist-npm/components/select/select-two.d.ts +0 -2
- package/dist-npm/components/select/select-two.js +0 -98
- package/dist-npm/components/spinner/index.d.ts +0 -15
- package/dist-npm/components/spinner/index.js +0 -110
- package/dist-npm/components/st-end/end.d.ts +0 -2
- package/dist-npm/components/st-end/end.js +0 -35
- package/dist-npm/components/st-end/start.d.ts +0 -2
- package/dist-npm/components/st-end/start.js +0 -32
- package/dist-npm/components/toggle/index.d.ts +0 -13
- package/dist-npm/components/toggle/index.js +0 -121
- package/dist-npm/components/visual/animate/animate.d.ts +0 -13
- package/dist-npm/components/visual/animate/animate.js +0 -55
- package/dist-npm/components/visual/ascii-art/ascii-art.d.ts +0 -6
- package/dist-npm/components/visual/ascii-art/ascii-art.js +0 -12
- package/dist-npm/testing/index.d.ts +0 -18
- package/dist-npm/testing/index.js +0 -64
- package/dist-npm/types/general.d.ts +0 -134
- package/dist-npm/types/index.d.ts +0 -2
- package/dist-npm/types/index.js +0 -2
- package/dist-npm/types/keypress.d.ts +0 -52
- package/dist-npm/types/keypress.js +0 -37
- package/dist-npm/types/readline.d.ts +0 -30
- package/dist-npm/types/readline.js +0 -0
- package/dist-npm/types/relinka.d.ts +0 -30
- package/dist-npm/types/relinka.js +0 -0
- package/dist-npm/types/utils.d.ts +0 -17
- package/dist-npm/types/utils.js +0 -0
- package/dist-npm/utils/colorize.d.ts +0 -2
- package/dist-npm/utils/colorize.js +0 -130
- package/dist-npm/utils/component.d.ts +0 -101
- package/dist-npm/utils/component.js +0 -630
- package/dist-npm/utils/core.d.ts +0 -2
- package/dist-npm/utils/core.js +0 -2
- package/dist-npm/utils/decoder.d.ts +0 -14
- package/dist-npm/utils/decoder.js +0 -281
- package/dist-npm/utils/errors.d.ts +0 -1
- package/dist-npm/utils/errors.js +0 -15
- package/dist-npm/utils/keypress.d.ts +0 -7
- package/dist-npm/utils/keypress.js +0 -327
- package/dist-npm/utils/mapping.d.ts +0 -4
- package/dist-npm/utils/mapping.js +0 -49
- package/dist-npm/utils/messages.d.ts +0 -17
- package/dist-npm/utils/messages.js +0 -213
- package/dist-npm/utils/platforms.d.ts +0 -1
- package/dist-npm/utils/platforms.js +0 -22
- package/dist-npm/utils/prompt-tmp.d.ts +0 -13
- package/dist-npm/utils/prompt-tmp.js +0 -254
- package/dist-npm/utils/prompt-two.d.ts +0 -13
- package/dist-npm/utils/prompt-two.js +0 -254
- package/dist-npm/utils/readline.d.ts +0 -2
- package/dist-npm/utils/readline.js +0 -9
- package/dist-npm/utils/skeleton.d.ts +0 -7
- package/dist-npm/utils/skeleton.js +0 -145
- package/dist-npm/utils/terminal.d.ts +0 -5
- package/dist-npm/utils/terminal.js +0 -33
- package/dist-npm/utils/types.d.ts +0 -0
- package/dist-npm/utils/types.js +0 -0
- package/dist-npm/utils/utils.d.ts +0 -3
- package/dist-npm/utils/utils.js +0 -9
- package/dist-npm/utils/variants.d.ts +0 -9
- package/dist-npm/utils/variants.js +0 -49
- /package/dist-npm/{utils/constants.js → components/levels/levels.js} +0 -0
- /package/dist-npm/components/{instance/reporter → reporters}/browser.js +0 -0
- /package/dist-npm/types/{general.js → mod.js} +0 -0
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export { deleteLastLine, deleteLastLines, countLines, removeCursor, restoreCursor } from "../../utils/terminal.js";
|
|
2
|
-
export { colorize } from "../../utils/colorize.js";
|
|
3
|
-
export { fmt, msg } from "../../utils/messages.js";
|
|
4
|
-
export { errorHandler } from "../../utils/errors.js";
|
|
5
|
-
export { colorMap } from "../../utils/mapping.js";
|
|
6
|
-
export { animateText } from "../../components/visual/animate/animate.js";
|
|
7
|
-
export { createAsciiArt } from "../../components/visual/ascii-art/ascii-art.js";
|
|
8
|
-
export { startPrompt } from "../../components/st-end/start.js";
|
|
9
|
-
export { anykeyPrompt } from "../../components/anykey/index.js";
|
|
10
|
-
export { textPrompt } from "../../components/input/text-main.js";
|
|
11
|
-
export { confirmPrompt } from "../../components/confirm/confirm-main.js";
|
|
12
|
-
export { togglePrompt } from "../../components/toggle/index.js";
|
|
13
|
-
export { datePrompt } from "../../components/date/date.js";
|
|
14
|
-
export { selectPrompt } from "../../components/select/select-main.js";
|
|
15
|
-
export { multiselectPrompt } from "../../components/multiselect/multiselect-main.js";
|
|
16
|
-
export { numSelectPrompt } from "../../components/select/num-select.js";
|
|
17
|
-
export { numMultiSelectPrompt } from "../../components/multiselect/num-multi-select.js";
|
|
18
|
-
export { nextStepsPrompt } from "../../components/next-steps/next-steps.js";
|
|
19
|
-
export { numberPrompt } from "../../components/number/number-main.js";
|
|
20
|
-
export { passwordPrompt } from "../../components/password/password-main.js";
|
|
21
|
-
export { endPrompt } from "../../components/st-end/end.js";
|
|
22
|
-
export { progressbar } from "../../components/progressbar/index.js";
|
|
23
|
-
export { promptsDisplayResults } from "../../components/results/results.js";
|
|
24
|
-
export { prompt } from "../../components/mono/mono.js";
|
|
25
|
-
export { default as block } from "../../components/block/block.js";
|
|
26
|
-
export { spinner } from "../../components/spinner/index.js";
|
|
27
|
-
export { default as checkbox, Separator } from "../../components/checkbox/index.js";
|
|
28
|
-
export { default as expand } from "../../components/expand/index.js";
|
|
29
|
-
export { default as rawlist } from "../../components/rawlist/index.js";
|
|
30
|
-
export { default as search } from "../../components/search/index.js";
|
|
31
|
-
export { default as select } from "../../components/select/index.js";
|
|
32
|
-
export { default as editor } from "../../components/editor/index.js";
|
|
33
|
-
export { default as confirm } from "../../components/confirm/index.js";
|
|
34
|
-
export { default as input } from "../../components/input/index.js";
|
|
35
|
-
export { default as number } from "../../components/number/index.js";
|
|
36
|
-
export { default as password } from "../../components/password/index.js";
|
|
37
|
-
export { default as ConfirmPrompt } from "../../components/confirm/confirm-three.js";
|
|
38
|
-
export { default as GroupMultiSelectPrompt } from "../../components/multiselect/group-multiselect.js";
|
|
39
|
-
export { default as MultiSelectPrompt } from "../../components/multiselect/multi-select.js";
|
|
40
|
-
export { default as PasswordPrompt } from "../../components/password/password-three.js";
|
|
41
|
-
export { default as Prompt, isCancel } from "../../components/prompts/prompt.js";
|
|
42
|
-
export { default as SelectPrompt } from "../../components/select/select-three.js";
|
|
43
|
-
export { default as SelectKeyPrompt } from "../../components/select/select-key.js";
|
|
44
|
-
export { default as TextPrompt } from "../../components/input/text.js";
|
|
45
|
-
export { multiselect } from "../../components/prompts/promptTwo.js";
|
|
46
|
-
export { relinka } from "../../components/prompts/create.js";
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { Readable, Writable } from "node:stream";
|
|
2
|
-
import type { State } from "../../types/general.js";
|
|
3
|
-
export declare function isCancel(value: unknown): value is symbol;
|
|
4
|
-
export type PromptOptions<Self extends Prompt> = {
|
|
5
|
-
render(this: Omit<Self, "prompt">): string | void;
|
|
6
|
-
placeholder?: string;
|
|
7
|
-
initialValue?: any;
|
|
8
|
-
validate?: ((value: any) => string | void) | undefined;
|
|
9
|
-
input?: Readable;
|
|
10
|
-
output?: Writable;
|
|
11
|
-
debug?: boolean;
|
|
12
|
-
};
|
|
13
|
-
export default class Prompt {
|
|
14
|
-
protected input: Readable;
|
|
15
|
-
protected output: Writable;
|
|
16
|
-
private rl;
|
|
17
|
-
private opts;
|
|
18
|
-
private _track;
|
|
19
|
-
private _render;
|
|
20
|
-
protected _cursor: number;
|
|
21
|
-
state: State;
|
|
22
|
-
value: any;
|
|
23
|
-
error: string;
|
|
24
|
-
constructor({ render, input, output, initialValue, ...opts }: PromptOptions<Prompt>, trackValue?: boolean);
|
|
25
|
-
prompt(): Promise<string | symbol>;
|
|
26
|
-
private subscribers;
|
|
27
|
-
on(event: string, cb: (...args: any) => any): void;
|
|
28
|
-
once(event: string, cb: (...args: any) => any): void;
|
|
29
|
-
emit(event: string, ...data: any[]): void;
|
|
30
|
-
private unsubscribe;
|
|
31
|
-
private onKeypress;
|
|
32
|
-
protected close(): void;
|
|
33
|
-
private restoreCursor;
|
|
34
|
-
private _prevFrame;
|
|
35
|
-
private render;
|
|
36
|
-
}
|
|
@@ -1,232 +0,0 @@
|
|
|
1
|
-
import { stdin, stdout } from "node:process";
|
|
2
|
-
import readline from "node:readline";
|
|
3
|
-
import { WriteStream } from "node:tty";
|
|
4
|
-
import { cursor, erase } from "sisteransi";
|
|
5
|
-
import wrap from "wrap-ansi";
|
|
6
|
-
function diffLines(a, b) {
|
|
7
|
-
if (a === b) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
const aLines = a.split("\n");
|
|
11
|
-
const bLines = b.split("\n");
|
|
12
|
-
const diff = [];
|
|
13
|
-
for (let i = 0; i < Math.max(aLines.length, bLines.length); i++) {
|
|
14
|
-
if (aLines[i] !== bLines[i]) {
|
|
15
|
-
diff.push(i);
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return diff;
|
|
19
|
-
}
|
|
20
|
-
const cancel = Symbol("rp:cancel");
|
|
21
|
-
export function isCancel(value) {
|
|
22
|
-
return value === cancel;
|
|
23
|
-
}
|
|
24
|
-
function setRawMode(input, value) {
|
|
25
|
-
if (input.isTTY) {
|
|
26
|
-
input.setRawMode(value);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const aliases = new Map([
|
|
30
|
-
["k", "up"],
|
|
31
|
-
["j", "down"],
|
|
32
|
-
["h", "left"],
|
|
33
|
-
["l", "right"]
|
|
34
|
-
]);
|
|
35
|
-
const keys = new Set(["up", "down", "left", "right", "space", "enter"]);
|
|
36
|
-
export default class Prompt {
|
|
37
|
-
input;
|
|
38
|
-
output;
|
|
39
|
-
rl;
|
|
40
|
-
opts;
|
|
41
|
-
_track = false;
|
|
42
|
-
_render;
|
|
43
|
-
_cursor = 0;
|
|
44
|
-
state = "initial";
|
|
45
|
-
value;
|
|
46
|
-
error = "";
|
|
47
|
-
constructor({
|
|
48
|
-
render,
|
|
49
|
-
input = stdin,
|
|
50
|
-
output = stdout,
|
|
51
|
-
initialValue = "",
|
|
52
|
-
...opts
|
|
53
|
-
}, trackValue = true) {
|
|
54
|
-
this.opts = opts;
|
|
55
|
-
this.onKeypress = this.onKeypress.bind(this);
|
|
56
|
-
this.close = this.close.bind(this);
|
|
57
|
-
this.render = this.render.bind(this);
|
|
58
|
-
this._render = render.bind(this);
|
|
59
|
-
this._track = trackValue;
|
|
60
|
-
this.input = input;
|
|
61
|
-
this.output = output;
|
|
62
|
-
this.value = initialValue ?? "";
|
|
63
|
-
}
|
|
64
|
-
prompt() {
|
|
65
|
-
const sink = new WriteStream(0);
|
|
66
|
-
sink._write = (chunk, encoding, done) => {
|
|
67
|
-
if (this._track) {
|
|
68
|
-
this.value = this.rl.line.replace(/\t/g, "");
|
|
69
|
-
this._cursor = this.rl.cursor;
|
|
70
|
-
this.emit("value", this.value);
|
|
71
|
-
}
|
|
72
|
-
done();
|
|
73
|
-
};
|
|
74
|
-
this.input.pipe(sink);
|
|
75
|
-
this.rl = readline.createInterface({
|
|
76
|
-
input: this.input,
|
|
77
|
-
output: sink,
|
|
78
|
-
tabSize: 2,
|
|
79
|
-
prompt: "",
|
|
80
|
-
escapeCodeTimeout: 50
|
|
81
|
-
});
|
|
82
|
-
readline.emitKeypressEvents(this.input, this.rl);
|
|
83
|
-
this.rl.prompt();
|
|
84
|
-
if (this.opts.initialValue !== void 0 && this._track) {
|
|
85
|
-
this.rl.write(this.opts.initialValue);
|
|
86
|
-
}
|
|
87
|
-
this.input.on("keypress", this.onKeypress);
|
|
88
|
-
setRawMode(this.input, true);
|
|
89
|
-
this.output.on("resize", this.render);
|
|
90
|
-
this.render();
|
|
91
|
-
return new Promise((resolve, reject) => {
|
|
92
|
-
this.once("submit", () => {
|
|
93
|
-
this.output.write(cursor.show);
|
|
94
|
-
this.output.off("resize", this.render);
|
|
95
|
-
setRawMode(this.input, false);
|
|
96
|
-
resolve(this.value);
|
|
97
|
-
});
|
|
98
|
-
this.once("cancel", () => {
|
|
99
|
-
this.output.write(cursor.show);
|
|
100
|
-
this.output.off("resize", this.render);
|
|
101
|
-
setRawMode(this.input, false);
|
|
102
|
-
resolve(cancel);
|
|
103
|
-
});
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
subscribers = new Map();
|
|
107
|
-
on(event, cb) {
|
|
108
|
-
const arr = this.subscribers.get(event) ?? [];
|
|
109
|
-
arr.push({ cb });
|
|
110
|
-
this.subscribers.set(event, arr);
|
|
111
|
-
}
|
|
112
|
-
once(event, cb) {
|
|
113
|
-
const arr = this.subscribers.get(event) ?? [];
|
|
114
|
-
arr.push({ cb, once: true });
|
|
115
|
-
this.subscribers.set(event, arr);
|
|
116
|
-
}
|
|
117
|
-
emit(event, ...data) {
|
|
118
|
-
const cbs = this.subscribers.get(event) ?? [];
|
|
119
|
-
const cleanup = [];
|
|
120
|
-
for (const subscriber of cbs) {
|
|
121
|
-
subscriber.cb(...data);
|
|
122
|
-
if (subscriber.once) {
|
|
123
|
-
cleanup.push(() => cbs.splice(cbs.indexOf(subscriber), 1));
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
for (const cb of cleanup) {
|
|
127
|
-
cb();
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
unsubscribe() {
|
|
131
|
-
this.subscribers.clear();
|
|
132
|
-
}
|
|
133
|
-
onKeypress(char, key) {
|
|
134
|
-
if (this.state === "error") {
|
|
135
|
-
this.state = "active";
|
|
136
|
-
}
|
|
137
|
-
if (key?.name && !this._track && aliases.has(key.name)) {
|
|
138
|
-
this.emit("cursor", aliases.get(key.name));
|
|
139
|
-
}
|
|
140
|
-
if (key?.name && keys.has(key.name)) {
|
|
141
|
-
this.emit("cursor", key.name);
|
|
142
|
-
}
|
|
143
|
-
if (char && (char.toLowerCase() === "y" || char.toLowerCase() === "n")) {
|
|
144
|
-
this.emit("confirm", char.toLowerCase() === "y");
|
|
145
|
-
}
|
|
146
|
-
if (char === " " && this.opts.placeholder) {
|
|
147
|
-
if (!this.value) {
|
|
148
|
-
this.rl.write(this.opts.placeholder);
|
|
149
|
-
this.emit("value", this.opts.placeholder);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
if (char) {
|
|
153
|
-
this.emit("key", char.toLowerCase());
|
|
154
|
-
}
|
|
155
|
-
if (key?.name === "return") {
|
|
156
|
-
if (this.opts.validate) {
|
|
157
|
-
const problem = this.opts.validate(this.value);
|
|
158
|
-
if (problem) {
|
|
159
|
-
this.error = problem;
|
|
160
|
-
this.state = "error";
|
|
161
|
-
this.rl.write(this.value);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
if (this.state !== "error") {
|
|
165
|
-
this.state = "submit";
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
if (char === "") {
|
|
169
|
-
this.state = "cancel";
|
|
170
|
-
}
|
|
171
|
-
if (this.state === "submit" || this.state === "cancel") {
|
|
172
|
-
this.emit("finalize");
|
|
173
|
-
}
|
|
174
|
-
this.render();
|
|
175
|
-
if (this.state === "submit" || this.state === "cancel") {
|
|
176
|
-
this.close();
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
close() {
|
|
180
|
-
this.input.unpipe();
|
|
181
|
-
this.input.removeListener("keypress", this.onKeypress);
|
|
182
|
-
this.output.write("\n");
|
|
183
|
-
setRawMode(this.input, false);
|
|
184
|
-
this.rl.close();
|
|
185
|
-
this.emit(this.state, this.value);
|
|
186
|
-
this.unsubscribe();
|
|
187
|
-
}
|
|
188
|
-
restoreCursor() {
|
|
189
|
-
const lines = wrap(this._prevFrame, process.stdout.columns, { hard: true }).split("\n").length - 1;
|
|
190
|
-
this.output.write(cursor.move(-999, lines * -1));
|
|
191
|
-
}
|
|
192
|
-
_prevFrame = "";
|
|
193
|
-
render() {
|
|
194
|
-
const frame = wrap(this._render(this) ?? "", process.stdout.columns, {
|
|
195
|
-
hard: true
|
|
196
|
-
});
|
|
197
|
-
if (frame === this._prevFrame) {
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
if (this.state === "initial") {
|
|
201
|
-
this.output.write(cursor.hide);
|
|
202
|
-
} else {
|
|
203
|
-
const diff = diffLines(this._prevFrame, frame);
|
|
204
|
-
this.restoreCursor();
|
|
205
|
-
if (diff && diff.length === 1) {
|
|
206
|
-
const diffLine = diff[0];
|
|
207
|
-
this.output.write(cursor.move(0, diffLine));
|
|
208
|
-
this.output.write(erase.lines(1));
|
|
209
|
-
const lines = frame.split("\n");
|
|
210
|
-
this.output.write(lines[diffLine]);
|
|
211
|
-
this._prevFrame = frame;
|
|
212
|
-
this.output.write(cursor.move(0, lines.length - diffLine - 1));
|
|
213
|
-
return;
|
|
214
|
-
} else if (diff && diff.length > 1) {
|
|
215
|
-
const diffLine = diff[0];
|
|
216
|
-
this.output.write(cursor.move(0, diffLine));
|
|
217
|
-
this.output.write(erase.down());
|
|
218
|
-
const lines = frame.split("\n");
|
|
219
|
-
const newLines = lines.slice(diffLine);
|
|
220
|
-
this.output.write(newLines.join("\n"));
|
|
221
|
-
this._prevFrame = frame;
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
this.output.write(erase.down());
|
|
225
|
-
}
|
|
226
|
-
this.output.write(frame);
|
|
227
|
-
if (this.state === "initial") {
|
|
228
|
-
this.state = "active";
|
|
229
|
-
}
|
|
230
|
-
this._prevFrame = frame;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
export { isCancel } from "../../components/prompts/prompt.js";
|
|
2
|
-
export type TextOptions = {
|
|
3
|
-
message: string;
|
|
4
|
-
placeholder?: string;
|
|
5
|
-
defaultValue?: string;
|
|
6
|
-
initialValue?: string;
|
|
7
|
-
validate?: (value: string) => string | void;
|
|
8
|
-
};
|
|
9
|
-
export declare const text: (opts: TextOptions) => any;
|
|
10
|
-
export type PasswordOptions = {
|
|
11
|
-
message: string;
|
|
12
|
-
mask?: string;
|
|
13
|
-
validate?: (value: string) => string | void;
|
|
14
|
-
};
|
|
15
|
-
export declare const password: (opts: PasswordOptions) => any;
|
|
16
|
-
export type ConfirmOptions = {
|
|
17
|
-
message: string;
|
|
18
|
-
active?: string;
|
|
19
|
-
inactive?: string;
|
|
20
|
-
initialValue?: boolean;
|
|
21
|
-
};
|
|
22
|
-
export declare const confirm: (opts: ConfirmOptions) => Promise<boolean | symbol>;
|
|
23
|
-
type Primitive = Readonly<string | boolean | number>;
|
|
24
|
-
type Option<Value> = Value extends Primitive ? {
|
|
25
|
-
value: Value;
|
|
26
|
-
label?: string;
|
|
27
|
-
hint?: string;
|
|
28
|
-
} : {
|
|
29
|
-
value: Value;
|
|
30
|
-
label: string;
|
|
31
|
-
hint?: string;
|
|
32
|
-
};
|
|
33
|
-
export type SelectOptions<Options extends Option<Value>[], Value> = {
|
|
34
|
-
message: string;
|
|
35
|
-
options: Options;
|
|
36
|
-
initialValue?: Value;
|
|
37
|
-
};
|
|
38
|
-
export declare const select: <Options extends Option<Value>[], Value>(opts: SelectOptions<Options, Value>) => Promise<Value | symbol>;
|
|
39
|
-
export declare const selectKey: <Options extends Option<Value>[], Value extends string>(opts: SelectOptions<Options, Value>) => Promise<Value | symbol>;
|
|
40
|
-
export type MultiSelectOptions<Options extends Option<Value>[], Value> = {
|
|
41
|
-
message: string;
|
|
42
|
-
options: Options;
|
|
43
|
-
initialValues?: Value[];
|
|
44
|
-
required?: boolean;
|
|
45
|
-
cursorAt?: Value;
|
|
46
|
-
};
|
|
47
|
-
export declare const multiselect: <Options extends Option<Value>[], Value>(opts: MultiSelectOptions<Options, Value>) => Promise<Value[] | symbol>;
|
|
48
|
-
export type GroupMultiSelectOptions<Options extends Option<Value>[], Value> = {
|
|
49
|
-
message: string;
|
|
50
|
-
options: Record<string, Options>;
|
|
51
|
-
initialValues?: Value[];
|
|
52
|
-
required?: boolean;
|
|
53
|
-
cursorAt?: Value;
|
|
54
|
-
};
|
|
55
|
-
export declare const groupMultiselect: <Options extends Option<Value>[], Value>(opts: GroupMultiSelectOptions<Options, Value>) => Promise<Value[] | symbol>;
|
|
56
|
-
export declare const note: (message?: string, title?: string) => void;
|
|
57
|
-
export declare const cancel: (message?: string) => void;
|
|
58
|
-
export declare const intro: (title?: string) => void;
|
|
59
|
-
export declare const outro: (message?: string) => void;
|
|
60
|
-
export type LogMessageOptions = {
|
|
61
|
-
symbol?: string;
|
|
62
|
-
};
|
|
63
|
-
export declare const log: {
|
|
64
|
-
message: (message?: string, { symbol }?: LogMessageOptions) => void;
|
|
65
|
-
info: (message: string) => void;
|
|
66
|
-
success: (message: string) => void;
|
|
67
|
-
step: (message: string) => void;
|
|
68
|
-
warn: (message: string) => void;
|
|
69
|
-
warning: (message: string) => void;
|
|
70
|
-
error: (message: string) => void;
|
|
71
|
-
};
|
|
72
|
-
export declare const spinner: () => {
|
|
73
|
-
start(message?: string): void;
|
|
74
|
-
stop(message?: string): void;
|
|
75
|
-
};
|
|
76
|
-
export type PromptGroupAwaitedReturn<T> = {
|
|
77
|
-
[P in keyof T]: Exclude<Awaited<T[P]>, symbol>;
|
|
78
|
-
};
|
|
79
|
-
export type PromptGroupOptions<T> = {
|
|
80
|
-
onCancel?: (opts: {
|
|
81
|
-
results: Prettify<Partial<PromptGroupAwaitedReturn<T>>>;
|
|
82
|
-
}) => void;
|
|
83
|
-
};
|
|
84
|
-
type Prettify<T> = {} & {
|
|
85
|
-
[P in keyof T]: T[P];
|
|
86
|
-
};
|
|
87
|
-
export type PromptGroup<T> = {
|
|
88
|
-
[P in keyof T]: (opts: {
|
|
89
|
-
results: Prettify<Partial<PromptGroupAwaitedReturn<Omit<T, P>>>>;
|
|
90
|
-
}) => void | Promise<T[P] | void>;
|
|
91
|
-
};
|
|
92
|
-
export declare const group: <T>(prompts: PromptGroup<T>, opts?: PromptGroupOptions<T>) => Promise<Prettify<PromptGroupAwaitedReturn<T>>>;
|