@reliverse/relinka 1.2.0 → 1.2.2

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 +9 -8
  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,270 +0,0 @@
1
- import Differ from "ansi-diff-stream";
2
- import esc from "ansi-escapes";
3
- import chalk from "chalk";
4
- import ui from "cli-styles";
5
- import { EventEmitter } from "events";
6
- import precision from "precision";
7
- import stringWidth from "string-width";
8
- import windowSize from "window-size";
9
- import wrap from "../../utils/skeleton.js";
10
- export class RangePrompt extends EventEmitter {
11
-
12
- hint;
13
- marker;
14
- bar;
15
- values;
16
- value;
17
- unit;
18
- typed;
19
- lastHit;
20
- min;
21
- max;
22
- step;
23
- size;
24
- done;
25
- aborted;
26
- msg;
27
- initialValue;
28
- out;
29
- close;
30
- pause;
31
- resume;
32
- _;
33
-
34
-
35
- stdin;
36
- keyListener;
37
- cursorHidden;
38
- constructor(msg, options = {}) {
39
- super();
40
- const defaults = {
41
- hint: "\u2013\xA0Use arrow keys or type a value.",
42
- marker: chalk.cyan.bold("\u25CF"),
43
- bar: "\u2013",
44
- values: [],
45
- value: null,
46
- unit: "",
47
- typed: "",
48
- lastHit: 0,
49
- min: 0,
50
- max: 100,
51
- step: 1,
52
- size: windowSize.width
53
- };
54
- const opts = { ...defaults, ...options };
55
- this.hint = opts.hint;
56
- this.marker = opts.marker;
57
- this.bar = opts.bar;
58
- this.values = opts.values;
59
- this.value = opts.value;
60
- this.unit = opts.unit;
61
- this.typed = opts.typed;
62
- this.lastHit = opts.lastHit;
63
- this.min = opts.min;
64
- this.max = opts.max;
65
- this.step = opts.step;
66
- this.size = opts.size;
67
- this.done = false;
68
- this.aborted = false;
69
- this.msg = msg;
70
- this.initialValue = this.value;
71
- this.out = process.stdout;
72
- this.stdin = process.stdin;
73
- this.keyListener = this.onKeyPress.bind(this);
74
- this.cursorHidden = false;
75
- this.close = this._close.bind(this);
76
- this.reset = this.reset.bind(this);
77
- this.abort = this.abort.bind(this);
78
- this.submit = this.submit.bind(this);
79
- this.up = this.up.bind(this);
80
- this.down = this.down.bind(this);
81
- this.handleNumericInput = this.handleNumericInput.bind(this);
82
- this.handleUnknownInput = this.handleUnknownInput.bind(this);
83
- this.render = this.render.bind(this);
84
- this.left = this.down.bind(this);
85
- this.right = this.up.bind(this);
86
- this._ = this.handleUnknownInput;
87
- this.initialize();
88
- }
89
- /**
90
- * Initializes the prompt by setting up listeners and terminal settings
91
- */
92
- initialize() {
93
- this.out.write(esc.cursorHide);
94
- this.cursorHidden = true;
95
- if (this.stdin.isTTY) {
96
- this.stdin.setRawMode(true);
97
- this.stdin.resume();
98
- }
99
- this.stdin.on("data", this.keyListener);
100
- this.render(true);
101
- }
102
- _close() {
103
- this.stdin.removeListener("data", this.keyListener);
104
- if (this.stdin.isTTY) {
105
- this.stdin.setRawMode(false);
106
- this.stdin.pause();
107
- }
108
- if (this.cursorHidden) {
109
- this.out.write(esc.cursorShow);
110
- this.cursorHidden = false;
111
- }
112
- if (this.out instanceof Differ) {
113
- this.out.end();
114
- }
115
- this.emit("close");
116
- }
117
- onKeyPress(chunk) {
118
- const key = chunk.toString();
119
- if (key === "") {
120
- this.abort();
121
- return;
122
- } else if (key === "\r" || key === "\n") {
123
- this.submit();
124
- return;
125
- } else if (key === "\x1B[A" || key === "\x1B[B") {
126
- if (key === "\x1B[A") {
127
- this.up();
128
- } else {
129
- this.down();
130
- }
131
- return;
132
- }
133
- if (isFloat.test(key)) {
134
- this.handleNumericInput(key);
135
- } else {
136
- this.handleUnknownInput(key);
137
- }
138
- }
139
- reset() {
140
- this.typed = "";
141
- this.value = this.initialValue;
142
- this.emit("change");
143
- this.render();
144
- }
145
- abort() {
146
- this.done = true;
147
- this.aborted = true;
148
- this.emit("abort");
149
- this.render();
150
- this.out.write("\n");
151
- this.close();
152
- }
153
- submit() {
154
- this.done = true;
155
- this.aborted = false;
156
- this.emit("submit");
157
- this.render();
158
- this.out.write("\n");
159
- this.close();
160
- }
161
- up() {
162
- this.typed = "";
163
- if (this.value !== null && this.value >= this.max) {
164
- this.bell();
165
- return;
166
- }
167
- if (this.value !== null) {
168
- this.value = +(this.value + this.step).toFixed(precision(this.step));
169
- if (this.value > this.max) {
170
- this.value = this.max;
171
- }
172
- }
173
- this.emit("change");
174
- this.render();
175
- }
176
- down() {
177
- this.typed = "";
178
- if (this.value !== null && this.value <= this.min) {
179
- this.bell();
180
- return;
181
- }
182
- if (this.value !== null) {
183
- this.value = +(this.value - this.step).toFixed(precision(this.step));
184
- if (this.value < this.min) {
185
- this.value = this.min;
186
- }
187
- }
188
- this.emit("change");
189
- this.render();
190
- }
191
- handleNumericInput(n) {
192
- if (!isFloat.test(n)) {
193
- this.bell();
194
- return;
195
- }
196
- const now = Date.now();
197
- if (now - this.lastHit > 1e3) {
198
- this.typed = "";
199
- }
200
- this.typed += n;
201
- this.lastHit = now;
202
- const v = parseFloat(this.typed);
203
- if (isNaN(v)) {
204
- this.bell();
205
- return;
206
- }
207
- let newValue = v;
208
- if (newValue > this.max) {
209
- newValue = this.max;
210
- }
211
- if (newValue < this.min) {
212
- newValue = this.min;
213
- }
214
- this.value = newValue;
215
- this.emit("change");
216
- this.render();
217
- }
218
- handleUnknownInput(input) {
219
- this.bell();
220
- }
221
- render(first = false) {
222
- let out = "";
223
- if (first) {
224
- out += esc.cursorHide;
225
- } else {
226
- out += esc.eraseLines(2) + esc.cursorTo(0);
227
- }
228
- out += [
229
- ui.symbol(this.done, this.aborted),
230
- chalk.bold(this.msg),
231
- ui.delimiter(this.done),
232
- this.value !== null ? this.value : "",
233
- chalk.gray(this.unit)
234
- ].join(" ") + "\n";
235
- const size = this.size - stringWidth(String(this.min)) - stringWidth(String(this.max)) - 6;
236
- const barWidth = stringWidth(this.bar);
237
- const left = Math.round(
238
- (size - barWidth) * (this.value !== null ? this.value : 0) / (this.max - this.min)
239
- );
240
- const right = size - left - barWidth;
241
- const leftBar = this.bar.repeat(Math.max(0, Math.floor(left / barWidth)));
242
- const rightBar = this.bar.repeat(Math.max(0, Math.floor(right / barWidth)));
243
- out += [
244
- "",
245
- this.min,
246
- chalk.gray(leftBar) + this.marker + chalk.gray(rightBar),
247
- this.max,
248
- ""
249
- ].join(" ") + "\n";
250
- this.out.write(out);
251
- }
252
- bell() {
253
- this.out.write("\x07");
254
- }
255
-
256
- left;
257
- right;
258
- }
259
- const isFloat = /^[0-9.]+$/;
260
- export const rangePrompt = (msg, opt) => {
261
- if (typeof msg !== "string") {
262
- throw new Error("Message must be string.");
263
- }
264
- if (Array.isArray(opt) || typeof opt !== "object") {
265
- opt = {};
266
- }
267
- const prompt = new RangePrompt(msg, opt);
268
- return wrap(prompt);
269
- };
270
- export default Object.assign(rangePrompt, { RangePrompt });
@@ -1,3 +0,0 @@
1
- declare const rawlist: any;
2
- export default rawlist;
3
- export { Separator } from "../../components/core/index.js";
@@ -1,104 +0,0 @@
1
- import colors from "picocolors";
2
- import {
3
- createPrompt,
4
- useMemo,
5
- useState,
6
- useKeypress,
7
- usePrefix,
8
- isEnterKey,
9
- Separator,
10
- makeTheme
11
- } from "../../components/core/index.js";
12
- const numberRegex = /\d+/;
13
- function isSelectableChoice(choice) {
14
- return choice != null && !Separator.isSeparator(choice);
15
- }
16
- function normalizeChoices(choices) {
17
- let index = 0;
18
- return choices.map((choice) => {
19
- if (Separator.isSeparator(choice)) {
20
- return choice;
21
- }
22
- index += 1;
23
- if (typeof choice === "string") {
24
- return {
25
- value: choice,
26
- name: choice,
27
- short: choice,
28
- key: String(index)
29
- };
30
- }
31
- const name = choice.name ?? String(choice.value);
32
- return {
33
-
34
- value: choice.value,
35
- name,
36
-
37
- short: choice.short ?? name,
38
-
39
- key: choice.key ?? String(index)
40
- };
41
- });
42
- }
43
- const rawlist = createPrompt(
44
- (config, done) => {
45
- const choices = useMemo(
46
- () => normalizeChoices(config.choices),
47
- [config.choices]
48
- );
49
- const [status, setStatus] = useState("idle");
50
- const [value, setValue] = useState("");
51
- const [errorMsg, setError] = useState();
52
- const theme = makeTheme(config.theme);
53
- const prefix = usePrefix({ status, theme });
54
- useKeypress((key, rl) => {
55
- if (isEnterKey(key)) {
56
- let selectedChoice;
57
- if (numberRegex.test(value)) {
58
- const answer = Number.parseInt(value, 10) - 1;
59
- selectedChoice = choices.filter(isSelectableChoice)[answer];
60
- } else {
61
- selectedChoice = choices.find(
62
- (choice) => isSelectableChoice(choice) && choice.key === value
63
- );
64
- }
65
- if (isSelectableChoice(selectedChoice)) {
66
- setValue(selectedChoice.short);
67
- setStatus("done");
68
- done(selectedChoice.value);
69
- } else if (value === "") {
70
- setError("Please input a value");
71
- } else {
72
- setError(`"${colors.red(value)}" isn't an available option`);
73
- }
74
- } else {
75
- setValue(rl.line);
76
- setError(void 0);
77
- }
78
- });
79
- const message = theme.style.message(config.message, status);
80
- if (status === "done") {
81
- return `${prefix} ${message} ${theme.style.answer(value)}`;
82
- }
83
- const choicesStr = choices.map((choice) => {
84
- if (Separator.isSeparator(choice)) {
85
- return ` ${choice.separator}`;
86
- }
87
- const line = ` ${choice.key}) ${choice.name}`;
88
- if (choice.key === value.toLowerCase()) {
89
- return theme.style.highlight(line);
90
- }
91
- return line;
92
- }).join("\n");
93
- let error = "";
94
- if (errorMsg) {
95
- error = theme.style.error(errorMsg);
96
- }
97
- return [
98
- `${prefix} ${message} ${value}`,
99
- [choicesStr, error].filter(Boolean).join("\n")
100
- ];
101
- }
102
- );
103
- export default rawlist;
104
- export { Separator } from "../../components/core/index.js";
@@ -1,10 +0,0 @@
1
- import type { Static } from "@sinclair/typebox";
2
- declare const ResultsSchema: import("@sinclair/typebox").TObject<{
3
- username: import("@sinclair/typebox").TString;
4
- }>;
5
- type ResultsType = Static<typeof ResultsSchema>;
6
- export declare function promptsDisplayResults({ results, inline, }: {
7
- results: ResultsType;
8
- inline?: boolean;
9
- }): Promise<void>;
10
- export {};
@@ -1,34 +0,0 @@
1
- import { Type } from "@sinclair/typebox";
2
- import { Value } from "@sinclair/typebox/value";
3
- import { msg } from "../../utils/messages.js";
4
- const ResultsSchema = Type.Object({
5
- username: Type.String()
6
- });
7
- export async function promptsDisplayResults({
8
- results,
9
- inline = true
10
- }) {
11
- if (!Value.Check(ResultsSchema, results)) {
12
- throw new Error("Invalid results structure.");
13
- }
14
- const title = "Your input results:";
15
- if (inline) {
16
- const formattedResults = Object.entries(results).map(([key, value]) => `${key}: ${value}`).join(", ");
17
- msg({
18
- type: "M_INFO",
19
- title,
20
- content: formattedResults,
21
- titleColor: "cyan",
22
- contentColor: "dim"
23
- });
24
- } else {
25
- const formattedResults = JSON.stringify(results, null, 2);
26
- msg({
27
- type: "M_INFO",
28
- title,
29
- content: formattedResults,
30
- titleColor: "cyan",
31
- contentColor: "dim"
32
- });
33
- }
34
- }
@@ -1,3 +0,0 @@
1
- declare const search: any;
2
- export default search;
3
- export { Separator } from "../../components/core/index.js";
@@ -1,186 +0,0 @@
1
- import colors from "picocolors";
2
- import {
3
- createPrompt,
4
- useState,
5
- useKeypress,
6
- usePrefix,
7
- usePagination,
8
- useRef,
9
- useEffect,
10
- useMemo,
11
- isEnterKey,
12
- Separator,
13
- makeTheme
14
- } from "../../components/core/index.js";
15
- import figures from "../../components/figures/index.js";
16
- const searchTheme = {
17
- icon: { cursor: figures.pointer },
18
- style: {
19
- disabled: (text) => colors.dim(`- ${text}`),
20
- searchTerm: (text) => colors.cyan(text),
21
- description: (text) => colors.cyan(text)
22
- },
23
- helpMode: "auto"
24
- };
25
- function isSelectable(item) {
26
- return !Separator.isSeparator(item) && !item.disabled;
27
- }
28
- function normalizeChoices(choices) {
29
- return choices.map((choice) => {
30
- if (Separator.isSeparator(choice)) {
31
- return choice;
32
- }
33
- if (typeof choice === "string") {
34
- return {
35
- value: choice,
36
- name: choice,
37
- short: choice,
38
- disabled: false
39
- };
40
- }
41
- const name = choice.name ?? String(choice.value);
42
- return {
43
-
44
- value: choice.value,
45
- name,
46
-
47
- description: choice.description,
48
-
49
- short: choice.short ?? name,
50
-
51
- disabled: choice.disabled ?? false
52
- };
53
- });
54
- }
55
- const search = createPrompt(
56
- (config, done) => {
57
- const { pageSize = 7, validate = () => true } = config;
58
- const theme = makeTheme(searchTheme, config.theme);
59
- const firstRender = useRef(true);
60
- const [status, setStatus] = useState("loading");
61
- const [searchTerm, setSearchTerm] = useState("");
62
- const [searchResults, setSearchResults] = useState(
63
- []
64
- );
65
- const [searchError, setSearchError] = useState();
66
- const prefix = usePrefix({ status, theme });
67
- const bounds = useMemo(() => {
68
- const first = searchResults.findIndex(isSelectable);
69
- const last = searchResults.findLastIndex(isSelectable);
70
- return { first, last };
71
- }, [searchResults]);
72
- const [active = bounds.first, setActive] = useState();
73
- useEffect(() => {
74
- const controller = new AbortController();
75
- setStatus("loading");
76
- setSearchError(void 0);
77
- const fetchResults = async () => {
78
- try {
79
- const results = await config.source(searchTerm || void 0, {
80
- signal: controller.signal
81
- });
82
- if (!controller.signal.aborted) {
83
- setActive(void 0);
84
- setSearchError(void 0);
85
- setSearchResults(normalizeChoices(results));
86
- setStatus("idle");
87
- }
88
- } catch (error2) {
89
- if (!controller.signal.aborted && error2 instanceof Error) {
90
- setSearchError(error2.message);
91
- }
92
- }
93
- };
94
- void fetchResults();
95
- return () => {
96
- controller.abort();
97
- };
98
- }, [searchTerm]);
99
- const selectedChoice = searchResults[active];
100
- useKeypress(async (key, rl) => {
101
- if (isEnterKey(key)) {
102
- if (selectedChoice) {
103
- setStatus("loading");
104
- const isValid = await validate(selectedChoice.value);
105
- setStatus("idle");
106
- if (isValid === true) {
107
- setStatus("done");
108
- done(selectedChoice.value);
109
- } else if (selectedChoice.name === searchTerm) {
110
- setSearchError(isValid || "You must provide a valid value");
111
- } else {
112
- rl.write(selectedChoice.name);
113
- setSearchTerm(selectedChoice.name);
114
- }
115
- } else {
116
- rl.write(searchTerm);
117
- }
118
- } else if (key.name === "tab" && selectedChoice) {
119
- rl.clearLine(0);
120
- rl.write(selectedChoice.name);
121
- setSearchTerm(selectedChoice.name);
122
- } else if (status !== "loading" && (key.name === "up" || key.name === "down")) {
123
- rl.clearLine(0);
124
- if (key.name === "up" && active !== bounds.first || key.name === "down" && active !== bounds.last) {
125
- const offset = key.name === "up" ? -1 : 1;
126
- let next = active;
127
- do {
128
- next = (next + offset + searchResults.length) % searchResults.length;
129
- } while (!isSelectable(searchResults[next]));
130
- setActive(next);
131
- }
132
- } else {
133
- setSearchTerm(rl.line);
134
- }
135
- });
136
- const message = theme.style.message(config.message, status);
137
- if (active > 0) {
138
- firstRender.current = false;
139
- }
140
- let helpTip = "";
141
- if (searchResults.length > 1 && (theme.helpMode === "always" || theme.helpMode === "auto" && firstRender.current)) {
142
- helpTip = searchResults.length > pageSize ? `
143
- ${theme.style.help("(Use arrow keys to reveal more choices)")}` : `
144
- ${theme.style.help("(Use arrow keys)")}`;
145
- }
146
- const page = usePagination({
147
- items: searchResults,
148
- active,
149
- renderItem({ item, isActive }) {
150
- if (Separator.isSeparator(item)) {
151
- return ` ${item.separator}`;
152
- }
153
- if (item.disabled) {
154
- const disabledLabel = typeof item.disabled === "string" ? item.disabled : "(disabled)";
155
- return theme.style.disabled(`${item.name} ${disabledLabel}`);
156
- }
157
- const color = isActive ? theme.style.highlight : (x) => x;
158
- const cursor = isActive ? theme.icon.cursor : ` `;
159
- return color(`${cursor} ${item.name}`);
160
- },
161
- pageSize,
162
- loop: false
163
- });
164
- let error;
165
- if (searchError) {
166
- error = theme.style.error(searchError);
167
- } else if (searchResults.length === 0 && searchTerm !== "" && status === "idle") {
168
- error = theme.style.error("No results found");
169
- }
170
- let searchStr;
171
- if (status === "done" && selectedChoice) {
172
- const answer = selectedChoice.short;
173
- return `${prefix} ${message} ${theme.style.answer(answer)}`;
174
- } else {
175
- searchStr = theme.style.searchTerm(searchTerm);
176
- }
177
- const choiceDescription = selectedChoice?.description ? `
178
- ${theme.style.description(selectedChoice.description)}` : ``;
179
- return [
180
- [prefix, message, searchStr].filter(Boolean).join(" "),
181
- `${error ?? page}${helpTip}${choiceDescription}`
182
- ];
183
- }
184
- );
185
- export default search;
186
- export { Separator } from "../../components/core/index.js";
@@ -1,3 +0,0 @@
1
- declare const select: any;
2
- export default select;
3
- export { Separator } from "../../components/core/index.js";