@reliverse/relinka 1.1.5 → 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 (115) 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 -85
  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 -167
  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 -97
  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 -97
  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 -97
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -23
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -95
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -119
  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 -124
  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 -94
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.js +26 -34
  77. package/dist-npm/components/st-end/start.js +15 -29
  78. package/dist-npm/components/toggle/index.js +137 -113
  79. package/dist-npm/components/visual/animate/animate.js +10 -53
  80. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  81. package/dist-npm/mod.js +2 -1
  82. package/dist-npm/testing/index.js +83 -58
  83. package/dist-npm/types/general.js +1 -0
  84. package/dist-npm/types/index.js +3 -2
  85. package/dist-npm/types/keypress.js +36 -35
  86. package/dist-npm/types/readline.js +1 -0
  87. package/dist-npm/types/relinka.js +1 -0
  88. package/dist-npm/types/utils.js +1 -0
  89. package/dist-npm/utils/box.js +137 -135
  90. package/dist-npm/utils/color.js +74 -65
  91. package/dist-npm/utils/colorize.js +156 -124
  92. package/dist-npm/utils/component.js +657 -532
  93. package/dist-npm/utils/constants.js +63 -64
  94. package/dist-npm/utils/core.js +3 -2
  95. package/dist-npm/utils/decoder.js +223 -244
  96. package/dist-npm/utils/error.js +9 -4
  97. package/dist-npm/utils/errors.js +4 -14
  98. package/dist-npm/utils/format.js +24 -19
  99. package/dist-npm/utils/keypress.js +414 -316
  100. package/dist-npm/utils/log.js +15 -11
  101. package/dist-npm/utils/mapping.js +52 -45
  102. package/dist-npm/utils/messages.js +183 -183
  103. package/dist-npm/utils/platforms.js +20 -16
  104. package/dist-npm/utils/prompt-tmp.js +286 -235
  105. package/dist-npm/utils/prompt-two.js +286 -235
  106. package/dist-npm/utils/readline.js +7 -5
  107. package/dist-npm/utils/skeleton.js +170 -130
  108. package/dist-npm/utils/stream.js +2 -2
  109. package/dist-npm/utils/string.js +58 -44
  110. package/dist-npm/utils/terminal.js +34 -23
  111. package/dist-npm/utils/tree.js +41 -30
  112. package/dist-npm/utils/types.js +1 -0
  113. package/dist-npm/utils/utils.js +8 -8
  114. package/dist-npm/utils/variants.js +44 -36
  115. package/package.json +20 -28
@@ -1,630 +1,755 @@
1
- import color from "picocolors";
2
- import { cursor, erase } from "sisteransi";
1
+ import color from 'picocolors';
2
+ import {cursor, erase} from 'sisteransi';
3
+ import process from 'node:process';
3
4
  import {
4
- block,
5
- ConfirmPrompt,
6
- GroupMultiSelectPrompt,
7
- isCancel,
8
- MultiSelectPrompt,
9
- PasswordPrompt,
10
- SelectKeyPrompt,
11
- SelectPrompt,
12
- TextPrompt
13
- } from "../components/prompts/index.js";
14
- import { isUnicodeSupported } from "../utils/platforms.js";
15
- export { isCancel } from "../components/prompts/prompt.js";
5
+ block,
6
+ ConfirmPrompt,
7
+ GroupMultiSelectPrompt,
8
+ isCancel,
9
+ MultiSelectPrompt,
10
+ PasswordPrompt,
11
+ SelectKeyPrompt,
12
+ SelectPrompt,
13
+ TextPrompt,
14
+ } from '../components/prompts/index.js';
15
+ import {isUnicodeSupported} from '../utils/platforms.js';
16
+
17
+ export {isCancel} from '../components/prompts/prompt.js';
18
+ const isString = (a) => typeof a === 'string';
16
19
  const unicode = isUnicodeSupported();
17
20
  const s = (c, fallback) => unicode ? c : fallback;
18
- const S_STEP_ACTIVE = s("\u25C6", "*");
19
- const S_STEP_CANCEL = s("\u25A0", "x");
20
- const S_STEP_ERROR = s("\u25B2", "x");
21
- const S_STEP_SUBMIT = s("\u25C7", "o");
22
- const S_BAR_START = s("\u250C", "T");
23
- const S_BAR = s("\u2502", "|");
24
- const S_BAR_END = s("\u2514", "\u2014");
25
- const S_RADIO_ACTIVE = s("\u25CF", ">");
26
- const S_RADIO_INACTIVE = s("\u25CB", " ");
27
- const S_CHECKBOX_ACTIVE = s("\u25FB", "[\u2022]");
28
- const S_CHECKBOX_SELECTED = s("\u25FC", "[+]");
29
- const S_CHECKBOX_INACTIVE = s("\u25FB", "[ ]");
30
- const S_PASSWORD_MASK = s("\u25AA", "\u2022");
31
- const S_BAR_H = s("\u2500", "-");
32
- const S_CORNER_TOP_RIGHT = s("\u256E", "+");
33
- const S_CONNECT_LEFT = s("\u251C", "+");
34
- const S_CORNER_BOTTOM_RIGHT = s("\u256F", "+");
35
- const S_INFO = s("\u25CF", "\u2022");
36
- const S_SUCCESS = s("\u25C6", "*");
37
- const S_WARN = s("\u25B2", "!");
38
- const S_ERROR = s("\u25A0", "x");
21
+ const S_STEP_ACTIVE = s('\u25C6', '*');
22
+ const S_STEP_CANCEL = s('\u25A0', 'x');
23
+ const S_STEP_ERROR = s('\u25B2', 'x');
24
+ const S_STEP_SUBMIT = s('\u25C7', 'o');
25
+ const S_BAR_START = s('\u250C', 'T');
26
+ const S_BAR = s('\u2502', '|');
27
+ const S_BAR_END = s('\u2514', '\u2014');
28
+ const S_RADIO_ACTIVE = s('\u25CF', '>');
29
+ const S_RADIO_INACTIVE = s('\u25CB', ' ');
30
+ const S_CHECKBOX_ACTIVE = s('\u25FB', '[\u2022]');
31
+ const S_CHECKBOX_SELECTED = s('\u25FC', '[+]');
32
+ const S_CHECKBOX_INACTIVE = s('\u25FB', '[ ]');
33
+ const S_PASSWORD_MASK = s('\u25AA', '\u2022');
34
+ const S_BAR_H = s('\u2500', '-');
35
+ const S_CORNER_TOP_RIGHT = s('\u256E', '+');
36
+ const S_CONNECT_LEFT = s('\u251C', '+');
37
+ const S_CORNER_BOTTOM_RIGHT = s('\u256F', '+');
38
+ const S_INFO = s('\u25CF', '\u2022');
39
+ const S_SUCCESS = s('\u25C6', '*');
40
+ const S_WARN = s('\u25B2', '!');
41
+ const S_ERROR = s('\u25A0', 'x');
42
+
39
43
  const symbol = (state) => {
40
- switch (state) {
41
- case "initial":
42
- case "active":
43
- return color.cyan(S_STEP_ACTIVE);
44
- case "cancel":
45
- return color.red(S_STEP_CANCEL);
46
- case "error":
47
- return color.yellow(S_STEP_ERROR);
48
- case "submit":
49
- return color.green(S_STEP_SUBMIT);
50
- }
44
+ switch(state) {
45
+ case 'initial':
46
+ case 'active':
47
+ return color.cyan(S_STEP_ACTIVE);
48
+
49
+ case 'cancel':
50
+ return color.red(S_STEP_CANCEL);
51
+
52
+ case 'error':
53
+ return color.yellow(S_STEP_ERROR);
54
+
55
+ case 'submit':
56
+ return color.green(S_STEP_SUBMIT);
57
+ }
51
58
  };
