@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.
Files changed (118) hide show
  1. package/dist-npm/components/anykey/index.js +77 -57
  2. package/dist-npm/components/block/block.js +61 -48
  3. package/dist-npm/components/checkbox/index.js +211 -178
  4. package/dist-npm/components/confirm/confirm-main.js +122 -86
  5. package/dist-npm/components/confirm/confirm-three.js +27 -24
  6. package/dist-npm/components/confirm/index.js +45 -36
  7. package/dist-npm/components/core/Separator.js +17 -15
  8. package/dist-npm/components/core/create-prompt.js +124 -101
  9. package/dist-npm/components/core/errors.js +15 -19
  10. package/dist-npm/components/core/hook-engine.js +120 -91
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +6 -16
  13. package/dist-npm/components/core/lines.js +54 -45
  14. package/dist-npm/components/core/make-theme.js +30 -21
  15. package/dist-npm/components/core/position.js +23 -27
  16. package/dist-npm/components/core/promise-polyfill.js +14 -11
  17. package/dist-npm/components/core/screen-manager.js +74 -59
  18. package/dist-npm/components/core/theme.js +32 -22
  19. package/dist-npm/components/core/use-effect.js +15 -9
  20. package/dist-npm/components/core/use-keypress.js +23 -19
  21. package/dist-npm/components/core/use-memo.js +16 -10
  22. package/dist-npm/components/core/use-pagination.js +32 -33
  23. package/dist-npm/components/core/use-prefix.js +38 -40
  24. package/dist-npm/components/core/use-ref.js +5 -2
  25. package/dist-npm/components/core/use-state.js +23 -15
  26. package/dist-npm/components/core/useKeyPress.js +17 -14
  27. package/dist-npm/components/core/usePromptState.js +14 -8
  28. package/dist-npm/components/core/utils.js +16 -7
  29. package/dist-npm/components/date/date.js +204 -168
  30. package/dist-npm/components/editor/index.js +92 -71
  31. package/dist-npm/components/expand/index.js +124 -96
  32. package/dist-npm/components/figures/index.js +294 -283
  33. package/dist-npm/components/input/index.js +87 -61
  34. package/dist-npm/components/input/text-main.js +124 -86
  35. package/dist-npm/components/input/text.js +28 -24
  36. package/dist-npm/components/instance/basic.js +25 -17
  37. package/dist-npm/components/instance/browser.js +18 -14
  38. package/dist-npm/components/instance/reporter/basic.js +65 -46
  39. package/dist-npm/components/instance/reporter/browser.js +47 -44
  40. package/dist-npm/components/instance/reporter/fancy.js +96 -83
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +62 -52
  43. package/dist-npm/components/mono/monoTwo.js +49 -35
  44. package/dist-npm/components/multiselect/group-multiselect.js +71 -55
  45. package/dist-npm/components/multiselect/multi-select-two.js +130 -98
  46. package/dist-npm/components/multiselect/multi-select.js +49 -43
  47. package/dist-npm/components/multiselect/multiselect-main.js +146 -120
  48. package/dist-npm/components/multiselect/num-multi-select.js +130 -98
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -24
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -96
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -120
  55. package/dist-npm/components/password/password-three.js +30 -26
  56. package/dist-npm/components/progressbar/ProgressBar.js +64 -45
  57. package/dist-npm/components/progressbar/helper.js +40 -33
  58. package/dist-npm/components/progressbar/index.js +1 -1
  59. package/dist-npm/components/prompts/create.js +44 -29
  60. package/dist-npm/components/prompts/index.js +45 -45
  61. package/dist-npm/components/prompts/prompt.js +260 -211
  62. package/dist-npm/components/prompts/promptTwo.js +605 -561
  63. package/dist-npm/components/prompts/relinka.js +295 -237
  64. package/dist-npm/components/range/range.js +294 -247
  65. package/dist-npm/components/rawlist/index.js +107 -87
  66. package/dist-npm/components/results/results.js +37 -31
  67. package/dist-npm/components/search/index.js +193 -148
  68. package/dist-npm/components/select/index.js +186 -148
  69. package/dist-npm/components/select/num-select-main.js +27 -27
  70. package/dist-npm/components/select/num-select.js +5 -125
  71. package/dist-npm/components/select/select-key.js +25 -24
  72. package/dist-npm/components/select/select-main.js +133 -109
  73. package/dist-npm/components/select/select-three.js +36 -32
  74. package/dist-npm/components/select/select-two.js +87 -95
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.d.ts +1 -1
  77. package/dist-npm/components/st-end/end.js +26 -35
  78. package/dist-npm/components/st-end/start.d.ts +1 -1
  79. package/dist-npm/components/st-end/start.js +15 -30
  80. package/dist-npm/components/toggle/index.js +137 -113
  81. package/dist-npm/components/visual/animate/animate.js +10 -53
  82. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  83. package/dist-npm/mod.js +2 -1
  84. package/dist-npm/testing/index.js +83 -58
  85. package/dist-npm/types/general.d.ts +2 -1
  86. package/dist-npm/types/general.js +1 -0
  87. package/dist-npm/types/index.js +3 -2
  88. package/dist-npm/types/keypress.js +36 -35
  89. package/dist-npm/types/readline.js +1 -0
  90. package/dist-npm/types/relinka.js +1 -0
  91. package/dist-npm/types/utils.js +1 -0
  92. package/dist-npm/utils/box.js +137 -135
  93. package/dist-npm/utils/color.js +74 -65
  94. package/dist-npm/utils/colorize.js +156 -124
  95. package/dist-npm/utils/component.js +657 -532
  96. package/dist-npm/utils/constants.js +63 -64
  97. package/dist-npm/utils/core.js +3 -2
  98. package/dist-npm/utils/decoder.js +223 -244
  99. package/dist-npm/utils/error.js +9 -4
  100. package/dist-npm/utils/errors.js +4 -14
  101. package/dist-npm/utils/format.js +24 -19
  102. package/dist-npm/utils/keypress.js +414 -316
  103. package/dist-npm/utils/log.js +15 -11
  104. package/dist-npm/utils/mapping.js +52 -45
  105. package/dist-npm/utils/messages.js +183 -183
  106. package/dist-npm/utils/platforms.js +20 -16
  107. package/dist-npm/utils/prompt-tmp.js +286 -235
  108. package/dist-npm/utils/prompt-two.js +286 -235
  109. package/dist-npm/utils/readline.js +7 -5
  110. package/dist-npm/utils/skeleton.js +170 -130
  111. package/dist-npm/utils/stream.js +2 -2
  112. package/dist-npm/utils/string.js +58 -44
  113. package/dist-npm/utils/terminal.js +34 -23
  114. package/dist-npm/utils/tree.js +41 -30
  115. package/dist-npm/utils/types.js +1 -0
  116. package/dist-npm/utils/utils.js +8 -8
  117. package/dist-npm/utils/variants.js +44 -36
  118. package/package.json +20 -28
