@reliverse/relinka 1.1.7 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/dist-npm/components/anykey/index.js +57 -77
  2. package/dist-npm/components/block/block.js +48 -61
  3. package/dist-npm/components/checkbox/index.js +178 -211
  4. package/dist-npm/components/confirm/confirm-main.js +85 -122
  5. package/dist-npm/components/confirm/confirm-three.js +24 -27
  6. package/dist-npm/components/confirm/index.js +36 -45
  7. package/dist-npm/components/core/Separator.js +15 -17
  8. package/dist-npm/components/core/create-prompt.js +101 -124
  9. package/dist-npm/components/core/errors.js +19 -15
  10. package/dist-npm/components/core/hook-engine.js +91 -120
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +16 -6
  13. package/dist-npm/components/core/lines.js +45 -54
  14. package/dist-npm/components/core/make-theme.js +21 -30
  15. package/dist-npm/components/core/position.js +27 -23
  16. package/dist-npm/components/core/promise-polyfill.js +11 -14
  17. package/dist-npm/components/core/screen-manager.js +59 -74
  18. package/dist-npm/components/core/theme.js +22 -32
  19. package/dist-npm/components/core/use-effect.js +9 -15
  20. package/dist-npm/components/core/use-keypress.js +19 -23
  21. package/dist-npm/components/core/use-memo.js +10 -16
  22. package/dist-npm/components/core/use-pagination.js +33 -32
  23. package/dist-npm/components/core/use-prefix.js +40 -38
  24. package/dist-npm/components/core/use-ref.js +2 -5
  25. package/dist-npm/components/core/use-state.js +15 -23
  26. package/dist-npm/components/core/useKeyPress.js +14 -17
  27. package/dist-npm/components/core/usePromptState.js +8 -14
  28. package/dist-npm/components/core/utils.js +7 -16
  29. package/dist-npm/components/date/date.js +173 -204
  30. package/dist-npm/components/editor/index.js +71 -92
  31. package/dist-npm/components/expand/index.js +96 -124
  32. package/dist-npm/components/figures/index.js +283 -294
  33. package/dist-npm/components/input/index.js +61 -87
  34. package/dist-npm/components/input/text-main.js +97 -124
  35. package/dist-npm/components/input/text.js +24 -28
  36. package/dist-npm/components/instance/basic.js +17 -25
  37. package/dist-npm/components/instance/browser.js +14 -18
  38. package/dist-npm/components/instance/reporter/basic.js +46 -65
  39. package/dist-npm/components/instance/reporter/browser.js +44 -47
  40. package/dist-npm/components/instance/reporter/fancy.js +83 -96
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +52 -62
  43. package/dist-npm/components/mono/monoTwo.js +35 -49
  44. package/dist-npm/components/multiselect/group-multiselect.js +55 -71
  45. package/dist-npm/components/multiselect/multi-select-two.js +97 -130
  46. package/dist-npm/components/multiselect/multi-select.js +43 -49
  47. package/dist-npm/components/multiselect/multiselect-main.d.ts +1 -0
  48. package/dist-npm/components/multiselect/multiselect-main.js +158 -145
  49. package/dist-npm/components/multiselect/num-multi-select.js +97 -130
  50. package/dist-npm/components/multiselect/num-multiselect-main.js +24 -35
  51. package/dist-npm/components/next-steps/next-steps.js +23 -25
  52. package/dist-npm/components/number/index.js +78 -112
  53. package/dist-npm/components/number/number-main.js +95 -2
  54. package/dist-npm/components/password/index.js +54 -73
  55. package/dist-npm/components/password/password-main.js +119 -2
  56. package/dist-npm/components/password/password-three.js +26 -30
  57. package/dist-npm/components/progressbar/ProgressBar.js +45 -64
  58. package/dist-npm/components/progressbar/helper.js +33 -40
  59. package/dist-npm/components/progressbar/index.js +1 -1
  60. package/dist-npm/components/prompts/create.js +29 -44
  61. package/dist-npm/components/prompts/index.d.ts +1 -0
  62. package/dist-npm/components/prompts/index.js +46 -45
  63. package/dist-npm/components/prompts/prompt.js +211 -260
  64. package/dist-npm/components/prompts/promptTwo.js +561 -605
  65. package/dist-npm/components/prompts/relinka.js +237 -295
  66. package/dist-npm/components/range/range.js +247 -294
  67. package/dist-npm/components/rawlist/index.js +87 -107
  68. package/dist-npm/components/results/results.js +31 -37
  69. package/dist-npm/components/search/index.js +148 -193
  70. package/dist-npm/components/select/index.js +148 -186
  71. package/dist-npm/components/select/num-select-main.js +27 -27
  72. package/dist-npm/components/select/num-select.js +124 -5
  73. package/dist-npm/components/select/select-key.js +24 -25
  74. package/dist-npm/components/select/select-main.d.ts +1 -0
  75. package/dist-npm/components/select/select-main.js +143 -133
  76. package/dist-npm/components/select/select-three.js +32 -36
  77. package/dist-npm/components/select/select-two.js +94 -87
  78. package/dist-npm/components/spinner/index.js +107 -136
  79. package/dist-npm/components/st-end/end.js +34 -26
  80. package/dist-npm/components/st-end/start.js +29 -15
  81. package/dist-npm/components/toggle/index.js +113 -137
  82. package/dist-npm/components/visual/animate/animate.js +53 -10
  83. package/dist-npm/components/visual/ascii-art/ascii-art.js +12 -1
  84. package/dist-npm/main.js +1 -0
  85. package/dist-npm/testing/index.js +58 -83
  86. package/dist-npm/types/general.d.ts +1 -1
  87. package/dist-npm/types/general.js +0 -1
  88. package/dist-npm/types/index.js +2 -3
  89. package/dist-npm/types/keypress.js +35 -36
  90. package/dist-npm/types/readline.js +0 -1
  91. package/dist-npm/types/relinka.js +0 -1
  92. package/dist-npm/types/utils.js +0 -1
  93. package/dist-npm/utils/box.js +135 -137
  94. package/dist-npm/utils/color.js +65 -74
  95. package/dist-npm/utils/colorize.js +124 -156
  96. package/dist-npm/utils/component.js +532 -657
  97. package/dist-npm/utils/constants.js +64 -63
  98. package/dist-npm/utils/core.js +2 -3
  99. package/dist-npm/utils/decoder.js +244 -223
  100. package/dist-npm/utils/error.js +4 -9
  101. package/dist-npm/utils/errors.js +14 -4
  102. package/dist-npm/utils/format.js +19 -24
  103. package/dist-npm/utils/keypress.js +316 -414
  104. package/dist-npm/utils/log.js +11 -15
  105. package/dist-npm/utils/mapping.js +45 -52
  106. package/dist-npm/utils/messages.js +196 -183
  107. package/dist-npm/utils/platforms.js +16 -20
  108. package/dist-npm/utils/prompt-tmp.js +235 -286
  109. package/dist-npm/utils/prompt-two.js +235 -286
  110. package/dist-npm/utils/readline.js +5 -7
  111. package/dist-npm/utils/skeleton.js +130 -170
  112. package/dist-npm/utils/stream.js +2 -2
  113. package/dist-npm/utils/string.js +44 -58
  114. package/dist-npm/utils/terminal.js +23 -34
  115. package/dist-npm/utils/tree.js +30 -41
  116. package/dist-npm/utils/types.js +0 -1
  117. package/dist-npm/utils/utils.js +8 -8
  118. package/dist-npm/utils/variants.js +36 -44
  119. package/package.json +14 -14
  120. package/dist-npm/mod.js +0 -2
  121. /package/dist-npm/{mod.d.ts → main.d.ts} +0 -0
