@reliverse/relinka 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist-npm/components/anykey/index.js +77 -57
  2. package/dist-npm/components/block/block.js +61 -48
  3. package/dist-npm/components/checkbox/index.js +211 -178
  4. package/dist-npm/components/confirm/confirm-main.js +122 -86
  5. package/dist-npm/components/confirm/confirm-three.js +27 -24
  6. package/dist-npm/components/confirm/index.js +45 -36
  7. package/dist-npm/components/core/Separator.js +17 -15
  8. package/dist-npm/components/core/create-prompt.js +124 -101
  9. package/dist-npm/components/core/errors.js +15 -19
  10. package/dist-npm/components/core/hook-engine.js +120 -91
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +6 -16
  13. package/dist-npm/components/core/lines.js +54 -45
  14. package/dist-npm/components/core/make-theme.js +30 -21
  15. package/dist-npm/components/core/position.js +23 -27
  16. package/dist-npm/components/core/promise-polyfill.js +14 -11
  17. package/dist-npm/components/core/screen-manager.js +74 -59
  18. package/dist-npm/components/core/theme.js +32 -22
  19. package/dist-npm/components/core/use-effect.js +15 -9
  20. package/dist-npm/components/core/use-keypress.js +23 -19
  21. package/dist-npm/components/core/use-memo.js +16 -10
  22. package/dist-npm/components/core/use-pagination.js +32 -33
  23. package/dist-npm/components/core/use-prefix.js +38 -40
  24. package/dist-npm/components/core/use-ref.js +5 -2
  25. package/dist-npm/components/core/use-state.js +23 -15
  26. package/dist-npm/components/core/useKeyPress.js +17 -14
  27. package/dist-npm/components/core/usePromptState.js +14 -8
  28. package/dist-npm/components/core/utils.js +16 -7
  29. package/dist-npm/components/date/date.js +204 -168
  30. package/dist-npm/components/editor/index.js +92 -71
  31. package/dist-npm/components/expand/index.js +124 -96
  32. package/dist-npm/components/figures/index.js +294 -283
  33. package/dist-npm/components/input/index.js +87 -61
  34. package/dist-npm/components/input/text-main.js +124 -86
  35. package/dist-npm/components/input/text.js +28 -24
  36. package/dist-npm/components/instance/basic.js +25 -17
  37. package/dist-npm/components/instance/browser.js +18 -14
  38. package/dist-npm/components/instance/reporter/basic.js +65 -46
  39. package/dist-npm/components/instance/reporter/browser.js +47 -44
  40. package/dist-npm/components/instance/reporter/fancy.js +96 -83
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +62 -52
  43. package/dist-npm/components/mono/monoTwo.js +49 -35
  44. package/dist-npm/components/multiselect/group-multiselect.js +71 -55
  45. package/dist-npm/components/multiselect/multi-select-two.js +130 -98
  46. package/dist-npm/components/multiselect/multi-select.js +49 -43
  47. package/dist-npm/components/multiselect/multiselect-main.js +146 -120
  48. package/dist-npm/components/multiselect/num-multi-select.js +130 -98
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -24
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -96
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -120
  55. package/dist-npm/components/password/password-three.js +30 -26
  56. package/dist-npm/components/progressbar/ProgressBar.js +64 -45
  57. package/dist-npm/components/progressbar/helper.js +40 -33
  58. package/dist-npm/components/progressbar/index.js +1 -1
  59. package/dist-npm/components/prompts/create.js +44 -29
  60. package/dist-npm/components/prompts/index.js +45 -45
  61. package/dist-npm/components/prompts/prompt.js +260 -211
  62. package/dist-npm/components/prompts/promptTwo.js +605 -561
  63. package/dist-npm/components/prompts/relinka.js +295 -237
  64. package/dist-npm/components/range/range.js +294 -247
  65. package/dist-npm/components/rawlist/index.js +107 -87
  66. package/dist-npm/components/results/results.js +37 -31
  67. package/dist-npm/components/search/index.js +193 -148
  68. package/dist-npm/components/select/index.js +186 -148
  69. package/dist-npm/components/select/num-select-main.js +27 -27
  70. package/dist-npm/components/select/num-select.js +5 -125
  71. package/dist-npm/components/select/select-key.js +25 -24
  72. package/dist-npm/components/select/select-main.js +133 -109
  73. package/dist-npm/components/select/select-three.js +36 -32
  74. package/dist-npm/components/select/select-two.js +87 -95
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.d.ts +1 -1
  77. package/dist-npm/components/st-end/end.js +26 -35
  78. package/dist-npm/components/st-end/start.d.ts +1 -1
  79. package/dist-npm/components/st-end/start.js +15 -30
  80. package/dist-npm/components/toggle/index.js +137 -113
  81. package/dist-npm/components/visual/animate/animate.js +10 -53
  82. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  83. package/dist-npm/mod.js +2 -1
  84. package/dist-npm/testing/index.js +83 -58
  85. package/dist-npm/types/general.d.ts +2 -1
  86. package/dist-npm/types/general.js +1 -0
  87. package/dist-npm/types/index.js +3 -2
  88. package/dist-npm/types/keypress.js +36 -35
  89. package/dist-npm/types/readline.js +1 -0
  90. package/dist-npm/types/relinka.js +1 -0
  91. package/dist-npm/types/utils.js +1 -0
  92. package/dist-npm/utils/box.js +137 -135
  93. package/dist-npm/utils/color.js +74 -65
  94. package/dist-npm/utils/colorize.js +156 -124
  95. package/dist-npm/utils/component.js +657 -532
  96. package/dist-npm/utils/constants.js +63 -64
  97. package/dist-npm/utils/core.js +3 -2
  98. package/dist-npm/utils/decoder.js +223 -244
  99. package/dist-npm/utils/error.js +9 -4
  100. package/dist-npm/utils/errors.js +4 -14
  101. package/dist-npm/utils/format.js +24 -19
  102. package/dist-npm/utils/keypress.js +414 -316
  103. package/dist-npm/utils/log.js +15 -11
  104. package/dist-npm/utils/mapping.js +52 -45
  105. package/dist-npm/utils/messages.js +183 -183
  106. package/dist-npm/utils/platforms.js +20 -16
  107. package/dist-npm/utils/prompt-tmp.js +286 -235
  108. package/dist-npm/utils/prompt-two.js +286 -235
  109. package/dist-npm/utils/readline.js +7 -5
  110. package/dist-npm/utils/skeleton.js +170 -130
  111. package/dist-npm/utils/stream.js +2 -2
  112. package/dist-npm/utils/string.js +58 -44
  113. package/dist-npm/utils/terminal.js +34 -23
  114. package/dist-npm/utils/tree.js +41 -30
  115. package/dist-npm/utils/types.js +1 -0
  116. package/dist-npm/utils/utils.js +8 -8
  117. package/dist-npm/utils/variants.js +44 -36
  118. package/package.json +20 -28
