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