@@ -1,755 +1,630 @@
1
- import color from 'picocolors';
2
- import {cursor, erase} from 'sisteransi';
3
- import process from 'node:process';
1
+ import color from "picocolors";
2
+ import { cursor, erase } from "sisteransi";
4
3
  import {
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';
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";
19
16
  const unicode = isUnicodeSupported();
20
17
  const s = (c, fallback) => unicode ? c : fallback;
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
-
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");
43
39
  const symbol = (state) => {
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
- }
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
+ }
58
51
  };
59
-
60
52
  const limitOptions = (params) => {
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
- });
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
+ });
92
73
  };
93
-
94
74
  export const text = (opts) => {
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)}
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)}
102
82
  ${symbol(this.state)} ${opts.message}
103
83
  `;
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()}
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()}
111
89
  ${color.yellow(S_BAR)} ${value}
112
- ${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
90
+ ${color.yellow(
91
+ S_BAR_END
92
+ )} ${color.yellow(this.error)}
113
93
  `;
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}
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}
124
103
  ${color.cyan(S_BAR_END)}
125
104
  `;
126
- }
127
- },
128
- }).prompt();
105
+ }
106
+ }
107
+ }).prompt();
129
108
  };
130
109
  export const password = (opts) => {
131
- return new PasswordPrompt({
132
- validate: opts.validate,
133
- mask: opts.mask ?? S_PASSWORD_MASK,
134
- render() {
135
- const title = `${color.gray(S_BAR)}
110
+ return new PasswordPrompt({
111
+ validate: opts.validate,
112
+ mask: opts.mask ?? S_PASSWORD_MASK,
113
+ render() {
114
+ const title = `${color.gray(S_BAR)}
136
115
  ${symbol(this.state)} ${opts.message}
137
116
  `;
138
-
139
- const value = this.valueWithCursor;
140
- const {masked} = this;
141
-
142
- switch(this.state) {
143
- case 'error':
144
- return `${title.trim()}
117
+ const value = this.valueWithCursor;
118
+ const masked = this.masked;
119
+ switch (this.state) {
120
+ case "error":
121
+ return `${title.trim()}
145
122
  ${color.yellow(S_BAR)} ${masked}
146
- ${color.yellow(S_BAR_END)} ${color.yellow(this.error)}
123
+ ${color.yellow(
124
+ S_BAR_END
125
+ )} ${color.yellow(this.error)}
147
126
  `;
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}
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}
158
134
  ${color.cyan(S_BAR_END)}
159
135
  `;
160
- }
161
- },
162
- }).prompt();
136
+ }
137
+ }
138
+ }).prompt();
163
139
  };
