@reliverse/relinka 1.1.10 → 1.2.1

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 (224) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +38 -42
  3. package/dist-npm/components/core/core.d.ts +2 -0
  4. package/dist-npm/components/core/core.js +2 -0
  5. package/dist-npm/{utils/constants.d.ts → components/levels/levels.d.ts} +1 -1
  6. package/dist-npm/components/{prompts/create.d.ts → modes/basic.d.ts} +3 -3
  7. package/dist-npm/components/{instance → modes}/basic.js +4 -4
  8. package/dist-npm/components/{instance → modes}/browser.d.ts +2 -2
  9. package/dist-npm/components/modes/browser.js +12 -0
  10. package/dist-npm/components/modes/shared.d.ts +5 -0
  11. package/dist-npm/components/modes/shared.js +2 -0
  12. package/dist-npm/components/{prompts → relinka}/relinka.d.ts +2 -4
  13. package/dist-npm/components/{prompts → relinka}/relinka.js +1 -7
  14. package/dist-npm/components/{instance/reporter → reporters}/basic.d.ts +1 -1
  15. package/dist-npm/components/{instance/reporter → reporters}/basic.js +2 -2
  16. package/dist-npm/components/{instance/reporter → reporters}/browser.d.ts +1 -1
  17. package/dist-npm/components/{instance/reporter → reporters}/fancy.d.ts +3 -3
  18. package/dist-npm/components/{instance/reporter → reporters}/fancy.js +5 -7
  19. package/dist-npm/main.d.ts +8 -1
  20. package/dist-npm/main.js +34 -1
  21. package/dist-npm/types/mod.d.ts +42 -0
  22. package/dist-npm/utils/color.js +4 -1
  23. package/dist-npm/utils/mod.d.ts +3 -0
  24. package/dist-npm/utils/mod.js +9 -0
  25. package/package.json +3 -2
  26. package/dist-npm/components/anykey/index.d.ts +0 -7
  27. package/dist-npm/components/anykey/index.js +0 -61
  28. package/dist-npm/components/block/block.d.ts +0 -10
  29. package/dist-npm/components/block/block.js +0 -52
  30. package/dist-npm/components/checkbox/index.d.ts +0 -3
  31. package/dist-npm/components/checkbox/index.js +0 -217
  32. package/dist-npm/components/confirm/confirm-main.d.ts +0 -3
  33. package/dist-npm/components/confirm/confirm-main.js +0 -98
  34. package/dist-npm/components/confirm/confirm-three.d.ts +0 -13
  35. package/dist-npm/components/confirm/confirm-three.js +0 -26
  36. package/dist-npm/components/confirm/index.d.ts +0 -2
  37. package/dist-npm/components/confirm/index.js +0 -41
  38. package/dist-npm/components/core/Separator.d.ts +0 -6
  39. package/dist-npm/components/core/Separator.js +0 -18
  40. package/dist-npm/components/core/create-prompt.d.ts +0 -4
  41. package/dist-npm/components/core/create-prompt.js +0 -107
  42. package/dist-npm/components/core/errors.d.ts +0 -20
  43. package/dist-npm/components/core/errors.js +0 -21
  44. package/dist-npm/components/core/hook-engine.d.ts +0 -23
  45. package/dist-npm/components/core/hook-engine.js +0 -109
  46. package/dist-npm/components/core/index.d.ts +0 -13
  47. package/dist-npm/components/core/index.js +0 -12
  48. package/dist-npm/components/core/key.d.ts +0 -10
  49. package/dist-npm/components/core/key.js +0 -16
  50. package/dist-npm/components/core/lines.d.ts +0 -14
  51. package/dist-npm/components/core/lines.js +0 -52
  52. package/dist-npm/components/core/make-theme.d.ts +0 -3
  53. package/dist-npm/components/core/make-theme.js +0 -28
  54. package/dist-npm/components/core/position.d.ts +0 -12
  55. package/dist-npm/components/core/position.js +0 -29
  56. package/dist-npm/components/core/promise-polyfill.d.ts +0 -7
  57. package/dist-npm/components/core/promise-polyfill.js +0 -13
  58. package/dist-npm/components/core/screen-manager.d.ts +0 -14
  59. package/dist-npm/components/core/screen-manager.js +0 -67
  60. package/dist-npm/components/core/theme.d.ts +0 -21
  61. package/dist-npm/components/core/theme.js +0 -24
  62. package/dist-npm/components/core/use-effect.d.ts +0 -2
  63. package/dist-npm/components/core/use-effect.js +0 -11
  64. package/dist-npm/components/core/use-keypress.d.ts +0 -3
  65. package/dist-npm/components/core/use-keypress.js +0 -21
  66. package/dist-npm/components/core/use-memo.d.ts +0 -1
  67. package/dist-npm/components/core/use-memo.js +0 -12
  68. package/dist-npm/components/core/use-pagination.d.ts +0 -11
  69. package/dist-npm/components/core/use-pagination.js +0 -34
  70. package/dist-npm/components/core/use-prefix.d.ts +0 -5
  71. package/dist-npm/components/core/use-prefix.js +0 -42
  72. package/dist-npm/components/core/use-ref.d.ts +0 -6
  73. package/dist-npm/components/core/use-ref.js +0 -4
  74. package/dist-npm/components/core/use-state.d.ts +0 -4
  75. package/dist-npm/components/core/use-state.js +0 -17
  76. package/dist-npm/components/core/useKeyPress.d.ts +0 -4
  77. package/dist-npm/components/core/useKeyPress.js +0 -16
  78. package/dist-npm/components/core/usePromptState.d.ts +0 -6
  79. package/dist-npm/components/core/usePromptState.js +0 -10
  80. package/dist-npm/components/core/utils.d.ts +0 -2
  81. package/dist-npm/components/core/utils.js +0 -11
  82. package/dist-npm/components/date/date.d.ts +0 -6
  83. package/dist-npm/components/date/date.js +0 -210
  84. package/dist-npm/components/editor/index.d.ts +0 -2
  85. package/dist-npm/components/editor/index.js +0 -78
  86. package/dist-npm/components/expand/index.d.ts +0 -3
  87. package/dist-npm/components/expand/index.js +0 -119
  88. package/dist-npm/components/figures/index.d.ts +0 -465
  89. package/dist-npm/components/figures/index.js +0 -299
  90. package/dist-npm/components/input/index.d.ts +0 -2
  91. package/dist-npm/components/input/index.js +0 -66
  92. package/dist-npm/components/input/text-main.d.ts +0 -3
  93. package/dist-npm/components/input/text-main.js +0 -103
  94. package/dist-npm/components/input/text.d.ts +0 -11
  95. package/dist-npm/components/input/text.js +0 -26
  96. package/dist-npm/components/instance/basic.d.ts +0 -8
  97. package/dist-npm/components/instance/browser.js +0 -18
  98. package/dist-npm/components/instance/shared.d.ts +0 -6
  99. package/dist-npm/components/instance/shared.js +0 -2
  100. package/dist-npm/components/mono/mono.d.ts +0 -5
  101. package/dist-npm/components/mono/mono.js +0 -64
  102. package/dist-npm/components/mono/monoTwo.d.ts +0 -30
  103. package/dist-npm/components/mono/monoTwo.js +0 -37
  104. package/dist-npm/components/multiselect/group-multiselect.d.ts +0 -23
  105. package/dist-npm/components/multiselect/group-multiselect.js +0 -58
  106. package/dist-npm/components/multiselect/multi-select-two.d.ts +0 -3
  107. package/dist-npm/components/multiselect/multi-select-two.js +0 -111
  108. package/dist-npm/components/multiselect/multi-select.d.ts +0 -21
  109. package/dist-npm/components/multiselect/multi-select.js +0 -45
  110. package/dist-npm/components/multiselect/multiselect-main.d.ts +0 -18
  111. package/dist-npm/components/multiselect/multiselect-main.js +0 -166
  112. package/dist-npm/components/multiselect/num-multi-select.d.ts +0 -3
  113. package/dist-npm/components/multiselect/num-multi-select.js +0 -111
  114. package/dist-npm/components/multiselect/num-multiselect-main.d.ts +0 -6
  115. package/dist-npm/components/multiselect/num-multiselect-main.js +0 -28
  116. package/dist-npm/components/next-steps/next-steps.d.ts +0 -2
  117. package/dist-npm/components/next-steps/next-steps.js +0 -24
  118. package/dist-npm/components/number/index.d.ts +0 -2
  119. package/dist-npm/components/number/index.js +0 -100
  120. package/dist-npm/components/number/number-main.d.ts +0 -3
  121. package/dist-npm/components/number/number-main.js +0 -95
  122. package/dist-npm/components/password/index.d.ts +0 -2
  123. package/dist-npm/components/password/index.js +0 -59
  124. package/dist-npm/components/password/password-main.d.ts +0 -3
  125. package/dist-npm/components/password/password-main.js +0 -119
  126. package/dist-npm/components/password/password-three.d.ts +0 -13
  127. package/dist-npm/components/password/password-three.js +0 -28
  128. package/dist-npm/components/progressbar/ProgressBar.d.ts +0 -22
  129. package/dist-npm/components/progressbar/ProgressBar.js +0 -53
  130. package/dist-npm/components/progressbar/helper.d.ts +0 -6
  131. package/dist-npm/components/progressbar/helper.js +0 -38
  132. package/dist-npm/components/progressbar/index.d.ts +0 -2
  133. package/dist-npm/components/progressbar/index.js +0 -1
  134. package/dist-npm/components/prompts/create.js +0 -35
  135. package/dist-npm/components/prompts/index.d.ts +0 -49
  136. package/dist-npm/components/prompts/index.js +0 -46
  137. package/dist-npm/components/prompts/prompt.d.ts +0 -36
  138. package/dist-npm/components/prompts/prompt.js +0 -232
  139. package/dist-npm/components/prompts/promptTwo.d.ts +0 -92
  140. package/dist-npm/components/prompts/promptTwo.js +0 -653
  141. package/dist-npm/components/range/range.d.ts +0 -62
  142. package/dist-npm/components/range/range.js +0 -270
  143. package/dist-npm/components/rawlist/index.d.ts +0 -3
  144. package/dist-npm/components/rawlist/index.js +0 -104
  145. package/dist-npm/components/results/results.d.ts +0 -10
  146. package/dist-npm/components/results/results.js +0 -34
  147. package/dist-npm/components/search/index.d.ts +0 -3
  148. package/dist-npm/components/search/index.js +0 -186
  149. package/dist-npm/components/select/index.d.ts +0 -3
  150. package/dist-npm/components/select/index.js +0 -176
  151. package/dist-npm/components/select/num-select-main.d.ts +0 -8
  152. package/dist-npm/components/select/num-select-main.js +0 -30
  153. package/dist-npm/components/select/num-select.d.ts +0 -5
  154. package/dist-npm/components/select/num-select.js +0 -125
  155. package/dist-npm/components/select/select-key.d.ts +0 -15
  156. package/dist-npm/components/select/select-key.js +0 -26
  157. package/dist-npm/components/select/select-main.d.ts +0 -19
  158. package/dist-npm/components/select/select-main.js +0 -151
  159. package/dist-npm/components/select/select-three.d.ts +0 -18
  160. package/dist-npm/components/select/select-three.js +0 -35
  161. package/dist-npm/components/select/select-two.d.ts +0 -2
  162. package/dist-npm/components/select/select-two.js +0 -98
  163. package/dist-npm/components/spinner/index.d.ts +0 -15
  164. package/dist-npm/components/spinner/index.js +0 -110
  165. package/dist-npm/components/st-end/end.d.ts +0 -2
  166. package/dist-npm/components/st-end/end.js +0 -35
  167. package/dist-npm/components/st-end/start.d.ts +0 -2
  168. package/dist-npm/components/st-end/start.js +0 -32
  169. package/dist-npm/components/toggle/index.d.ts +0 -13
  170. package/dist-npm/components/toggle/index.js +0 -121
  171. package/dist-npm/components/visual/animate/animate.d.ts +0 -13
  172. package/dist-npm/components/visual/animate/animate.js +0 -55
  173. package/dist-npm/components/visual/ascii-art/ascii-art.d.ts +0 -6
  174. package/dist-npm/components/visual/ascii-art/ascii-art.js +0 -12
  175. package/dist-npm/testing/index.d.ts +0 -18
  176. package/dist-npm/testing/index.js +0 -64
  177. package/dist-npm/types/general.d.ts +0 -134
  178. package/dist-npm/types/index.d.ts +0 -2
  179. package/dist-npm/types/index.js +0 -2
  180. package/dist-npm/types/keypress.d.ts +0 -52
  181. package/dist-npm/types/keypress.js +0 -37
  182. package/dist-npm/types/readline.d.ts +0 -30
  183. package/dist-npm/types/readline.js +0 -0
  184. package/dist-npm/types/relinka.d.ts +0 -30
  185. package/dist-npm/types/relinka.js +0 -0
  186. package/dist-npm/types/utils.d.ts +0 -17
  187. package/dist-npm/types/utils.js +0 -0
  188. package/dist-npm/utils/colorize.d.ts +0 -2
  189. package/dist-npm/utils/colorize.js +0 -130
  190. package/dist-npm/utils/component.d.ts +0 -101
  191. package/dist-npm/utils/component.js +0 -630
  192. package/dist-npm/utils/core.d.ts +0 -2
  193. package/dist-npm/utils/core.js +0 -2
  194. package/dist-npm/utils/decoder.d.ts +0 -14
  195. package/dist-npm/utils/decoder.js +0 -281
  196. package/dist-npm/utils/errors.d.ts +0 -1
  197. package/dist-npm/utils/errors.js +0 -15
  198. package/dist-npm/utils/keypress.d.ts +0 -7
  199. package/dist-npm/utils/keypress.js +0 -327
  200. package/dist-npm/utils/mapping.d.ts +0 -4
  201. package/dist-npm/utils/mapping.js +0 -49
  202. package/dist-npm/utils/messages.d.ts +0 -17
  203. package/dist-npm/utils/messages.js +0 -213
  204. package/dist-npm/utils/platforms.d.ts +0 -1
  205. package/dist-npm/utils/platforms.js +0 -22
  206. package/dist-npm/utils/prompt-tmp.d.ts +0 -13
  207. package/dist-npm/utils/prompt-tmp.js +0 -254
  208. package/dist-npm/utils/prompt-two.d.ts +0 -13
  209. package/dist-npm/utils/prompt-two.js +0 -254
  210. package/dist-npm/utils/readline.d.ts +0 -2
  211. package/dist-npm/utils/readline.js +0 -9
  212. package/dist-npm/utils/skeleton.d.ts +0 -7
  213. package/dist-npm/utils/skeleton.js +0 -145
  214. package/dist-npm/utils/terminal.d.ts +0 -5
  215. package/dist-npm/utils/terminal.js +0 -33
  216. package/dist-npm/utils/types.d.ts +0 -0
  217. package/dist-npm/utils/types.js +0 -0
  218. package/dist-npm/utils/utils.d.ts +0 -3
  219. package/dist-npm/utils/utils.js +0 -9
  220. package/dist-npm/utils/variants.d.ts +0 -9
  221. package/dist-npm/utils/variants.js +0 -49
  222. /package/dist-npm/{utils/constants.js → components/levels/levels.js} +0 -0
  223. /package/dist-npm/components/{instance/reporter → reporters}/browser.js +0 -0
  224. /package/dist-npm/types/{general.js → mod.js} +0 -0