59
+
52
60
  const limitOptions = (params) => {
53
- const { cursor: cursor2, options, style } = params;
54
- const paramMaxItems = params.maxItems ?? Infinity;
55
- const outputMaxItems = Math.max(process.stdout.rows - 4, 0);
56
- const maxItems = Math.min(outputMaxItems, Math.max(paramMaxItems, 5));
57
- let slidingWindowLocation = 0;
58
- if (cursor2 >= slidingWindowLocation + maxItems - 3) {
59
- slidingWindowLocation = Math.max(
60
- Math.min(cursor2 - maxItems + 3, options.length - maxItems),
61
- 0
62
- );
63
- } else if (cursor2 < slidingWindowLocation + 2) {
64
- slidingWindowLocation = Math.max(cursor2 - 2, 0);
65
- }
66
- const shouldRenderTopEllipsis = maxItems < options.length && slidingWindowLocation > 0;
67
- const shouldRenderBottomEllipsis = maxItems < options.length && slidingWindowLocation + maxItems < options.length;
68
- return options.slice(slidingWindowLocation, slidingWindowLocation + maxItems).map((option, i, arr) => {
69
- const isTopLimit = i === 0 && shouldRenderTopEllipsis;
70
- const isBottomLimit = i === arr.length - 1 && shouldRenderBottomEllipsis;
71
- return isTopLimit || isBottomLimit ? color.dim("...") : style(option, i + slidingWindowLocation === cursor2);
72
- });
61
+ const {
62
+ cursor: cursor2,
63
+ options,
64
+ style,
65
+ } = params;
66
+ const paramMaxItems = params.maxItems ?? Infinity;
67
+ const outputMaxItems = Math.max(process.stdout.rows - 4, 0);
68
+ const maxItems = Math.min(outputMaxItems, Math.max(
69
+ paramMaxItems,
70
+ 5,
71
+ ));
72
+ let slidingWindowLocation = 0;
73
+
74
+ if (cursor2 >= slidingWindowLocation + maxItems - 3) {
75
+ slidingWindowLocation = Math.max(Math.min(cursor2 - maxItems + 3, options.length - maxItems), 0);
76
+ } else if (cursor2 < slidingWindowLocation + 2) {
77
+ slidingWindowLocation = Math.max(cursor2 - 2, 0);
78
+ }
79
+
80
+
81
+ const shouldRenderTopEllipsis = maxItems < options.length && slidingWindowLocation > 0;
82
+ const shouldRenderBottomEllipsis = maxItems < options.length && options.length > slidingWindowLocation + maxItems;
83
+
84
+ return options
85
+ .slice(slidingWindowLocation, slidingWindowLocation + maxItems)
86
+ .map((option, i, arr) => {
87
+ const isTopLimit = !i && shouldRenderTopEllipsis;
88
+ const isBottomLimit = i === arr.length - 1 && shouldRenderBottomEllipsis;
89
+
90
+ return isTopLimit || isBottomLimit ? color.dim('...') : style(option, cursor2 === i + slidingWindowLocation);
91
+ });
73
92
  };
