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