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