@reliverse/relinka 1.1.7 → 1.1.8
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 +173 -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,317 +1,270 @@
|
|
|
1
|
-
import Differ from
|
|
2
|
-
import esc from
|
|
3
|
-
import chalk from
|
|
4
|
-
import ui from
|
|
5
|
-
import {EventEmitter} from
|
|
6
|
-
import precision from
|
|
7
|
-
import stringWidth from
|
|
8
|
-
import windowSize from
|
|
9
|
-
import
|
|
10
|
-
import wrap from '../../utils/skeleton.js';
|
|
11
|
-
|
|
12
|
-
const isString = (a) => typeof a === 'string';
|
|
13
|
-
|
|
1
|
+
import Differ from "ansi-diff-stream";
|
|
2
|
+
import esc from "ansi-escapes";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import ui from "cli-styles";
|
|
5
|
+
import { EventEmitter } from "events";
|
|
6
|
+
import precision from "precision";
|
|
7
|
+
import stringWidth from "string-width";
|
|
8
|
+
import windowSize from "window-size";
|
|
9
|
+
import wrap from "../../utils/skeleton.js";
|
|
14
10
|
export class RangePrompt extends EventEmitter {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
/**
|
|
11
|
+
|
|
12
|
+
hint;
|
|
13
|
+
marker;
|
|
14
|
+
bar;
|
|
15
|
+
values;
|
|
16
|
+
value;
|
|
17
|
+
unit;
|
|
18
|
+
typed;
|
|
19
|
+
lastHit;
|
|
20
|
+
min;
|
|
21
|
+
max;
|
|
22
|
+
step;
|
|
23
|
+
size;
|
|
24
|
+
done;
|
|
25
|
+
aborted;
|
|
26
|
+
msg;
|
|
27
|
+
initialValue;
|
|
28
|
+
out;
|
|
29
|
+
close;
|
|
30
|
+
pause;
|
|
31
|
+
resume;
|
|
32
|
+
_;
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
stdin;
|
|
36
|
+
keyListener;
|
|
37
|
+
cursorHidden;
|
|
38
|
+
constructor(msg, options = {}) {
|
|
39
|
+
super();
|
|
40
|
+
const defaults = {
|
|
41
|
+
hint: "\u2013\xA0Use arrow keys or type a value.",
|
|
42
|
+
marker: chalk.cyan.bold("\u25CF"),
|
|
43
|
+
bar: "\u2013",
|
|
44
|
+
values: [],
|
|
45
|
+
value: null,
|
|
46
|
+
unit: "",
|
|
47
|
+
typed: "",
|
|
48
|
+
lastHit: 0,
|
|
49
|
+
min: 0,
|
|
50
|
+
max: 100,
|
|
51
|
+
step: 1,
|
|
52
|
+
size: windowSize.width
|
|
53
|
+
};
|
|
54
|
+
const opts = { ...defaults, ...options };
|
|
55
|
+
this.hint = opts.hint;
|
|
56
|
+
this.marker = opts.marker;
|
|
57
|
+
this.bar = opts.bar;
|
|
58
|
+
this.values = opts.values;
|
|
59
|
+
this.value = opts.value;
|
|
60
|
+
this.unit = opts.unit;
|
|
61
|
+
this.typed = opts.typed;
|
|
62
|
+
this.lastHit = opts.lastHit;
|
|
63
|
+
this.min = opts.min;
|
|
64
|
+
this.max = opts.max;
|
|
65
|
+
this.step = opts.step;
|
|
66
|
+
this.size = opts.size;
|
|
67
|
+
this.done = false;
|
|
68
|
+
this.aborted = false;
|
|
69
|
+
this.msg = msg;
|
|
70
|
+
this.initialValue = this.value;
|
|
71
|
+
this.out = process.stdout;
|
|
72
|
+
this.stdin = process.stdin;
|
|
73
|
+
this.keyListener = this.onKeyPress.bind(this);
|
|
74
|
+
this.cursorHidden = false;
|
|
75
|
+
this.close = this._close.bind(this);
|
|
76
|
+
this.reset = this.reset.bind(this);
|
|
77
|
+
this.abort = this.abort.bind(this);
|
|
78
|
+
this.submit = this.submit.bind(this);
|
|
79
|
+
this.up = this.up.bind(this);
|
|
80
|
+
this.down = this.down.bind(this);
|
|
81
|
+
this.handleNumericInput = this.handleNumericInput.bind(this);
|
|
82
|
+
this.handleUnknownInput = this.handleUnknownInput.bind(this);
|
|
83
|
+
this.render = this.render.bind(this);
|
|
84
|
+
this.left = this.down.bind(this);
|
|
85
|
+
this.right = this.up.bind(this);
|
|
86
|
+
this._ = this.handleUnknownInput;
|
|
87
|
+
this.initialize();
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
95
90
|
* Initializes the prompt by setting up listeners and terminal settings
|
|
96
91
|
*/
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
this.stdin.on('data', this.keyListener);
|
|
106
|
-
this.render(true);
|
|
92
|
+
initialize() {
|
|
93
|
+
this.out.write(esc.cursorHide);
|
|
94
|
+
this.cursorHidden = true;
|
|
95
|
+
if (this.stdin.isTTY) {
|
|
96
|
+
this.stdin.setRawMode(true);
|
|
97
|
+
this.stdin.resume();
|
|
107
98
|
}
|
|
108
|
-
|
|
99
|
+
this.stdin.on("data", this.keyListener);
|
|
100
|
+
this.render(true);
|
|
101
|
+
}
|
|
109
102
|
_close() {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
if (this.out instanceof Differ) {
|
|
122
|
-
this.out.end();
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
this.emit('close');
|
|
103
|
+
this.stdin.removeListener("data", this.keyListener);
|
|
104
|
+
if (this.stdin.isTTY) {
|
|
105
|
+
this.stdin.setRawMode(false);
|
|
106
|
+
this.stdin.pause();
|
|
107
|
+
}
|
|
108
|
+
if (this.cursorHidden) {
|
|
109
|
+
this.out.write(esc.cursorShow);
|
|
110
|
+
this.cursorHidden = false;
|
|
111
|
+
}
|
|
112
|
+
if (this.out instanceof Differ) {
|
|
113
|
+
this.out.end();
|
|
126
114
|
}
|
|
127
|
-
|
|
115
|
+
this.emit("close");
|
|
116
|
+
}
|
|
128
117
|
onKeyPress(chunk) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
this.up();
|
|
144
|
-
} else {
|
|
145
|
-
this.down();
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (isFloat.test(key)) {
|
|
152
|
-
this.handleNumericInput(key);
|
|
153
|
-
} else {
|
|
154
|
-
this.handleUnknownInput();
|
|
155
|
-
}
|
|
118
|
+
const key = chunk.toString();
|
|
119
|
+
if (key === "") {
|
|
120
|
+
this.abort();
|
|
121
|
+
return;
|
|
122
|
+
} else if (key === "\r" || key === "\n") {
|
|
123
|
+
this.submit();
|
|
124
|
+
return;
|
|
125
|
+
} else if (key === "\x1B[A" || key === "\x1B[B") {
|
|
126
|
+
if (key === "\x1B[A") {
|
|
127
|
+
this.up();
|
|
128
|
+
} else {
|
|
129
|
+
this.down();
|
|
130
|
+
}
|
|
131
|
+
return;
|
|
156
132
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
this.emit('change');
|
|
162
|
-
this.render();
|
|
133
|
+
if (isFloat.test(key)) {
|
|
134
|
+
this.handleNumericInput(key);
|
|
135
|
+
} else {
|
|
136
|
+
this.handleUnknownInput(key);
|
|
163
137
|
}
|
|
164
|
-
|
|
138
|
+
}
|
|
139
|
+
reset() {
|
|
140
|
+
this.typed = "";
|
|
141
|
+
this.value = this.initialValue;
|
|
142
|
+
this.emit("change");
|
|
143
|
+
this.render();
|
|
144
|
+
}
|
|
165
145
|
abort() {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
146
|
+
this.done = true;
|
|
147
|
+
this.aborted = true;
|
|
148
|
+
this.emit("abort");
|
|
149
|
+
this.render();
|
|
150
|
+
this.out.write("\n");
|
|
151
|
+
this.close();
|
|
152
|
+
}
|
|
174
153
|
submit() {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
154
|
+
this.done = true;
|
|
155
|
+
this.aborted = false;
|
|
156
|
+
this.emit("submit");
|
|
157
|
+
this.render();
|
|
158
|
+
this.out.write("\n");
|
|
159
|
+
this.close();
|
|
160
|
+
}
|
|
183
161
|
up() {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
if (this.value !== null) {
|
|
191
|
-
this.value = +(this.value + this.step).toFixed(precision(this.step));
|
|
192
|
-
if (this.value > this.max) {
|
|
193
|
-
this.value = this.max;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
this.emit('change');
|
|
198
|
-
this.render();
|
|
162
|
+
this.typed = "";
|
|
163
|
+
if (this.value !== null && this.value >= this.max) {
|
|
164
|
+
this.bell();
|
|
165
|
+
return;
|
|
199
166
|
}
|
|
200
|
-
|
|
167
|
+
if (this.value !== null) {
|
|
168
|
+
this.value = +(this.value + this.step).toFixed(precision(this.step));
|
|
169
|
+
if (this.value > this.max) {
|
|
170
|
+
this.value = this.max;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
this.emit("change");
|
|
174
|
+
this.render();
|
|
175
|
+
}
|
|
201
176
|
down() {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
this.emit('change');
|
|
216
|
-
this.render();
|
|
177
|
+
this.typed = "";
|
|
178
|
+
if (this.value !== null && this.value <= this.min) {
|
|
179
|
+
this.bell();
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (this.value !== null) {
|
|
183
|
+
this.value = +(this.value - this.step).toFixed(precision(this.step));
|
|
184
|
+
if (this.value < this.min) {
|
|
185
|
+
this.value = this.min;
|
|
186
|
+
}
|
|
217
187
|
}
|
|
218
|
-
|
|
188
|
+
this.emit("change");
|
|
189
|
+
this.render();
|
|
190
|
+
}
|
|
219
191
|
handleNumericInput(n) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
const now = Date.now();
|
|
226
|
-
|
|
227
|
-
if (now - this.lastHit > 1e3) {
|
|
228
|
-
this.typed = '';
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
this.typed += n;
|
|
232
|
-
this.lastHit = now;
|
|
233
|
-
const v = parseFloat(this.typed);
|
|
234
|
-
|
|
235
|
-
if (isNaN(v)) {
|
|
236
|
-
this.bell();
|
|
237
|
-
return;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
let newValue = v;
|
|
241
|
-
|
|
242
|
-
if (newValue > this.max) {
|
|
243
|
-
newValue = this.max;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
if (newValue < this.min) {
|
|
247
|
-
newValue = this.min;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
this.value = newValue;
|
|
251
|
-
this.emit('change');
|
|
252
|
-
this.render();
|
|
192
|
+
if (!isFloat.test(n)) {
|
|
193
|
+
this.bell();
|
|
194
|
+
return;
|
|
253
195
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
196
|
+
const now = Date.now();
|
|
197
|
+
if (now - this.lastHit > 1e3) {
|
|
198
|
+
this.typed = "";
|
|
257
199
|
}
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
} else {
|
|
265
|
-
out += esc.eraseLines(2) + esc.cursorTo(0);
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
out += [
|
|
269
|
-
ui.symbol(this.done, this.aborted),
|
|
270
|
-
chalk.bold(this.msg),
|
|
271
|
-
ui.delimiter(this.done),
|
|
272
|
-
this.value !== null ? this.value : '',
|
|
273
|
-
chalk.gray(this.unit),
|
|
274
|
-
].join(' ') + '\n';
|
|
275
|
-
const size = this.size - stringWidth(String(this.min)) - stringWidth(String(this.max)) - 6;
|
|
276
|
-
const barWidth = stringWidth(this.bar);
|
|
277
|
-
|
|
278
|
-
const left = Math.round((size - barWidth) * (this.value !== null ? this.value : 0) / (this.max - this.min));
|
|
279
|
-
|
|
280
|
-
const right = size - left - barWidth;
|
|
281
|
-
const leftBar = this.bar.repeat(Math.max(0, Math.floor(left / barWidth)));
|
|
282
|
-
const rightBar = this.bar.repeat(Math.max(0, Math.floor(right / barWidth)));
|
|
283
|
-
|
|
284
|
-
out += [
|
|
285
|
-
'',
|
|
286
|
-
this.min,
|
|
287
|
-
chalk.gray(leftBar) + this.marker + chalk.gray(rightBar),
|
|
288
|
-
this.max,
|
|
289
|
-
'',
|
|
290
|
-
].join(' ') + '\n';
|
|
291
|
-
this.out.write(out);
|
|
200
|
+
this.typed += n;
|
|
201
|
+
this.lastHit = now;
|
|
202
|
+
const v = parseFloat(this.typed);
|
|
203
|
+
if (isNaN(v)) {
|
|
204
|
+
this.bell();
|
|
205
|
+
return;
|
|
292
206
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
207
|
+
let newValue = v;
|
|
208
|
+
if (newValue > this.max) {
|
|
209
|
+
newValue = this.max;
|
|
296
210
|
}
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
right;
|
|
300
|
-
}const isFloat = /^[\d.]+$/;
|
|
301
|
-
|
|
302
|
-
export const rangePrompt = (msg, opt) => {
|
|
303
|
-
if (!isString(msg)) {
|
|
304
|
-
throw Error('Message must be string.');
|
|
211
|
+
if (newValue < this.min) {
|
|
212
|
+
newValue = this.min;
|
|
305
213
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
214
|
+
this.value = newValue;
|
|
215
|
+
this.emit("change");
|
|
216
|
+
this.render();
|
|
217
|
+
}
|
|
218
|
+
handleUnknownInput(input) {
|
|
219
|
+
this.bell();
|
|
220
|
+
}
|
|
221
|
+
render(first = false) {
|
|
222
|
+
let out = "";
|
|
223
|
+
if (first) {
|
|
224
|
+
out += esc.cursorHide;
|
|
225
|
+
} else {
|
|
226
|
+
out += esc.eraseLines(2) + esc.cursorTo(0);
|
|
309
227
|
}
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
228
|
+
out += [
|
|
229
|
+
ui.symbol(this.done, this.aborted),
|
|
230
|
+
chalk.bold(this.msg),
|
|
231
|
+
ui.delimiter(this.done),
|
|
232
|
+
this.value !== null ? this.value : "",
|
|
233
|
+
chalk.gray(this.unit)
|
|
234
|
+
].join(" ") + "\n";
|
|
235
|
+
const size = this.size - stringWidth(String(this.min)) - stringWidth(String(this.max)) - 6;
|
|
236
|
+
const barWidth = stringWidth(this.bar);
|
|
237
|
+
const left = Math.round(
|
|
238
|
+
(size - barWidth) * (this.value !== null ? this.value : 0) / (this.max - this.min)
|
|
239
|
+
);
|
|
240
|
+
const right = size - left - barWidth;
|
|
241
|
+
const leftBar = this.bar.repeat(Math.max(0, Math.floor(left / barWidth)));
|
|
242
|
+
const rightBar = this.bar.repeat(Math.max(0, Math.floor(right / barWidth)));
|
|
243
|
+
out += [
|
|
244
|
+
"",
|
|
245
|
+
this.min,
|
|
246
|
+
chalk.gray(leftBar) + this.marker + chalk.gray(rightBar),
|
|
247
|
+
this.max,
|
|
248
|
+
""
|
|
249
|
+
].join(" ") + "\n";
|
|
250
|
+
this.out.write(out);
|
|
251
|
+
}
|
|
252
|
+
bell() {
|
|
253
|
+
this.out.write("\x07");
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
left;
|
|
257
|
+
right;
|
|
258
|
+
}
|
|
259
|
+
const isFloat = /^[0-9.]+$/;
|
|
260
|
+
export const rangePrompt = (msg, opt) => {
|
|
261
|
+
if (typeof msg !== "string") {
|
|
262
|
+
throw new Error("Message must be string.");
|
|
263
|
+
}
|
|
264
|
+
if (Array.isArray(opt) || typeof opt !== "object") {
|
|
265
|
+
opt = {};
|
|
266
|
+
}
|
|
267
|
+
const prompt = new RangePrompt(msg, opt);
|
|
268
|
+
return wrap(prompt);
|
|
314
269
|
};
|
|
315
|
-
export default Object.assign(rangePrompt, {
|
|
316
|
-
RangePrompt,
|
|
317
|
-
});
|
|
270
|
+
export default Object.assign(rangePrompt, { RangePrompt });
|