@@ -1,653 +1,697 @@
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";
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';
14
17
  const unicode = isUnicodeSupported();
15
18
  const s = (c, fallback) => unicode ? c : fallback;
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");
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
+
37
41
  const symbol = (state) => {
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);
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);
45
55
  }
46
- case "error": {
47
- return color.yellow(S_STEP_ERROR);
48
- }
49
- case "submit": {
50
- return color.green(S_STEP_SUBMIT);
51
- }
52
- }
53
56
  };
57
+
54
58
  export const text = (opts) => {
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)}
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)}
62
66
  ${symbol(this.state)} ${opts.message}
63
67
  `;
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
- )}
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)}
75
77
  `;
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
- )}
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)}
92
88
  `;
93
- }
94
- }
95
- }
96
- }).prompt();
89
+ }
90
+ },
91
+ }).prompt();
97
92
  };
98
93
  export const password = (opts) => {
99
- return new PasswordPrompt({
100
- validate: opts.validate,
101
- mask: opts.mask ?? S_PASSWORD_MASK,
102
- render() {
103
- const title = `${color.gray(S_BAR)}
94
+ return new PasswordPrompt({
95
+ validate: opts.validate,
96
+ mask: opts.mask ?? S_PASSWORD_MASK,
97
+ render() {
98
+ const title = `${color.gray(S_BAR)}
104
99
  ${symbol(this.state)} ${opts.message}
105
100
  `;
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
- )}
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)}
117
110
  `;
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
- )}
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)}
132
121
  `;