@@ -1,270 +1,317 @@
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";
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
- 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
- /**
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
- 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();
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
- this.stdin.on("data", this.keyListener);
100
- this.render(true);
101
- }
108
+
102
109
  _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();
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
- this.emit("close");
116
- }
127
+
117
128
  onKeyPress(chunk) {
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;
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
- if (isFloat.test(key)) {
134
- this.handleNumericInput(key);
135
- } else {
136
- this.handleUnknownInput(key);
137
- }
138
- }
157
+
139
158
  reset() {
140
- this.typed = "";
141
- this.value = this.initialValue;
142
- this.emit("change");
143
- this.render();
144
- }
159
+ this.typed = '';
160
+ this.value = this.initialValue;
161
+ this.emit('change');
162
+ this.render();
163
+ }
164
+
145
165
  abort() {
146
- this.done = true;
147
- this.aborted = true;
148
- this.emit("abort");
149
- this.render();
150
- this.out.write("\n");
151
- this.close();
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
- this.done = true;
155
- this.aborted = false;
156
- this.emit("submit");
157
- this.render();
158
- this.out.write("\n");
159
- this.close();
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
- 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
- }
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
- this.emit("change");
174
- this.render();
175
- }
200
+
176
201
  down() {
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
- }
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
- this.emit("change");
189
- this.render();
190
- }
218
+
191
219
  handleNumericInput(n) {
192
- if (!isFloat.test(n)) {
193
- this.bell();
194
- return;
195
- }
196
- const now = Date.now();
197
- if (now - this.lastHit > 1e3) {
198
- this.typed = "";
199
- }
200
- this.typed += n;
201
- this.lastHit = now;
202
- const v = parseFloat(this.typed);
203
- if (isNaN(v)) {
204
- this.bell();
205
- return;
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
- let newValue = v;
208
- if (newValue > this.max) {
209
- newValue = this.max;
254
+
255
+ handleUnknownInput() {
256
+ this.bell();
210
257
  }
211
- if (newValue < this.min) {
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
- let out = "";
223
- if (first) {
224
- out += esc.cursorHide;
225
- } else {
226
- out += esc.eraseLines(2) + esc.cursorTo(0);
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
- 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
- }
293
+
252
294
  bell() {
253
- this.out.write("\x07");
254
- }
255
-
256
- left;
257
- right;
258
- }
259
- const isFloat = /^[0-9.]+$/;
295
+ this.out.write('\x07');
296
+ }
297
+
298
+ left;
299
+ right;
300
+ }const isFloat = /^[\d.]+$/;
301
+
260
302
  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);
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, { RangePrompt });
315
+ export default Object.assign(rangePrompt, {
316
+ RangePrompt,
317
+ });