164
140
  export const confirm = (opts) => {
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)}
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)}
174
149
  ${symbol(this.state)} ${opts.message}
175
150
  `;
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))}
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
+ )}
185
159
  ${color.gray(S_BAR)}`;
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)}`}
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)}`}
189
162
  ${color.cyan(S_BAR_END)}
190
163
  `;
191
- }
192
- },
193
- }).prompt();
164
+ }
165
+ }
166
+ }
167
+ }).prompt();
194
168
  };
195
169
  export const select = (opts) => {
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)}
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)}
219
188
  ${symbol(this.state)} ${opts.message}
220
189
  `;
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')}
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
+ )}
228
198
  ${color.gray(S_BAR)}`;
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(`
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(`
237
206
  ${color.cyan(S_BAR)} `)}
238
207
  ${color.cyan(S_BAR_END)}
239
208
  `;
240
- }
241
- },
242
- }).prompt();
209
+ }
210
+ }
211
+ }
212
+ }).prompt();
243
213
  };
244
214
  export const selectKey = (opts) => {
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)}
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)}
268
231
  ${symbol(this.state)} ${opts.message}
269
232
  `;
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(`
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(`
284
248
  ${color.cyan(S_BAR)} `)}
285
249
  ${color.cyan(S_BAR_END)}
286
250
  `;
287
- }
288
- },
289
- }).prompt();
251
+ }
252
+ }
253
+ }
254
+ }).prompt();
290
255
  };
291
256
  export const multiselect = (opts) => {
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
- }
298
-
299
- if (state === 'selected') {
300
- return `${color.green(S_CHECKBOX_SELECTED)} ${color.dim(label)}`;
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");
301
297
  }
302
-
303
- if (state === 'cancelled') {
304
- return color.strikethrough(color.dim(label));
298
+ if (selected) {
299
+ return opt(option, "selected");
305
300
  }
306
-
307
- if (state === 'active-selected') {
308
- return `${color.green(S_CHECKBOX_SELECTED)} ${label} ${option.hint ? color.dim(`(${option.hint})`) : ''}`;
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")}`;
309
306
  }
310
-
311
- if (state === 'submitted') {
312
- return color.dim(label);
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)}` : ""}`;
313
311
  }
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(`
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(`
380
322
  ${color.yellow(S_BAR)} `)}
381
323
  ${footer}
382
324
  `;
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(`
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(`
392
333
  ${color.cyan(S_BAR)} `)}
393
334
  ${color.cyan(S_BAR_END)}
394
335
  `;
395
- }
396
- },
397
- }).prompt();
336
+ }
337
+ }
338
+ }
339
+ }).prompt();
398
340
  };