133
- }
134
- }
135
- }
136
- }).prompt();
122
+ }
123
+ },
124
+ }).prompt();
137
125
  };
138
126
  export const confirm = (opts) => {
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)}
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)}
147
136
  ${symbol(this.state)} ${opts.message}
148
137
  `;
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
- )}
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))}
158
147
  ${color.gray(S_BAR)}`;
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}`}
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}`}
162
151
  ${color.cyan(S_BAR_END)}
163
152
  `;
164
- }
165
- }
166
- }
167
- }).prompt();
153
+ }
154
+ },
155
+ }).prompt();
168
156
  };
169
157
  export const select = (opts) => {
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)}
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)}
190
181
  ${symbol(this.state)} ${opts.message}
191
182
  `;
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
- )}
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')}
212
203
  ${color.gray(S_BAR)}`;
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(`
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(`
218
211
  ${color.cyan(S_BAR)} `)}
219
212
  ${color.cyan(S_BAR_END)}
220
213
  `;
221
- }
222
- }
223
- }
224
- }).prompt();
214
+ }
215
+ },
216
+ }).prompt();
225
217
  };
226
218
  export const selectKey = (opts) => {
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)}
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)}
249
242
  ${symbol(this.state)} ${opts.message}
250
243
  `;
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
- )}
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')}
273
264
  ${color.gray(S_BAR)}`;
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(`
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(`
279
272
  ${color.cyan(S_BAR)} `)}
280
273
  ${color.cyan(S_BAR_END)}
281
274
  `;
282
- }
283
- }
284
- }
285
- }).prompt();
275
+ }
276
+ },
277
+ }).prompt();
286
278
  };
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)}
330
- ${symbol(this.state)} ${opts.message}
331
- `;
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)}` : ""}`;
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);
340
298
  }
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");
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`))}`;
350
313
  }
351
- if (selected) {
352
- return opt(option, "selected");
353
- }
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");
314
+ },
315
+ render() {
316
+ const title = `${color.gray(S_BAR)}
317
+ ${symbol(this.state)} ${opts.message}
318
+ `;
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)}` : ''}`;
364
337
  }
365
- if (selected) {
366
- return opt(option, "selected");
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';
367
367
  }
368
- return opt(option, active ? "active" : "inactive");
369
- }).join(`
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(`
370
387
  ${color.cyan(S_BAR)} `)}
371
388
  ${color.cyan(S_BAR_END)}
372
389
  `;
373
- }
374
- }
375
- }
376
- }).prompt();
390
+ }
391
+ },
392
+ }).prompt();
377
393
  };
378
394
  export const groupMultiselect = (opts) => {
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)}
439
- ${symbol(this.state)} ${opts.message}
440
- `;
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(", "))}`;
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);
444
425
  }
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);
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`))}`;
467
440
  }
468
- if (selected) {
469
- return opt(option, "selected", options);
441
+ },
442
+ render() {
443
+ const title = `${color.gray(S_BAR)}
444
+ ${symbol(this.state)} ${opts.message}
445
+ `;
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)}` : ''}`;
470
464
  }
471
- return opt(option, active ? "active" : "inactive", options);
472
- }).join(`
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(`
473
495
  ${color.yellow(S_BAR)} `)}
474
496
  ${footer}
475
497
  `;
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);
491
498
  }
492
- if (selected) {
493
- return opt(option, "selected", options);
494
- }
495
- return opt(option, active ? "active" : "inactive", options);
496
- }).join(`
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(`
497
523
  ${color.cyan(S_BAR)} `)}
498
524
  ${color.cyan(S_BAR_END)}
499
525
  `;
500
- }
501
- }
502
- }
503
- }).prompt();
526
+ }
527
+ },
528
+ }).prompt();
504
529
  };
