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