93
+
74
94
  export const text = (opts) => {
75
- return new TextPrompt({
76
- validate: opts.validate,
77
- placeholder: opts.placeholder,
78
- defaultValue: opts.defaultValue,
79
- initialValue: opts.initialValue,
80
- render() {
81
- const title = `${color.gray(S_BAR)}
95
+ return new TextPrompt({
96
+ validate: opts.validate,
97
+ placeholder: opts.placeholder,
98
+ defaultValue: opts.defaultValue,
99
+ initialValue: opts.initialValue,
100
+ render() {
101
+ const title = `${color.gray(S_BAR)}
82
102
  ${symbol(this.state)} ${opts.message}
83
103
  `;
84
- const placeholder = opts.placeholder ? color.inverse(opts.placeholder[0]) + color.dim(opts.placeholder.slice(1)) : color.inverse(color.hidden("_"));
85
- const value = !this.value ? placeholder : this.valueWithCursor;
86
- switch (this.state) {
87
- case "error":
88
- return `${title.trim()}
104
+
105
+ const placeholder = opts.placeholder ? color.inverse(opts.placeholder[0]) + color.dim(opts.placeholder.slice(1)) : color.inverse(color.hidden('_'));
106
+ const value = !this.value ? placeholder : this.valueWithCursor;
107
+
108
+ switch(this.state) {
109
+ case 'error':
110
+ return `${title.trim()}
89
111
  ${color.yellow(S_BAR)} ${value}
90
- ${color.yellow(
91
- S_BAR_END
92
- )} ${color.yellow(this.error)}
112
+ ${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
93
113
  `;
94
- case "submit":
95
- return `${title}${color.gray(S_BAR)} ${color.dim(this.value || opts.placeholder)}`;
96
- case "cancel":
97
- return `${title}${color.gray(S_BAR)} ${color.strikethrough(
98
- color.dim(this.value ?? "")
99
- )}${this.value?.trim() ? `
100
- ${color.gray(S_BAR)}` : ""}`;
101
- default:
102
- return `${title}${color.cyan(S_BAR)} ${value}
114
+
115
+ case 'submit':
116
+ return `${title}${color.gray(S_BAR)} ${color.dim(this.value || opts.placeholder)}`;
117
+
118
+ case 'cancel':
119
+ return `${title}${color.gray(S_BAR)} ${color.strikethrough(color.dim(this.value ?? ''))}${this.value?.trim() ? `
120
+ ${color.gray(S_BAR)}` : ''}`;
121
+
122
+ default:
123
+ return `${title}${color.cyan(S_BAR)} ${value}
103
124
  ${color.cyan(S_BAR_END)}
104
125
  `;
105
- }
106
- }
107
- }).prompt();
126
+ }
127
+ },
128
+ }).prompt();
108
129
  };
109
130
  export const password = (opts) => {
110
- return new PasswordPrompt({
111
- validate: opts.validate,
112
- mask: opts.mask ?? S_PASSWORD_MASK,
113
- render() {
114
- const title = `${color.gray(S_BAR)}
131
+ return new PasswordPrompt({
132
+ validate: opts.validate,
133
+ mask: opts.mask ?? S_PASSWORD_MASK,
134
+ render() {
135
+ const title = `${color.gray(S_BAR)}
115
136
  ${symbol(this.state)} ${opts.message}
116
137
  `;
117
- const value = this.valueWithCursor;
118
- const masked = this.masked;
119
- switch (this.state) {
120
- case "error":
121
- return `${title.trim()}
138
+
139
+ const value = this.valueWithCursor;
140
+ const {masked} = this;
141
+
142
+ switch(this.state) {
143
+ case 'error':
144
+ return `${title.trim()}
122
145
  ${color.yellow(S_BAR)} ${masked}
123
- ${color.yellow(
124
- S_BAR_END
125
- )} ${color.yellow(this.error)}
146
+ ${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
126
147
  `;
127
- case "submit":
128
- return `${title}${color.gray(S_BAR)} ${color.dim(masked)}`;
129
- case "cancel":
130
- return `${title}${color.gray(S_BAR)} ${color.strikethrough(color.dim(masked ?? ""))}${masked ? `
131
- ${color.gray(S_BAR)}` : ""}`;
132
- default:
133
- return `${title}${color.cyan(S_BAR)} ${value}
148
+
149
+ case 'submit':
150
+ return `${title}${color.gray(S_BAR)} ${color.dim(masked)}`;
151
+
152
+ case 'cancel':
153
+ return `${title}${color.gray(S_BAR)} ${color.strikethrough(color.dim(masked ?? ''))}${masked ? `
154
+ ${color.gray(S_BAR)}` : ''}`;
155
+
156
+ default:
157
+ return `${title}${color.cyan(S_BAR)} ${value}
134
158
  ${color.cyan(S_BAR_END)}
135
159
  `;
136
- }
137
- }
138
- }).prompt();
160
+ }
161
+ },
162
+ }).prompt();
139
163
  };
140
164
  export const confirm = (opts) => {
141
- const active = opts.active ?? "Yes";
142
- const inactive = opts.inactive ?? "No";
143
- return new ConfirmPrompt({
144
- active,
145
- inactive,
146
- initialValue: opts.initialValue ?? true,
147
- render() {
148
- const title = `${color.gray(S_BAR)}
165
+ const active = opts.active ?? 'Yes';
166
+ const inactive = opts.inactive ?? 'No';
167
+
168
+ return new ConfirmPrompt({
169
+ active,
170
+ inactive,
171
+ initialValue: opts.initialValue ?? true,
172
+ render() {
173
+ const title = `${color.gray(S_BAR)}
149
174
  ${symbol(this.state)} ${opts.message}
150
175
  `;
151
- const value = this.value ? active : inactive;
152
- switch (this.state) {
153
- case "submit":
154
- return `${title}${color.gray(S_BAR)} ${color.dim(value)}`;
155
- case "cancel":
156
- return `${title}${color.gray(S_BAR)} ${color.strikethrough(
157
- color.dim(value)
158
- )}
176
+
177
+ const value = this.value ? active : inactive;
178
+
179
+ switch(this.state) {
180
+ case 'submit':
181
+ return `${title}${color.gray(S_BAR)} ${color.dim(value)}`;
182
+
183
+ case 'cancel':
184
+ return `${title}${color.gray(S_BAR)} ${color.strikethrough(color.dim(value))}
159
185
  ${color.gray(S_BAR)}`;
160
- default: {
161
- return `${title}${color.cyan(S_BAR)} ${this.value ? `${color.green(S_RADIO_ACTIVE)} ${active}` : `${color.dim(S_RADIO_INACTIVE)} ${color.dim(active)}`} ${color.dim("/")} ${!this.value ? `${color.green(S_RADIO_ACTIVE)} ${inactive}` : `${color.dim(S_RADIO_INACTIVE)} ${color.dim(inactive)}`}
186
+
187
+ default:
188
+ return `${title}${color.cyan(S_BAR)} ${this.value ? `${color.green(S_RADIO_ACTIVE)} ${active}` : `${color.dim(S_RADIO_INACTIVE)} ${color.dim(active)}`} ${color.dim('/')} ${!this.value ? `${color.green(S_RADIO_ACTIVE)} ${inactive}` : `${color.dim(S_RADIO_INACTIVE)} ${color.dim(inactive)}`}
162
189
  ${color.cyan(S_BAR_END)}
163
190
  `;
164
- }
165
- }
166
- }
167
- }).prompt();
191
+ }
192
+ },
193
+ }).prompt();
168
194
  };
169
195
  export const select = (opts) => {
170
- const opt = (option, state) => {
171
- const label = option.label ?? String(option.value);
172
- switch (state) {
173
- case "selected":
174
- return color.dim(label);
175
- case "active":
176
- return `${color.green(S_RADIO_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
177
- case "cancelled":
178
- return color.strikethrough(color.dim(label));
179
- default:
180
- return `${color.dim(S_RADIO_INACTIVE)} ${color.dim(label)}`;
181
- }
182
- };
183
- return new SelectPrompt({
184
- options: opts.options,
185
- initialValue: opts.initialValue,
186
- render() {
187
- const title = `${color.gray(S_BAR)}
196
+ const opt = (option, state) => {
197
+ const label = option.label ?? String(option.value);
198
+
199
+ switch(state) {
200
+ case 'selected':
201
+ return color.dim(label);
202
+
203
+ case 'active':
204
+ return `${color.green(S_RADIO_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
205
+
206
+ case 'cancelled':
207
+ return color.strikethrough(color.dim(label));
208
+
209
+ default:
210
+ return `${color.dim(S_RADIO_INACTIVE)} ${color.dim(label)}`;
211
+ }
212
+ };
213
+
214
+ return new SelectPrompt({
215
+ options: opts.options,
216
+ initialValue: opts.initialValue,
217
+ render() {
218
+ const title = `${color.gray(S_BAR)}
188
219
  ${symbol(this.state)} ${opts.message}
189
220
  `;
190
- switch (this.state) {
191
- case "submit":
192
- return `${title}${color.gray(S_BAR)} ${opt(this.options[this.cursor], "selected")}`;
193
- case "cancel":
194
- return `${title}${color.gray(S_BAR)} ${opt(
195
- this.options[this.cursor],
196
- "cancelled"
197
- )}
221
+
222
+ switch(this.state) {
223
+ case 'submit':
224
+ return `${title}${color.gray(S_BAR)} ${opt(this.options[this.cursor], 'selected')}`;
225
+
226
+ case 'cancel':
227
+ return `${title}${color.gray(S_BAR)} ${opt(this.options[this.cursor], 'cancelled')}
198
228
  ${color.gray(S_BAR)}`;
199
- default: {
200
- return `${title}${color.cyan(S_BAR)} ${limitOptions({
201
- cursor: this.cursor,
202
- options: this.options,
203
- maxItems: opts.maxItems,
204
- style: (item, active) => opt(item, active ? "active" : "inactive")
205
- }).join(`
229
+
230
+ default:
231
+ return `${title}${color.cyan(S_BAR)} ${limitOptions({
232
+ cursor: this.cursor,
233
+ options: this.options,
234
+ maxItems: opts.maxItems,
235
+ style: (item, active) => opt(item, active ? 'active' : 'inactive'),
236
+ }).join(`
206
237
  ${color.cyan(S_BAR)} `)}
207
238
  ${color.cyan(S_BAR_END)}
208
239
  `;
209
- }
210
- }
211
- }
212
- }).prompt();
240
+ }
241
+ },
242
+ }).prompt();
213
243
  };
214
244
  export const selectKey = (opts) => {
215
- const opt = (option, state = "inactive") => {
216
- const label = option.label ?? String(option.value);
217
- if (state === "selected") {
218
- return color.dim(label);
219
- } else if (state === "cancelled") {
220
- return color.strikethrough(color.dim(label));
221
- } else if (state === "active") {
222
- return `${color.bgCyan(color.gray(` ${option.value} `))} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
223
- }
224
- return `${color.gray(color.bgWhite(color.inverse(` ${option.value} `)))} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
225
- };
226
- return new SelectKeyPrompt({
227
- options: opts.options,
228
- initialValue: opts.initialValue,
229
- render() {
230
- const title = `${color.gray(S_BAR)}
245
+ const opt = (option, state = 'inactive') => {
246
+ const label = option.label ?? String(option.value);
247
+
248
+ if (state === 'selected') {
249
+ return color.dim(label);
250
+ }
251
+
252
+ if (state === 'cancelled') {
253
+ return color.strikethrough(color.dim(label));
254
+ }
255
+
256
+ if (state === 'active') {
257
+ return `${color.bgCyan(color.gray(` ${option.value} `))} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
258
+ }
259
+
260
+ return `${color.gray(color.bgWhite(color.inverse(` ${option.value} `)))} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
261
+ };
262
+
263
+ return new SelectKeyPrompt({
264
+ options: opts.options,
265
+ initialValue: opts.initialValue,
266
+ render() {
267
+ const title = `${color.gray(S_BAR)}
231
268
  ${symbol(this.state)} ${opts.message}
232
269
  `;
233
- switch (this.state) {
234
- case "submit":
235
- return `${title}${color.gray(S_BAR)} ${opt(
236
- this.options.find((opt2) => opt2.value === this.value),
237
- "selected"
238
- )}`;
239
- case "cancel":
240
- return `${title}${color.gray(S_BAR)} ${opt(this.options[0], "cancelled")}
241
- ${color.gray(
242
- S_BAR
243
- )}`;
244
- default: {
245
- return `${title}${color.cyan(S_BAR)} ${this.options.map(
246
- (option, i) => opt(option, i === this.cursor ? "active" : "inactive")
247
- ).join(`
270
+
271
+ switch(this.state) {
272
+ case 'submit':
273
+ return `${title}${color.gray(S_BAR)} ${opt(this.options.find((opt2) => opt2.value === this.value), 'selected')}`;
274
+
275
+ case 'cancel':
276
+ return `${title}${color.gray(S_BAR)} ${opt(this.options[0], 'cancelled')}
277
+ ${color.gray(S_BAR)}`;
278
+
279
+ default:
280
+ return `${title}${color.cyan(S_BAR)} ${this
281
+ .options
282
+ .map((option, i) => opt(option, i === this.cursor ? 'active' : 'inactive'))
283
+ .join(`
248
284
  ${color.cyan(S_BAR)} `)}
249
285
  ${color.cyan(S_BAR_END)}
250
286
  `;
251
- }
252
- }
253
- }
254
- }).prompt();
287
+ }
288
+ },
289
+ }).prompt();
255
290
  };
256
291
  export const multiselect = (opts) => {
257
- const opt = (option, state) => {
258
- const label = option.label ?? String(option.value);
259
- if (state === "active") {
260
- return `${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
261
- } else if (state === "selected") {
262
- return `${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
263
- } else if (state === "cancelled") {
264
- return color.strikethrough(color.dim(label));
265
- } else if (state === "active-selected") {
266
- return `${color.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
267
- } else if (state === "submitted") {
268
- return color.dim(label);
269
- }
270
- return `${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(label)}`;
271
- };
272
- return new MultiSelectPrompt({
273
- options: opts.options,
274
- initialValues: opts.initialValues,
275
- required: opts.required ?? true,
276
- cursorAt: opts.cursorAt,
277
- validate(selected) {
278
- if (this.required && selected.length === 0) {
279
- return `Please select at least one option.
280
- ${color.reset(
281
- color.dim(
282
- `Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(
283
- color.bgWhite(color.inverse(" enter "))
284
- )} to submit`
285
- )
286
- )}`;
287
- }
288
- },
289
- render() {
290
- const title = `${color.gray(S_BAR)}
291
- ${symbol(this.state)} ${opts.message}
292
- `;
293
- const styleOption = (option, active) => {
294
- const selected = this.value.includes(option.value);
295
- if (active && selected) {
296
- return opt(option, "active-selected");
292
+ const opt = (option, state) => {
293
+ const label = option.label ?? String(option.value);
294
+
295
+ if (state === 'active') {
296
+ return `${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
297
297
  }
298
- if (selected) {
299
- return opt(option, "selected");
298
+
299
+ if (state === 'selected') {
300
+ return `${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
300
301
  }
301
- return opt(option, active ? "active" : "inactive");
302
- };
303
- switch (this.state) {
304
- case "submit": {
305
- return `${title}${color.gray(S_BAR)} ${this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(color.dim(", ")) || color.dim("none")}`;
302
+
303
+ if (state === 'cancelled') {
304
+ return color.strikethrough(color.dim(label));
306
305
  }
307
- case "cancel": {
308
- const label = this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "cancelled")).join(color.dim(", "));
309
- return `${title}${color.gray(S_BAR)} ${label.trim() ? `${label}
310
- ${color.gray(S_BAR)}` : ""}`;
306
+
307
+ if (state === 'active-selected') {
308
+ return `${color.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
311
309
  }
312
- case "error": {
313
- const footer = this.error.split("\n").map(
314
- (ln, i) => i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`
315
- ).join("\n");
316
- return `${title + color.yellow(S_BAR)} ${limitOptions({
317
- options: this.options,
318
- cursor: this.cursor,
319
- maxItems: opts.maxItems,
320
- style: styleOption
321
- }).join(`
310
+
311
+ if (state === 'submitted') {
312
+ return color.dim(label);
313
+ }
314
+
315
+ return `${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(label)}`;
316
+ };
317
+
318
+ return new MultiSelectPrompt({
319
+ options: opts.options,
320
+ initialValues: opts.initialValues,
321
+ required: opts.required ?? true,
322
+ cursorAt: opts.cursorAt,
323
+ validate(selected) {
324
+ if (this.required && !selected.length) {
325
+ return `Please select at least one option.
326
+ ${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(color.bgWhite(color.inverse(' enter ')))} to submit`))}`;
327
+ }
328
+ },
329
+ render() {
330
+ const title = `${color.gray(S_BAR)}
331
+ ${symbol(this.state)} ${opts.message}
332
+ `;
333
+
334
+ const styleOption = (option, active) => {
335
+ const selected = this.value.includes(option.value);
336
+
337
+ if (active && selected) {
338
+ return opt(option, 'active-selected');
339
+ }
340
+
341
+ if (selected) {
342
+ return opt(option, 'selected');
343
+ }
344
+
345
+ return opt(option, active ? 'active' : 'inactive');
346
+ };
347
+
348
+ switch(this.state) {
349
+ case 'submit':
350
+ return `${title}${color.gray(S_BAR)} ${this
351
+ .options
352
+ .filter(({value}) => this.value.includes(value))
353
+ .map((option) => opt(option, 'submitted'))
354
+ .join(color.dim(', ')) || color.dim('none')}`;
355
+
356
+ case 'cancel': {
357
+ const label = this
358
+ .options
359
+ .filter(({value}) => this.value.includes(value))
360
+ .map((option) => opt(option, 'cancelled'))
361
+ .join(color.dim(', '));
362
+
363
+ return `${title}${color.gray(S_BAR)} ${label.trim() ? `${label}
364
+ ${color.gray(S_BAR)}` : ''}`;
365
+ }
366
+
367
+ case 'error': {
368
+ const footer = this
369
+ .error
370
+ .split('\n')
371
+ .map((ln, i) => !i ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`)
372
+ .join('\n');
373
+
374
+ return `${title + color.yellow(S_BAR)} ${limitOptions({
375
+ options: this.options,
376
+ cursor: this.cursor,
377
+ maxItems: opts.maxItems,
378
+ style: styleOption,
379
+ }).join(`
322
380
  ${color.yellow(S_BAR)} `)}
323
381
  ${footer}
324
382
  `;
325
- }
326
- default: {
327
- return `${title}${color.cyan(S_BAR)} ${limitOptions({
328
- options: this.options,
329
- cursor: this.cursor,
330
- maxItems: opts.maxItems,
331
- style: styleOption
332
- }).join(`
383
+ }
384
+
385
+ default:
386
+ return `${title}${color.cyan(S_BAR)} ${limitOptions({
387
+ options: this.options,
388
+ cursor: this.cursor,
389
+ maxItems: opts.maxItems,
390
+ style: styleOption,
391
+ }).join(`
333
392
  ${color.cyan(S_BAR)} `)}
334
393
  ${color.cyan(S_BAR_END)}
335
394
  `;
336
- }
337
- }
338
- }
339
- }).prompt();
395
+ }
396
+ },
397
+ }).prompt();
340
398
  };
341
399
  export const groupMultiselect = (opts) => {
342
- const opt = (option, state, options = []) => {
343
- const label = option.label ?? String(option.value);
344
- const isItem = typeof option.group === "string";
345
- const next = isItem && (options[options.indexOf(option) + 1] ?? { group: true });
346
- const isLast = isItem && next.group === true;
347
- const prefix = isItem ? `${isLast ? S_BAR_END : S_BAR} ` : "";
348
- if (state === "active") {
349
- return `${color.dim(prefix)}${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
350
- } else if (state === "group-active") {
351
- return `${prefix}${color.cyan(S_CHECKBOX_ACTIVE)} ${color.dim(label)}`;
352
- } else if (state === "group-active-selected") {
353
- return `${prefix}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
354
- } else if (state === "selected") {
355
- return `${color.dim(prefix)}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
356
- } else if (state === "cancelled") {
357
- return color.strikethrough(color.dim(label));
358
- } else if (state === "active-selected") {
359
- return `${color.dim(prefix)}${color.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ""}`;
360
- } else if (state === "submitted") {
361
- return color.dim(label);
362
- }
363
- return `${color.dim(prefix)}${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(label)}`;
364
- };
365
- return new GroupMultiSelectPrompt({
366
- options: opts.options,
367
- initialValues: opts.initialValues,
368
- required: opts.required ?? true,
369
- cursorAt: opts.cursorAt,
370
- validate(selected) {
371
- if (this.required && selected.length === 0) {
372
- return `Please select at least one option.
373
- ${color.reset(
374
- color.dim(
375
- `Press ${color.gray(color.bgWhite(color.inverse(" space ")))} to select, ${color.gray(
376
- color.bgWhite(color.inverse(" enter "))
377
- )} to submit`
378
- )
379
- )}`;
380
- }
381
- },
382
- render() {
383
- const title = `${color.gray(S_BAR)}
384
- ${symbol(this.state)} ${opts.message}
385
- `;
386
- switch (this.state) {
387
- case "submit": {
388
- return `${title}${color.gray(S_BAR)} ${this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "submitted")).join(color.dim(", "))}`;
400
+ const opt = (option, state, options = []) => {
401
+ const label = option.label ?? String(option.value);
402
+ const isItem = isString(option.group);
403
+ const next = isItem && (options[options.indexOf(option) + 1] ?? {
404
+ group: true,
405
+ });
406
+ const isLast = isItem && next.group;
407
+ const prefix = isItem ? `${isLast ? S_BAR_END : S_BAR} ` : '';
408
+
409
+ if (state === 'active') {
410
+ return `${color.dim(prefix)}${color.cyan(S_CHECKBOX_ACTIVE)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
389
411
  }
390
- case "cancel": {
391
- const label = this.options.filter(({ value }) => this.value.includes(value)).map((option) => opt(option, "cancelled")).join(color.dim(", "));
392
- return `${title}${color.gray(S_BAR)} ${label.trim() ? `${label}
393
- ${color.gray(S_BAR)}` : ""}`;
412
+
413
+ if (state === 'group-active') {
414
+ return `${prefix}${color.cyan(S_CHECKBOX_ACTIVE)} ${color.dim(label)}`;
394
415
  }
395
- case "error": {
396
- const footer = this.error.split("\n").map(
397
- (ln, i) => i === 0 ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`
398
- ).join("\n");
399
- return `${title}${color.yellow(S_BAR)} ${this.options.map((option, i, options) => {
400
- const selected = this.value.includes(option.value) || option.group === true && this.isGroupSelected(`${option.value}`);
401
- const active = i === this.cursor;
402
- const groupActive = !active && typeof option.group === "string" && this.options[this.cursor].value === option.group;
403
- if (groupActive) {
404
- return opt(
405
- option,
406
- selected ? "group-active-selected" : "group-active",
407
- options
408
- );
409
- }
410
- if (active && selected) {
411
- return opt(option, "active-selected", options);
416
+
417
+ if (state === 'group-active-selected') {
418
+ return `${prefix}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
419
+ }
420
+
421
+ if (state === 'selected') {
422
+ return `${color.dim(prefix)}${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
423
+ }
424
+
425
+ if (state === 'cancelled') {
426
+ return color.strikethrough(color.dim(label));
427
+ }
428
+
429
+ if (state === 'active-selected') {
430
+ return `${color.dim(prefix)}${color.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
431
+ }
432
+
433
+ if (state === 'submitted') {
434
+ return color.dim(label);
435
+ }
436
+
437
+ return `${color.dim(prefix)}${color.dim(S_CHECKBOX_INACTIVE)} ${color.dim(label)}`;
438
+ };
439
+
440
+ return new GroupMultiSelectPrompt({
441
+ options: opts.options,
442
+ initialValues: opts.initialValues,
443
+ required: opts.required ?? true,
444
+ cursorAt: opts.cursorAt,
445
+ validate(selected) {
446
+ if (this.required && !selected.length) {
447
+ return `Please select at least one option.
448
+ ${color.reset(color.dim(`Press ${color.gray(color.bgWhite(color.inverse(' space ')))} to select, ${color.gray(color.bgWhite(color.inverse(' enter ')))} to submit`))}`;
412
449
  }
413
- if (selected) {
414
- return opt(option, "selected", options);
450
+ },
451
+ render() {
452
+ const title = `${color.gray(S_BAR)}
453
+ ${symbol(this.state)} ${opts.message}
454
+ `;
455
+
456
+ switch(this.state) {
457
+ case 'submit':
458
+ return `${title}${color.gray(S_BAR)} ${this
459
+ .options
460
+ .filter(({value}) => this.value.includes(value))
461
+ .map((option) => opt(option, 'submitted'))
462
+ .join(color.dim(', '))}`;
463
+
464
+ case 'cancel': {
465
+ const label = this
466
+ .options
467
+ .filter(({value}) => this.value.includes(value))
468
+ .map((option) => opt(option, 'cancelled'))
469
+ .join(color.dim(', '));
470
+
471
+ return `${title}${color.gray(S_BAR)} ${label.trim() ? `${label}
472
+ ${color.gray(S_BAR)}` : ''}`;
415
473
  }
416
- return opt(option, active ? "active" : "inactive", options);
417
- }).join(`
474
+
475
+ case 'error': {
476
+ const footer = this
477
+ .error
478
+ .split('\n')
479
+ .map((ln, i) => !i ? `${color.yellow(S_BAR_END)} ${color.yellow(ln)}` : ` ${ln}`)
480
+ .join('\n');
481
+
482
+ return `${title}${color.yellow(S_BAR)} ${this
483
+ .options
484
+ .map((option, i, options) => {
485
+ const selected = this.value.includes(option.value) || option.group && this.isGroupSelected(String(option.value));
486
+ const active = i === this.cursor;
487
+ const groupActive = !active && isString(option.group) && this.options[this.cursor].value === option.group;
488
+
489
+ if (groupActive) {
490
+ return opt(option, selected ? 'group-active-selected' : 'group-active', options);
491
+ }
492
+
493
+ if (active && selected) {
494
+ return opt(option, 'active-selected', options);
495
+ }
496
+
497
+ if (selected) {
498
+ return opt(option, 'selected', options);
499
+ }
500
+
501
+ return opt(option, active ? 'active' : 'inactive', options);
502
+ })
503
+ .join(`
418
504
  ${color.yellow(S_BAR)} `)}
419
505
  ${footer}
420
506
  `;
421
- }
422
- default: {
423
- return `${title}${color.cyan(S_BAR)} ${this.options.map((option, i, options) => {
424
- const selected = this.value.includes(option.value) || option.group === true && this.isGroupSelected(`${option.value}`);
425
- const active = i === this.cursor;
426
- const groupActive = !active && typeof option.group === "string" && this.options[this.cursor].value === option.group;
427
- if (groupActive) {
428
- return opt(
429
- option,
430
- selected ? "group-active-selected" : "group-active",
431
- options
432
- );
433
507
  }
434
- if (active && selected) {
435
- return opt(option, "active-selected", options);
436
- }
437
- if (selected) {
438
- return opt(option, "selected", options);
439
- }
440
- return opt(option, active ? "active" : "inactive", options);
441
- }).join(`
508
+
509
+ default:
510
+ return `${title}${color.cyan(S_BAR)} ${this
511
+ .options
512
+ .map((option, i, options) => {
513
+ const selected = this.value.includes(option.value) || option.group && this.isGroupSelected(String(option.value));
514
+ const active = i === this.cursor;
515
+ const groupActive = !active && isString(option.group) && this.options[this.cursor].value === option.group;
516
+
517
+ if (groupActive) {
518
+ return opt(option, selected ? 'group-active-selected' : 'group-active', options);
519
+ }
520
+
521
+ if (active && selected) {
522
+ return opt(option, 'active-selected', options);
523
+ }
524
+
525
+ if (selected) {
526
+ return opt(option, 'selected', options);
527
+ }
528
+
529
+ return opt(option, active ? 'active' : 'inactive', options);
530
+ })
531
+ .join(`
442
532
  ${color.cyan(S_BAR)} `)}
443
533
  ${color.cyan(S_BAR_END)}
444
534
  `;
445
- }
446
- }
447
- }
448
- }).prompt();
535
+ }
536
+ },
537
+ }).prompt();
449
538
  };
450
- const strip = (str) => str.replace(ansiRegex(), "");
451
- export const note = (message = "", title = "") => {
452
- const lines = `
539
+ const strip = (str) => str.replace(ansiRegex(), '');
540
+
541
+ export const note = (message = '', title = '') => {
542
+ const lines = `
453
543
  ${message}
454
- `.split("\n");
455
- const titleLen = strip(title).length;
456
- const len = Math.max(
457
- lines.reduce((sum, ln) => {
458
- ln = strip(ln);
459
- return ln.length > sum ? ln.length : sum;
460
- }, 0),
461
- titleLen
462
- ) + 2;
463
- const msg = lines.map(
464
- (ln) => `${color.gray(S_BAR)} ${color.dim(ln)}${" ".repeat(len - strip(ln).length)}${color.gray(
465
- S_BAR
466
- )}`
467
- ).join("\n");
468
- process.stdout.write(
469
- `${color.gray(S_BAR)}
470
- ${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray(
471
- S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT
472
- )}
544
+ `.split('\n');
545
+
546
+ const titleLen = strip(title).length;
547
+ const len = Math.max(lines.reduce((sum, ln) => {
548
+ ln = strip(ln);
549
+ return ln.length > sum ? ln.length : sum;
550
+ }, 0), titleLen) + 2;
551
+
552
+ const msg = lines
553
+ .map((ln) => `${color.gray(S_BAR)} ${color.dim(ln)}${' '.repeat(len - strip(ln).length)}${color.gray(S_BAR)}`)
554
+ .join('\n');
555
+
556
+ process.stdout.write(`${color.gray(S_BAR)}
557
+ ${color.green(S_STEP_SUBMIT)} ${color.reset(title)} ${color.gray(S_BAR_H.repeat(Math.max(len - titleLen - 1, 1)) + S_CORNER_TOP_RIGHT)}
473
558
  ${msg}
474
559
  ${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}
475
- `
476
- );
560
+ `);
477
561
  };
478
- export const cancel = (message = "") => {
479
- process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
562
+ export const cancel = (message = '') => {
563
+ process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
480
564
 
481
565
  `);
482
566
  };
483
- export const intro = (title = "") => {
484
- process.stdout.write(`${color.gray(S_BAR_START)} ${title}
567
+ export const intro = (title = '') => {
568
+ process.stdout.write(`${color.gray(S_BAR_START)} ${title}
485
569
  `);
486
570
  };
487
- export const outro = (message = "") => {
488
- process.stdout.write(
489
- `${color.gray(S_BAR)}
571
+ export const outro = (message = '') => {
572
+ process.stdout.write(`${color.gray(S_BAR)}
490
573
  ${color.gray(S_BAR_END)} ${message}
491
574
 
492
- `
493
- );
575
+ `);
494
576
  };
495
577
  export const log = {
496
- message: (message = "", { symbol: symbol2 = color.gray(S_BAR) } = {}) => {
497
- const parts = [color.gray(S_BAR)];
498
- if (message) {
499
- const [firstLine, ...lines] = message.split("\n");
500
- parts.push(
501
- `${symbol2} ${firstLine}`,
502
- ...lines.map((ln) => `${color.gray(S_BAR)} ${ln}`)
503
- );
504
- }
505
- process.stdout.write(`${parts.join("\n")}
578
+ message: (message = '', {symbol: symbol2 = color.gray(S_BAR)} = {}) => {
579
+ const parts = [color.gray(S_BAR)];
580
+
581
+ if (message) {
582
+ const [firstLine, ...lines] = message.split('\n');
583
+
584
+ parts.push(`${symbol2} ${firstLine}`, ...lines.map((ln) => `${color.gray(S_BAR)} ${ln}`));
585
+ }
586
+
587
+ process.stdout.write(`${parts.join('\n')}
506
588
  `);
507
- },
508
- info: (message) => {
509
- log.message(message, { symbol: color.blue(S_INFO) });
510
- },
511
- success: (message) => {
512
- log.message(message, { symbol: color.green(S_SUCCESS) });
513
- },
514
- step: (message) => {
515
- log.message(message, { symbol: color.green(S_STEP_SUBMIT) });
516
- },
517
- warn: (message) => {
518
- log.message(message, { symbol: color.yellow(S_WARN) });
519
- },
589
+ },
590
+ info: (message) => {
591
+ log.message(message, {
592
+ symbol: color.blue(S_INFO),
593
+ });
594
+ },
595
+ success: (message) => {
596
+ log.message(message, {
597
+ symbol: color.green(S_SUCCESS),
598
+ });
599
+ },
600
+ step: (message) => {
601
+ log.message(message, {
602
+ symbol: color.green(S_STEP_SUBMIT),
603
+ });
604
+ },
605
+ warn: (message) => {
606
+ log.message(message, {
607
+ symbol: color.yellow(S_WARN),
608
+ });
609
+ },
520
610
  warning: (message) => {
521
- log.warn(message);
522
- },
523
- error: (message) => {
524
- log.message(message, { symbol: color.red(S_ERROR) });
525
- }
611
+ log.warn(message);
612
+ },
613
+ error: (message) => {
614
+ log.message(message, {
615
+ symbol: color.red(S_ERROR),
616
+ });
617
+ },
526
618
  };
527
619
  export const spinner = () => {
528
- const frames = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"];
529
- const delay = unicode ? 80 : 120;
530
- let unblock;
531
- let loop;
532
- let isSpinnerActive = false;
533
- let _message = "";
534
- const handleExit = (code) => {
535
- const msg = code > 1 ? "Something went wrong" : "Canceled";
536
- if (isSpinnerActive) {
537
- stop(msg, code);
538
- }
539
- };
540
- const errorEventHandler = () => handleExit(2);
541
- const signalEventHandler = () => handleExit(1);
542
- const registerHooks = () => {
543
- process.on("uncaughtExceptionMonitor", errorEventHandler);
544
- process.on("unhandledRejection", errorEventHandler);
545
- process.on("SIGINT", signalEventHandler);
546
- process.on("SIGTERM", signalEventHandler);
547
- process.on("exit", handleExit);
548
- };
549
- const clearHooks = () => {
550
- process.removeListener("uncaughtExceptionMonitor", errorEventHandler);
551
- process.removeListener("unhandledRejection", errorEventHandler);
552
- process.removeListener("SIGINT", signalEventHandler);
553
- process.removeListener("SIGTERM", signalEventHandler);
554
- process.removeListener("exit", handleExit);
555
- };
556
- const start = (msg = "") => {
557
- isSpinnerActive = true;
558
- unblock = block();
559
- _message = msg.replace(/\.+$/, "");
560
- process.stdout.write(`${color.gray(S_BAR)}
620
+ const frames = unicode ? [
621
+ '\u25D2',
622
+ '\u25D0',
623
+ '\u25D3',
624
+ '\u25D1',
625
+ ] : [
626
+ '\u2022',
627
+ 'o',
628
+ 'O',
629
+ '0',
630
+ ];
631
+ const delay = unicode ? 80 : 120;
632
+ let unblock;
633
+ let loop;
634
+ let isSpinnerActive = false;
635
+ let _message = '';
636
+
637
+ const handleExit = (code) => {
638
+ const msg = code > 1 ? 'Something went wrong' : 'Canceled';
639
+
640
+ if (isSpinnerActive) {
641
+ stop(msg, code);
642
+ }
643
+ };
644
+
645
+ const errorEventHandler = () => handleExit(2);
646
+ const signalEventHandler = () => handleExit(1);
647
+
648
+ const registerHooks = () => {
649
+ process.on('uncaughtExceptionMonitor', errorEventHandler);
650
+ process.on('unhandledRejection', errorEventHandler);
651
+ process.on('SIGINT', signalEventHandler);
652
+ process.on('SIGTERM', signalEventHandler);
653
+ process.on('exit', handleExit);
654
+ };
655
+
656
+ const clearHooks = () => {
657
+ process.removeListener('uncaughtExceptionMonitor', errorEventHandler);
658
+ process.removeListener('unhandledRejection', errorEventHandler);
659
+ process.removeListener('SIGINT', signalEventHandler);
660
+ process.removeListener('SIGTERM', signalEventHandler);
661
+ process.removeListener('exit', handleExit);
662
+ };
663
+
664
+ const start = (msg = '') => {
665
+ isSpinnerActive = true;
666
+ unblock = block();
667
+ _message = msg.replace(/\.+$/, '');
668
+ process.stdout.write(`${color.gray(S_BAR)}
561
669
  `);
562
- let frameIndex = 0;
563
- let dotsTimer = 0;
564
- registerHooks();
565
- loop = setInterval(() => {
566
- const frame = color.magenta(frames[frameIndex]);
567
- const loadingDots = ".".repeat(Math.floor(dotsTimer)).slice(0, 3);
568
- process.stdout.write(cursor.move(-999, 0));
569
- process.stdout.write(erase.down(1));
570
- process.stdout.write(`${frame} ${_message}${loadingDots}`);
571
- frameIndex = frameIndex + 1 < frames.length ? frameIndex + 1 : 0;
572
- dotsTimer = dotsTimer < frames.length ? dotsTimer + 0.125 : 0;
573
- }, delay);
574
- };
575
- const stop = (msg = "", code = 0) => {
576
- _message = msg ?? _message;
577
- isSpinnerActive = false;
578
- clearInterval(loop);
579
- const step = code === 0 ? color.green(S_STEP_SUBMIT) : code === 1 ? color.red(S_STEP_CANCEL) : color.red(S_STEP_ERROR);
580
- process.stdout.write(cursor.move(-999, 0));
581
- process.stdout.write(erase.down(1));
582
- process.stdout.write(`${step} ${_message}
670
+ let frameIndex = 0;
671
+ let dotsTimer = 0;
672
+
673
+ registerHooks();
674
+ loop = setInterval(() => {
675
+ const frame = color.magenta(frames[frameIndex]);
676
+ const loadingDots = '.'
677
+ .repeat(Math.floor(dotsTimer))
678
+ .slice(0, 3);
679
+ process.stdout.write(cursor.move(-999, 0));
680
+ process.stdout.write(erase.down(1));
681
+ process.stdout.write(`${frame} ${_message}${loadingDots}`);
682
+ frameIndex = frames.length > frameIndex + 1 ? frameIndex + 1 : 0;
683
+ dotsTimer = dotsTimer < frames.length ? dotsTimer + 0.125 : 0;
684
+ }, delay);
685
+ };
686
+
687
+ const stop = (msg = '', code = 0) => {
688
+ _message = msg ?? _message;
689
+ isSpinnerActive = false;
690
+ clearInterval(loop);
691
+ const step = !code ? color.green(S_STEP_SUBMIT) : code === 1 ? color.red(S_STEP_CANCEL) : color.red(S_STEP_ERROR);
692
+ process.stdout.write(cursor.move(-999, 0));
693
+ process.stdout.write(erase.down(1));
694
+ process.stdout.write(`${step} ${_message}
583
695
  `);
584
- clearHooks();
585
- unblock();
586
- };
587
- const message = (msg = "") => {
588
- _message = msg ?? _message;
589
- };
590
- return {
591
- start,
592
- stop,
593
- message
594
- };
696
+ clearHooks();
697
+ unblock();
698
+ };
699
+
700
+ const message = (msg = '') => {
701
+ _message = msg ?? _message;
702
+ };
703
+
704
+ return {
705
+ start,
706
+ stop,
707
+ message,
708
+ };
595
709
  };
596
710
  function ansiRegex() {
597
- const pattern = [
598
- "[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)",
599
- "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"
600
- ].join("|");
601
- return new RegExp(pattern, "g");
711
+ const pattern = [
712
+ '[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
713
+ '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))',
714
+ ].join('|');
715
+
716
+ return new RegExp(pattern, 'g');
602
717
  }
718
+
603
719
  export const group = async (prompts, opts) => {
604
- const results = {};
605
- const promptNames = Object.keys(prompts);
606
- for (const name of promptNames) {
607
- const prompt = prompts[name];
608
- const result = await prompt({ results })?.catch((e) => {
609
- throw e;
610
- });
611
- if (typeof opts?.onCancel === "function" && isCancel(result)) {
612
- results[name] = "canceled";
613
- opts.onCancel({ results });
614
- continue;
720
+ const results = {};
721
+ const promptNames = Object.keys(prompts);
722
+
723
+ for (const name of promptNames) {
724
+ const prompt = prompts[name];
725
+ const result = prompt({
726
+ results,
727
+ })?.catch((e) => {
728
+ throw e;
729
+ });
730
+
731
+ if (typeof opts?.onCancel === 'function' && isCancel(result)) {
732
+ results[name] = 'canceled';
733
+ opts.onCancel({
734
+ results,
735
+ });
736
+ continue;
737
+ }
738
+
739
+ results[name] = result;
615
740
  }
616
- results[name] = result;
617
- }
618
- return results;
741
+
742
+ return results;
619
743
  };
620
744
  export const tasks = async (tasks2) => {
621
- for (const task of tasks2) {
622
- if (!task.enabled) {
623
- continue;
745
+ for (const task of tasks2) {
746
+ if (!task.enabled) {
747
+ continue;
748
+ }
749
+
750
+ const s2 = spinner();
751
+ s2.start(task.title);
752
+ const result = await task.task(s2.message);
753
+ s2.stop(result || task.title);
624
754
  }
625
- const s2 = spinner();
626
- s2.start(task.title);
627
- const result = await task.task(s2.message);
628
- s2.stop(result || task.title);
629
- }
630
755
  };