@@ -1,653 +0,0 @@
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";
14
- const unicode = isUnicodeSupported();
15
- 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");
37
- 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);
45
- }
46
- case "error": {
47
- return color.yellow(S_STEP_ERROR);
48
- }
49
- case "submit": {
50
- return color.green(S_STEP_SUBMIT);
51
- }
52
- }
53
- };
54
- 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)}
62
- ${symbol(this.state)} ${opts.message}
63
- `;
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
- )}
75
- `;
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
- )}
92
- `;
93
- }
94
- }
95
- }
96
- }).prompt();
97
- };
98
- 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)}
104
- ${symbol(this.state)} ${opts.message}
105
- `;
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
- )}
117
- `;
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
- )}
132
- `;
133
- }
134
- }
135
- }
136
- }).prompt();
137
- };
138
- 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)}
147
- ${symbol(this.state)} ${opts.message}
148
- `;
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
- )}
158
- ${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}`}
162
- ${color.cyan(S_BAR_END)}
163
- `;
164
- }
165
- }
166
- }
167
- }).prompt();
168
- };
169
- 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)}
190
- ${symbol(this.state)} ${opts.message}
191
- `;
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
- )}
212
- ${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(`
218
- ${color.cyan(S_BAR)} `)}
219
- ${color.cyan(S_BAR_END)}
220
- `;
221
- }
222
- }
223
- }
224
- }).prompt();
225
- };
226
- 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)}
249
- ${symbol(this.state)} ${opts.message}
250
- `;
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
- )}
273
- ${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(`
279
- ${color.cyan(S_BAR)} `)}
280
- ${color.cyan(S_BAR_END)}
281
- `;
282
- }
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)}
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)}` : ""}`;
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");
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");
364
- }
365
- if (selected) {
366
- return opt(option, "selected");
367
- }
368
- return opt(option, active ? "active" : "inactive");
369
- }).join(`
370
- ${color.cyan(S_BAR)} `)}
371
- ${color.cyan(S_BAR_END)}
372
- `;
373
- }
374
- }
375
- }
376
- }).prompt();
377
- };
378
- 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(", "))}`;
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);
467
- }
468
- if (selected) {
469
- return opt(option, "selected", options);
470
- }
471
- return opt(option, active ? "active" : "inactive", options);
472
- }).join(`
473
- ${color.yellow(S_BAR)} `)}
474
- ${footer}
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);
491
- }
492
- if (selected) {
493
- return opt(option, "selected", options);
494
- }
495
- return opt(option, active ? "active" : "inactive", options);
496
- }).join(`
497
- ${color.cyan(S_BAR)} `)}
498
- ${color.cyan(S_BAR_END)}
499
- `;
500
- }
501
- }
502
- }
503
- }).prompt();
504
- };
505
- const strip = (str) => str.replace(ansiRegex(), "");
506
- export const note = (message = "", title = "") => {
507
- const lines = `
508
- ${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
- )}
529
- ${msg}
530
- ${color.gray(
531
- S_CONNECT_LEFT + S_BAR_H.repeat(len + 2) + S_CORNER_BOTTOM_RIGHT
532
- )}
533
- `
534
- );
535
- };
536
- export const cancel = (message = "") => {
537
- process.stdout.write(`${color.gray(S_BAR_END)} ${color.red(message)}
538
-
539
- `);
540
- };
541
- export const intro = (title = "") => {
542
- process.stdout.write(`${color.gray(S_BAR_START)} ${title}
543
- `);
544
- };
545
- export const outro = (message = "") => {
546
- process.stdout.write(
547
- `${color.gray(S_BAR)}
548
- ${color.gray(S_BAR_END)} ${message}
549
-
550
- `
551
- );
552
- };
553
- export const log = {
554
- /**
555
- * Logs an message, prefixed with a gray bar.
556
- * @param {string} message - The message to log.
557
- * @param {LogMessageOptions} [opts] - Optional settings for the log message. See {@link LogMessageOptions}.
558
- */
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")}
569
- `);
570
- },
571
- info: (message) => {
572
- log.message(message, { symbol: color.blue(S_INFO) });
573
- },
574
- success: (message) => {
575
- log.message(message, { symbol: color.green(S_SUCCESS) });
576
- },
577
- step: (message) => {
578
- log.message(message, { symbol: color.green(S_STEP_SUBMIT) });
579
- },
580
- warn: (message) => {
581
- log.message(message, { symbol: color.yellow(S_WARN) });
582
- },
583
- warning: (message) => {
584
- log.warn(message);
585
- },
586
- error: (message) => {
587
- log.message(message, { symbol: color.red(S_ERROR) });
588
- }
589
- };
590
- const frames = unicode ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"];
591
- 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)}
623
- ${color.green(S_STEP_SUBMIT)} ${message}
624
- `
625
- );
626
- unblock();
627
- }
628
- };
629
- };
630
- 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");
636
- }
637
- 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;
649
- }
650
- results[name] = result;
651
- }
652
- return results;
653
- };
@@ -1,62 +0,0 @@
1
- import type { Writable } from "stream";
2
- import { EventEmitter } from "events";
3
- type RangePromptOptions = {
4
- hint?: string;
5
- marker?: string;
6
- bar?: string;
7
- values?: any[];
8
- value?: number | null;
9
- unit?: string;
10
- typed?: string;
11
- lastHit?: number;
12
- min?: number;
13
- max?: number;
14
- step?: number;
15
- size?: number;
16
- };
17
- export declare class RangePrompt extends EventEmitter {
18
- hint: string;
19
- marker: string;
20
- bar: string;
21
- values: any[];
22
- value: number | null;
23
- unit: string;
24
- typed: string;
25
- lastHit: number;
26
- min: number;
27
- max: number;
28
- step: number;
29
- size: number;
30
- done: boolean;
31
- aborted: boolean;
32
- msg: string;
33
- initialValue: number | null;
34
- out: Writable;
35
- close: () => void;
36
- pause: () => void;
37
- resume: () => void;
38
- _: (input: string) => void;
39
- private stdin;
40
- private keyListener;
41
- private cursorHidden;
42
- constructor(msg: string, options?: RangePromptOptions);
43
- private initialize;
44
- private _close;
45
- private onKeyPress;
46
- reset(): void;
47
- abort(): void;
48
- submit(): void;
49
- up(): void;
50
- down(): void;
51
- handleNumericInput(n: string): void;
52
- handleUnknownInput(input: string): void;
53
- render(first?: boolean): void;
54
- bell(): void;
55
- left: () => void;
56
- right: () => void;
57
- }
58
- export declare const rangePrompt: (msg: string, opt?: RangePromptOptions) => any;
59
- declare const _default: ((msg: string, opt?: RangePromptOptions) => any) & {
60
- RangePrompt: typeof RangePrompt;
61
- };
62
- export default _default;