@reliverse/relinka 1.1.5 → 1.1.7
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/dist-npm/components/anykey/index.js +77 -57
- package/dist-npm/components/block/block.js +61 -48
- package/dist-npm/components/checkbox/index.js +211 -178
- package/dist-npm/components/confirm/confirm-main.js +122 -85
- package/dist-npm/components/confirm/confirm-three.js +27 -24
- package/dist-npm/components/confirm/index.js +45 -36
- package/dist-npm/components/core/Separator.js +17 -15
- package/dist-npm/components/core/create-prompt.js +124 -101
- package/dist-npm/components/core/errors.js +15 -19
- package/dist-npm/components/core/hook-engine.js +120 -91
- package/dist-npm/components/core/index.js +12 -12
- package/dist-npm/components/core/key.js +6 -16
- package/dist-npm/components/core/lines.js +54 -45
- package/dist-npm/components/core/make-theme.js +30 -21
- package/dist-npm/components/core/position.js +23 -27
- package/dist-npm/components/core/promise-polyfill.js +14 -11
- package/dist-npm/components/core/screen-manager.js +74 -59
- package/dist-npm/components/core/theme.js +32 -22
- package/dist-npm/components/core/use-effect.js +15 -9
- package/dist-npm/components/core/use-keypress.js +23 -19
- package/dist-npm/components/core/use-memo.js +16 -10
- package/dist-npm/components/core/use-pagination.js +32 -33
- package/dist-npm/components/core/use-prefix.js +38 -40
- package/dist-npm/components/core/use-ref.js +5 -2
- package/dist-npm/components/core/use-state.js +23 -15
- package/dist-npm/components/core/useKeyPress.js +17 -14
- package/dist-npm/components/core/usePromptState.js +14 -8
- package/dist-npm/components/core/utils.js +16 -7
- package/dist-npm/components/date/date.js +204 -167
- package/dist-npm/components/editor/index.js +92 -71
- package/dist-npm/components/expand/index.js +124 -96
- package/dist-npm/components/figures/index.js +294 -283
- package/dist-npm/components/input/index.js +87 -61
- package/dist-npm/components/input/text-main.js +124 -97
- package/dist-npm/components/input/text.js +28 -24
- package/dist-npm/components/instance/basic.js +25 -17
- package/dist-npm/components/instance/browser.js +18 -14
- package/dist-npm/components/instance/reporter/basic.js +65 -46
- package/dist-npm/components/instance/reporter/browser.js +47 -44
- package/dist-npm/components/instance/reporter/fancy.js +96 -83
- package/dist-npm/components/instance/shared.js +2 -2
- package/dist-npm/components/mono/mono.js +62 -52
- package/dist-npm/components/mono/monoTwo.js +49 -35
- package/dist-npm/components/multiselect/group-multiselect.js +71 -55
- package/dist-npm/components/multiselect/multi-select-two.js +130 -97
- package/dist-npm/components/multiselect/multi-select.js +49 -43
- package/dist-npm/components/multiselect/multiselect-main.js +146 -120
- package/dist-npm/components/multiselect/num-multi-select.js +130 -97
- package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
- package/dist-npm/components/next-steps/next-steps.js +25 -23
- package/dist-npm/components/number/index.js +112 -78
- package/dist-npm/components/number/number-main.js +2 -95
- package/dist-npm/components/password/index.js +73 -54
- package/dist-npm/components/password/password-main.js +2 -119
- package/dist-npm/components/password/password-three.js +30 -26
- package/dist-npm/components/progressbar/ProgressBar.js +64 -45
- package/dist-npm/components/progressbar/helper.js +40 -33
- package/dist-npm/components/progressbar/index.js +1 -1
- package/dist-npm/components/prompts/create.js +44 -29
- package/dist-npm/components/prompts/index.js +45 -45
- package/dist-npm/components/prompts/prompt.js +260 -211
- package/dist-npm/components/prompts/promptTwo.js +605 -561
- package/dist-npm/components/prompts/relinka.js +295 -237
- package/dist-npm/components/range/range.js +294 -247
- package/dist-npm/components/rawlist/index.js +107 -87
- package/dist-npm/components/results/results.js +37 -31
- package/dist-npm/components/search/index.js +193 -148
- package/dist-npm/components/select/index.js +186 -148
- package/dist-npm/components/select/num-select-main.js +27 -27
- package/dist-npm/components/select/num-select.js +5 -124
- package/dist-npm/components/select/select-key.js +25 -24
- package/dist-npm/components/select/select-main.js +133 -109
- package/dist-npm/components/select/select-three.js +36 -32
- package/dist-npm/components/select/select-two.js +87 -94
- package/dist-npm/components/spinner/index.js +136 -107
- package/dist-npm/components/st-end/end.js +26 -34
- package/dist-npm/components/st-end/start.js +15 -29
- package/dist-npm/components/toggle/index.js +137 -113
- package/dist-npm/components/visual/animate/animate.js +10 -53
- package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
- package/dist-npm/mod.js +2 -1
- package/dist-npm/testing/index.js +83 -58
- package/dist-npm/types/general.js +1 -0
- package/dist-npm/types/index.js +3 -2
- package/dist-npm/types/keypress.js +36 -35
- package/dist-npm/types/readline.js +1 -0
- package/dist-npm/types/relinka.js +1 -0
- package/dist-npm/types/utils.js +1 -0
- package/dist-npm/utils/box.js +137 -135
- package/dist-npm/utils/color.js +74 -65
- package/dist-npm/utils/colorize.js +156 -124
- package/dist-npm/utils/component.js +657 -532
- package/dist-npm/utils/constants.js +63 -64
- package/dist-npm/utils/core.js +3 -2
- package/dist-npm/utils/decoder.js +223 -244
- package/dist-npm/utils/error.js +9 -4
- package/dist-npm/utils/errors.js +4 -14
- package/dist-npm/utils/format.js +24 -19
- package/dist-npm/utils/keypress.js +414 -316
- package/dist-npm/utils/log.js +15 -11
- package/dist-npm/utils/mapping.js +52 -45
- package/dist-npm/utils/messages.js +183 -183
- package/dist-npm/utils/platforms.js +20 -16
- package/dist-npm/utils/prompt-tmp.js +286 -235
- package/dist-npm/utils/prompt-two.js +286 -235
- package/dist-npm/utils/readline.js +7 -5
- package/dist-npm/utils/skeleton.js +170 -130
- package/dist-npm/utils/stream.js +2 -2
- package/dist-npm/utils/string.js +58 -44
- package/dist-npm/utils/terminal.js +34 -23
- package/dist-npm/utils/tree.js +41 -30
- package/dist-npm/utils/types.js +1 -0
- package/dist-npm/utils/utils.js +8 -8
- package/dist-npm/utils/variants.js +44 -36
- package/package.json +20 -28
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
5
|
-
export {
|
|
6
|
-
export {
|
|
7
|
-
export {
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
14
|
-
export {
|
|
15
|
-
export {
|
|
16
|
-
export {
|
|
17
|
-
export {
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
export {
|
|
21
|
-
export {
|
|
22
|
-
export {
|
|
23
|
-
export {
|
|
24
|
-
export {
|
|
25
|
-
export {
|
|
26
|
-
export {
|
|
27
|
-
export {
|
|
28
|
-
export {
|
|
29
|
-
export {
|
|
30
|
-
export {
|
|
31
|
-
export {
|
|
32
|
-
export {
|
|
33
|
-
export {
|
|
34
|
-
export {
|
|
35
|
-
export {
|
|
36
|
-
export {
|
|
37
|
-
export {
|
|
38
|
-
export {
|
|
39
|
-
export {
|
|
40
|
-
export {
|
|
41
|
-
export {
|
|
42
|
-
export {
|
|
43
|
-
export {
|
|
44
|
-
export {
|
|
45
|
-
export {
|
|
1
|
+
export {colorize} from '../../utils/colorize.js';
|
|
2
|
+
export {fmt, msg} from '../../utils/messages.js';
|
|
3
|
+
export {errorHandler} from '../../utils/errors.js';
|
|
4
|
+
export {colorMap} from '../../utils/mapping.js';
|
|
5
|
+
export {animateText} from '../../components/visual/animate/animate.js';
|
|
6
|
+
export {createAsciiArt} from '../../components/visual/ascii-art/ascii-art.js';
|
|
7
|
+
export {startPrompt} from '../../components/st-end/start.js';
|
|
8
|
+
export {anykeyPrompt} from '../../components/anykey/index.js';
|
|
9
|
+
export {textPrompt} from '../../components/input/text-main.js';
|
|
10
|
+
export {confirmPrompt} from '../../components/confirm/confirm-main.js';
|
|
11
|
+
export {togglePrompt} from '../../components/toggle/index.js';
|
|
12
|
+
export {datePrompt} from '../../components/date/date.js';
|
|
13
|
+
export {selectPrompt} from '../../components/select/select-main.js';
|
|
14
|
+
export {multiselectPrompt} from '../../components/multiselect/multiselect-main.js';
|
|
15
|
+
export {numSelectPrompt} from '../../components/select/num-select.js';
|
|
16
|
+
export {numMultiSelectPrompt} from '../../components/multiselect/num-multi-select.js';
|
|
17
|
+
export {nextStepsPrompt} from '../../components/next-steps/next-steps.js';
|
|
18
|
+
export {numberPrompt} from '../../components/number/number-main.js';
|
|
19
|
+
export {passwordPrompt} from '../../components/password/password-main.js';
|
|
20
|
+
export {endPrompt} from '../../components/st-end/end.js';
|
|
21
|
+
export {progressbar} from '../../components/progressbar/index.js';
|
|
22
|
+
export {promptsDisplayResults} from '../../components/results/results.js';
|
|
23
|
+
export {prompt} from '../../components/mono/mono.js';
|
|
24
|
+
export {default as block} from '../../components/block/block.js';
|
|
25
|
+
export {spinner} from '../../components/spinner/index.js';
|
|
26
|
+
export {default as checkbox, Separator} from '../../components/checkbox/index.js';
|
|
27
|
+
export {default as expand} from '../../components/expand/index.js';
|
|
28
|
+
export {default as rawlist} from '../../components/rawlist/index.js';
|
|
29
|
+
export {default as search} from '../../components/search/index.js';
|
|
30
|
+
export {default as select} from '../../components/select/index.js';
|
|
31
|
+
export {default as editor} from '../../components/editor/index.js';
|
|
32
|
+
export {default as confirm} from '../../components/confirm/index.js';
|
|
33
|
+
export {default as input} from '../../components/input/index.js';
|
|
34
|
+
export {default as number} from '../../components/number/index.js';
|
|
35
|
+
export {default as password} from '../../components/password/index.js';
|
|
36
|
+
export {default as ConfirmPrompt} from '../../components/confirm/confirm-three.js';
|
|
37
|
+
export {default as GroupMultiSelectPrompt} from '../../components/multiselect/group-multiselect.js';
|
|
38
|
+
export {default as MultiSelectPrompt} from '../../components/multiselect/multi-select.js';
|
|
39
|
+
export {default as PasswordPrompt} from '../../components/password/password-three.js';
|
|
40
|
+
export {default as Prompt, isCancel} from '../../components/prompts/prompt.js';
|
|
41
|
+
export {default as SelectPrompt} from '../../components/select/select-three.js';
|
|
42
|
+
export {default as SelectKeyPrompt} from '../../components/select/select-key.js';
|
|
43
|
+
export {default as TextPrompt} from '../../components/input/text.js';
|
|
44
|
+
export {multiselect} from '../../components/prompts/promptTwo.js';
|
|
45
|
+
export {relinka} from '../../components/prompts/create.js';
|
|
@@ -1,232 +1,281 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import readline from
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import wrap from
|
|
1
|
+
import process, {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
|
+
|
|
6
7
|
function diffLines(a, b) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
if (a === b) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const aLines = a.split('\n');
|
|
13
|
+
const bLines = b.split('\n');
|
|
14
|
+
const diff = [];
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < Math.max(aLines.length, bLines.length); i++) {
|
|
17
|
+
if (aLines[i] !== bLines[i]) {
|
|
18
|
+
diff.push(i);
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
|
-
|
|
18
|
-
|
|
21
|
+
|
|
22
|
+
return diff;
|
|
19
23
|
}
|
|
20
|
-
|
|
24
|
+
|
|
25
|
+
const cancel = Symbol('rp:cancel');
|
|
26
|
+
|
|
21
27
|
export function isCancel(value) {
|
|
22
|
-
|
|
28
|
+
return value === cancel;
|
|
23
29
|
}
|
|
30
|
+
|
|
24
31
|
function setRawMode(input, value) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
if (input.isTTY) {
|
|
33
|
+
input.setRawMode(value);
|
|
34
|
+
}
|
|
28
35
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
36
|
+
|
|
37
|
+
const aliases = new Map([
|
|
38
|
+
['k', 'up'],
|
|
39
|
+
['j', 'down'],
|
|
40
|
+
['h', 'left'],
|
|
41
|
+
['l', 'right'],
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
const keys = new Set([
|
|
45
|
+
'up',
|
|
46
|
+
'down',
|
|
47
|
+
'left',
|
|
48
|
+
'right',
|
|
49
|
+
'space',
|
|
50
|
+
'enter',
|
|
34
51
|
]);
|
|
35
|
-
|
|
52
|
+
|
|
36
53
|
export default class Prompt {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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();
|
|
54
|
+
input;
|
|
55
|
+
output;
|
|
56
|
+
rl;
|
|
57
|
+
opts;
|
|
58
|
+
_track = false;
|
|
59
|
+
_render;
|
|
60
|
+
_cursor = 0;
|
|
61
|
+
state = 'initial';
|
|
62
|
+
value;
|
|
63
|
+
error = '';
|
|
64
|
+
constructor({render, input = stdin, output = stdout, initialValue = '', ...opts}, trackValue = true) {
|
|
65
|
+
this.opts = opts;
|
|
66
|
+
this.onKeypress = this.onKeypress.bind(this);
|
|
67
|
+
this.close = this.close.bind(this);
|
|
68
|
+
this.render = this.render.bind(this);
|
|
69
|
+
this._render = render.bind(this);
|
|
70
|
+
this._track = trackValue;
|
|
71
|
+
this.input = input;
|
|
72
|
+
this.output = output;
|
|
73
|
+
this.value = initialValue ?? '';
|
|
128
74
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
75
|
+
|
|
76
|
+
prompt() {
|
|
77
|
+
const sink = new WriteStream(0);
|
|
78
|
+
|
|
79
|
+
sink._write = (chunk, encoding, done) => {
|
|
80
|
+
if (this._track) {
|
|
81
|
+
this.value = this.rl.line.replace(/\t/g, '');
|
|
82
|
+
this._cursor = this.rl.cursor;
|
|
83
|
+
this.emit('value', this.value);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
done();
|
|
87
|
+
};
|
|
88
|
+
this.input.pipe(sink);
|
|
89
|
+
this.rl = readline.createInterface({
|
|
90
|
+
input: this.input,
|
|
91
|
+
output: sink,
|
|
92
|
+
tabSize: 2,
|
|
93
|
+
prompt: '',
|
|
94
|
+
escapeCodeTimeout: 50,
|
|
95
|
+
});
|
|
96
|
+
readline.emitKeypressEvents(this.input, this.rl);
|
|
97
|
+
this.rl.prompt();
|
|
98
|
+
if (this.opts.initialValue !== void 0 && this._track) {
|
|
99
|
+
this.rl.write(this.opts.initialValue);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.input.on('keypress', this.onKeypress);
|
|
103
|
+
setRawMode(this.input, true);
|
|
104
|
+
this.output.on('resize', this.render);
|
|
105
|
+
this.render();
|
|
106
|
+
return new Promise((resolve) => {
|
|
107
|
+
this.once('submit', () => {
|
|
108
|
+
this.output.write(cursor.show);
|
|
109
|
+
this.output.off('resize', this.render);
|
|
110
|
+
setRawMode(this.input, false);
|
|
111
|
+
resolve(this.value);
|
|
112
|
+
});
|
|
113
|
+
this.once('cancel', () => {
|
|
114
|
+
this.output.write(cursor.show);
|
|
115
|
+
this.output.off('resize', this.render);
|
|
116
|
+
setRawMode(this.input, false);
|
|
117
|
+
resolve(cancel);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
145
120
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
121
|
+
|
|
122
|
+
subscribers = new Map();
|
|
123
|
+
on(event, cb) {
|
|
124
|
+
const arr = this.subscribers.get(event) ?? [];
|
|
125
|
+
arr.push({
|
|
126
|
+
cb,
|
|
127
|
+
});
|
|
128
|
+
this.subscribers.set(event, arr);
|
|
151
129
|
}
|
|
152
|
-
|
|
153
|
-
|
|
130
|
+
|
|
131
|
+
once(event, cb) {
|
|
132
|
+
const arr = this.subscribers.get(event) ?? [];
|
|
133
|
+
arr.push({
|
|
134
|
+
cb,
|
|
135
|
+
once: true,
|
|
136
|
+
});
|
|
137
|
+
this.subscribers.set(event, arr);
|
|
154
138
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
139
|
+
|
|
140
|
+
emit(event, ...data) {
|
|
141
|
+
const cbs = this.subscribers.get(event) ?? [];
|
|
142
|
+
const cleanup = [];
|
|
143
|
+
|
|
144
|
+
for (const subscriber of cbs) {
|
|
145
|
+
subscriber.cb(...data);
|
|
146
|
+
if (subscriber.once) {
|
|
147
|
+
cleanup.push(() => cbs.splice(cbs.indexOf(subscriber), 1));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
for (const cb of cleanup) {
|
|
152
|
+
cb();
|
|
153
|
+
}
|
|
167
154
|
}
|
|
168
|
-
|
|
169
|
-
|
|
155
|
+
|
|
156
|
+
unsubscribe() {
|
|
157
|
+
this.subscribers.clear();
|
|
170
158
|
}
|
|
171
|
-
|
|
172
|
-
|
|
159
|
+
|
|
160
|
+
onKeypress(char, key) {
|
|
161
|
+
if (this.state === 'error') {
|
|
162
|
+
this.state = 'active';
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (key?.name && !this._track && aliases.has(key.name)) {
|
|
166
|
+
this.emit('cursor', aliases.get(key.name));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (key?.name && keys.has(key.name)) {
|
|
170
|
+
this.emit('cursor', key.name);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
if (char && (char.toLowerCase() === 'y' || char.toLowerCase() === 'n')) {
|
|
174
|
+
this.emit('confirm', char.toLowerCase() === 'y');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (char === ' ' && this.opts.placeholder && !this.value) {
|
|
178
|
+
this.rl.write(this.opts.placeholder);
|
|
179
|
+
this.emit('value', this.opts.placeholder);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (char) {
|
|
183
|
+
this.emit('key', char.toLowerCase());
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (key?.name === 'return') {
|
|
187
|
+
if (this.opts.validate) {
|
|
188
|
+
const problem = this.opts.validate(this.value);
|
|
189
|
+
|
|
190
|
+
if (problem) {
|
|
191
|
+
this.error = problem;
|
|
192
|
+
this.state = 'error';
|
|
193
|
+
this.rl.write(this.value);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (this.state !== 'error') {
|
|
198
|
+
this.state = 'submit';
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (char === '') {
|
|
203
|
+
this.state = 'cancel';
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (this.state === 'submit' || this.state === 'cancel') {
|
|
207
|
+
this.emit('finalize');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
this.render();
|
|
211
|
+
if (this.state === 'submit' || this.state === 'cancel') {
|
|
212
|
+
this.close();
|
|
213
|
+
}
|
|
173
214
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
215
|
+
|
|
216
|
+
close() {
|
|
217
|
+
this.input.unpipe();
|
|
218
|
+
this.input.removeListener('keypress', this.onKeypress);
|
|
219
|
+
this.output.write('\n');
|
|
220
|
+
setRawMode(this.input, false);
|
|
221
|
+
this.rl.close();
|
|
222
|
+
this.emit(this.state, this.value);
|
|
223
|
+
this.unsubscribe();
|
|
177
224
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
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;
|
|
225
|
+
|
|
226
|
+
restoreCursor() {
|
|
227
|
+
const lines = wrap(this._prevFrame, process.stdout.columns, {
|
|
228
|
+
hard: true,
|
|
229
|
+
}).split('\n').length - 1;
|
|
230
|
+
this.output.write(cursor.move(-999, lines * -1));
|
|
199
231
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
232
|
+
|
|
233
|
+
_prevFrame = '';
|
|
234
|
+
render() {
|
|
235
|
+
const frame = wrap(this._render(this) ?? '', process.stdout.columns, {
|
|
236
|
+
hard: true,
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
if (frame === this._prevFrame) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (this.state === 'initial') {
|
|
244
|
+
this.output.write(cursor.hide);
|
|
245
|
+
} else {
|
|
246
|
+
const diff = diffLines(this._prevFrame, frame);
|
|
247
|
+
this.restoreCursor();
|
|
248
|
+
if (diff && diff.length === 1) {
|
|
249
|
+
const [diffLine] = diff;
|
|
250
|
+
this.output.write(cursor.move(0, diffLine));
|
|
251
|
+
this.output.write(erase.lines(1));
|
|
252
|
+
const lines = frame.split('\n');
|
|
253
|
+
this.output.write(lines[diffLine]);
|
|
254
|
+
this._prevFrame = frame;
|
|
255
|
+
this.output.write(cursor.move(0, lines.length - diffLine - 1));
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (diff && diff.length > 1) {
|
|
260
|
+
const [diffLine] = diff;
|
|
261
|
+
this.output.write(cursor.move(0, diffLine));
|
|
262
|
+
this.output.write(erase.down());
|
|
263
|
+
const lines = frame.split('\n');
|
|
264
|
+
const newLines = lines.slice(diffLine);
|
|
265
|
+
|
|
266
|
+
this.output.write(newLines.join('\n'));
|
|
267
|
+
this._prevFrame = frame;
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
this.output.write(erase.down());
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
this.output.write(frame);
|
|
275
|
+
if (this.state === 'initial') {
|
|
276
|
+
this.state = 'active';
|
|
277
|
+
}
|
|
278
|
+
|
|
221
279
|
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
280
|
}
|
|
230
|
-
this._prevFrame = frame;
|
|
231
|
-
}
|
|
232
281
|
}
|