399
341
  export const groupMultiselect = (opts) => {
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})`) : ''}`;
411
- }
412
-
413
- if (state === 'group-active') {
414
- return `${prefix}${color.cyan(S_CHECKBOX_ACTIVE)} ${color.dim(label)}`;
415
- }
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})`) : ''}`;
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(", "))}`;
431
389
  }
432
-
433
- if (state === 'submitted') {
434
- return color.dim(label);
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)}` : ""}`;
435
394
  }
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`))}`;
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
+ );
449
409
  }
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)}` : ''}`;
410
+ if (active && selected) {
411
+ return opt(option, "active-selected", options);
473
412
  }
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(`
413
+ if (selected) {
414
+ return opt(option, "selected", options);
415
+ }
416
+ return opt(option, active ? "active" : "inactive", options);
417
+ }).join(`
504
418
  ${color.yellow(S_BAR)} `)}
505
419
  ${footer}
506
420
  `;
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
+ );
507
433
  }
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(`
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(`
532
442
  ${color.cyan(S_BAR)} `)}
533
443
  ${color.cyan(S_BAR_END)}
534
444
  `;
535
- }
536
- },
537
- }).prompt();
445
+ }
446
+ }
447
+ }
448
+ }).prompt();
538
449
  };
539
- const strip = (str) => str.replace(ansiRegex(), '');
540
-
541
- export const note = (message = '', title = '') => {
542
- const lines = `
450
+ const strip = (str) => str.replace(ansiRegex(), "");
451
+ export const note = (message = "", title = "") => {
452
+ const lines = `
543
453
  ${message}
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)}
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
+ )}
558
473
  ${msg}
559
474
  ${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}
560
- `);
475
+ `
476
+ );
561
477
  };
562
- export const cancel = (message = '') => {
563
- process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
478
+ export const cancel = (message = "") => {
479
+ process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
564
480
 
565
481
  `);
566
482
  };
567
- export const intro = (title = '') => {
568
- process.stdout.write(`${color.gray(S_BAR_START)} ${title}
483
+ export const intro = (title = "") => {
484
+ process.stdout.write(`${color.gray(S_BAR_START)} ${title}
569
485
  `);
570
486
  };
571
- export const outro = (message = '') => {
572
- process.stdout.write(`${color.gray(S_BAR)}
487
+ export const outro = (message = "") => {
488
+ process.stdout.write(
489
+ `${color.gray(S_BAR)}
573
490
  ${color.gray(S_BAR_END)} ${message}
574
491
 
575
- `);
492
+ `
493
+ );
576
494
  };
577
495
  export const log = {
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')}
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")}
588
506
  `);
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
- },
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
+ },
610
520
  warning: (message) => {
611
- log.warn(message);
612
- },
613
- error: (message) => {
614
- log.message(message, {
615
- symbol: color.red(S_ERROR),
616
- });
617
- },
521
+ log.warn(message);
522
+ },
523
+ error: (message) => {
524
+ log.message(message, { symbol: color.red(S_ERROR) });
525
+ }
618
526
  };
619
527
  export const spinner = () => {
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)}
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)}
669
561
  `);
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}
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}
695
583
  `);
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
- };
584
+ clearHooks();
585
+ unblock();
586
+ };
587
+ const message = (msg = "") => {
588
+ _message = msg ?? _message;
589
+ };
590
+ return {
591
+ start,
592
+ stop,
593
+ message
594
+ };
709
595
  };
710
596
  function ansiRegex() {
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');
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");
717
602
  }
718
-
719
603
  export const group = async (prompts, opts) => {
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;
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;
740
615
  }
741
-
742
- return results;
616
+ results[name] = result;
617
+ }
618
+ return results;
743
619
  };
744
620
  export const tasks = async (tasks2) => {
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);
621
+ for (const task of tasks2) {
622
+ if (!task.enabled) {
623
+ continue;
754
624
  }
625
+ const s2 = spinner();
626
+ s2.start(task.title);
627
+ const result = await task.task(s2.message);
628
+ s2.stop(result || task.title);
629
+ }
755
630
  };