505
- const strip = (str) => str.replace(ansiRegex(), "");
506
- export const note = (message = "", title = "") => {
507
- const lines = `
530
+ const strip = (str) => str.replace(ansiRegex(), '');
531
+
532
+ export const note = (message = '', title = '') => {
533
+ const lines = `
508
534
  ${message}
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
- )}
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)}
529
548
  ${msg}
530
- ${color.gray(
531
- S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT
532
- )}
533
- `
534
- );
549
+ ${color.gray(S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT)}
550
+ `);
535
551
  };
536
- export const cancel = (message = "") => {
537
- process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
552
+ export const cancel = (message = '') => {
553
+ process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
538
554
 
539
555
  `);
540
556
  };
541
- export const intro = (title = "") => {
542
- process.stdout.write(`${color.gray(S_BAR_START)} ${title}
557
+ export const intro = (title = '') => {
558
+ process.stdout.write(`${color.gray(S_BAR_START)} ${title}
543
559
  `);
544
560
  };
545
- export const outro = (message = "") => {
546
- process.stdout.write(
547
- `${color.gray(S_BAR)}
561
+ export const outro = (message = '') => {
562
+ process.stdout.write(`${color.gray(S_BAR)}
548
563
  ${color.gray(S_BAR_END)} ${message}
549
564
 
550
- `
551
- );
565
+ `);
552
566
  };
553
567
  export const log = {
554
- /**
568
+
569
+ /**
555
570
  * Logs an message, prefixed with a gray bar.
556
571
  * @param {string} message - The message to log.
557
572
  * @param {LogMessageOptions} [opts] - Optional settings for the log message. See {@link LogMessageOptions}.
558
573
  */
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")}
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')}
569
584
  `);
570
- },
585
+ },
571
586
  info: (message) => {
572
- log.message(message, { symbol: color.blue(S_INFO) });
573
- },
587
+ log.message(message, {
588
+ symbol: color.blue(S_INFO),
589
+ });
590
+ },
574
591
  success: (message) => {
575
- log.message(message, { symbol: color.green(S_SUCCESS) });
576
- },
592
+ log.message(message, {
593
+ symbol: color.green(S_SUCCESS),
594
+ });
595
+ },
577
596
  step: (message) => {
578
- log.message(message, { symbol: color.green(S_STEP_SUBMIT) });
579
- },
597
+ log.message(message, {
598
+ symbol: color.green(S_STEP_SUBMIT),
599
+ });
600
+ },
580
601
  warn: (message) => {
581
- log.message(message, { symbol: color.yellow(S_WARN) });
582
- },
602
+ log.message(message, {
603
+ symbol: color.yellow(S_WARN),
604
+ });
605
+ },
583
606
  warning: (message) => {
584
- log.warn(message);
585
- },
607
+ log.warn(message);
608
+ },
586
609
  error: (message) => {
587
- log.message(message, { symbol: color.red(S_ERROR) });
588
- }
610
+ log.message(message, {
611
+ symbol: color.red(S_ERROR),
612
+ });
613
+ },
589
614
  };
590
- const frames = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"];
615
+ const frames = unicode ? [
616
+ '\u25D2',
617
+ '\u25D0',
618
+ '\u25D3',
619
+ '\u25D1',
620
+ ] : [
621
+ '\u2022',
622
+ 'o',
623
+ 'O',
624
+ '0',
625
+ ];
626
+
591
627
  export const spinner = () => {
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)}
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)}
623
658
  ${color.green(S_STEP_SUBMIT)} ${message}
624
- `
625
- );
626
- unblock();
627
- }
628
- };
659
+ `);
660
+ unblock();
661
+ },
662
+ };
629
663
  };
630
664
  function ansiRegex() {
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");
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');
636
671
  }
672
+
637
673
  export const group = async (prompts, opts) => {
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;
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;
649
694
  }
650
- results[name] = result;
651
- }
652
- return results;
695
+
696
+ return results;
653
697
  };