@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,254 +0,0 @@
1
- import { stdin, stdout } from "node:process";
2
- import readline from "node:readline";
3
- import { WriteStream } from "node:tty";
4
- import { cursor, erase } from "sisteransi";
5
- import wrap from "wrap-ansi";
6
- function diffLines(a, b) {
7
- if (a === b) {
8
- return;
9
- }
10
- const aLines = a.split("\n");
11
- const bLines = b.split("\n");
12
- const diff = [];
13
- for (let i = 0; i < Math.max(aLines.length, bLines.length); i++) {
14
- if (aLines[i] !== bLines[i]) {
15
- diff.push(i);
16
- }
17
- }
18
- return diff;
19
- }
20
- const cancel = Symbol("rp:cancel");
21
- export function isCancel(value) {
22
- return value === cancel;
23
- }
24
- function setRawMode(input, value) {
25
- if (input.isTTY) {
26
- input.setRawMode(value);
27
- }
28
- }
29
- const aliases = new Map([
30
- ["k", "up"],
31
- ["j", "down"],
32
- ["h", "left"],
33
- ["l", "right"]
34
- ]);
35
- const keys = new Set(["up", "down", "left", "right", "space", "enter"]);
36
- export function createPrompt({
37
- render: renderFn,
38
- input = stdin,
39
- output = stdout,
40
- ...opts
41
- }, trackValue = true) {
42
- const _input = input;
43
- const _output = output;
44
- let _rl;
45
- const _opts = opts;
46
- const _track = trackValue;
47
- let _cursor = 0;
48
- let state = "initial";
49
- let value = _opts.initialValue ?? "";
50
- let error = "";
51
- const subscribers = /* @__PURE__ */ new Map();
52
- let _prevFrame = "";
53
- const self = {};
54
- const _render = () => renderFn.call(self);
55
- function prompt() {
56
- const sink = new WriteStream(0);
57
- sink._write = (chunk, encoding, done) => {
58
- if (_track) {
59
- value = _rl.line.replace(/\t/g, "");
60
- _cursor = _rl.cursor;
61
- emit("value", value);
62
- }
63
- done();
64
- };
65
- _input.pipe(sink);
66
- _rl = readline.createInterface({
67
- input: _input,
68
- output: sink,
69
- tabSize: 2,
70
- prompt: "",
71
- escapeCodeTimeout: 50
72
- });
73
- readline.emitKeypressEvents(_input, _rl);
74
- _rl.prompt();
75
- if (_opts.initialValue !== void 0 && _track) {
76
- _rl.write(_opts.initialValue);
77
- }
78
- _input.on("keypress", onKeypress);
79
- setRawMode(_input, true);
80
- _output.on("resize", render);
81
- render();
82
- return new Promise((resolve) => {
83
- once("submit", () => {
84
- _output.write(cursor.show);
85
- _output.off("resize", render);
86
- setRawMode(_input, false);
87
- resolve(value);
88
- });
89
- once("cancel", () => {
90
- _output.write(cursor.show);
91
- _output.off("resize", render);
92
- setRawMode(_input, false);
93
- resolve(cancel);
94
- });
95
- });
96
- }
97
- function on(event, cb) {
98
- const arr = subscribers.get(event) ?? [];
99
- arr.push({ cb });
100
- subscribers.set(event, arr);
101
- }
102
- function once(event, cb) {
103
- const arr = subscribers.get(event) ?? [];
104
- arr.push({ cb, once: true });
105
- subscribers.set(event, arr);
106
- }
107
- function emit(event, ...data) {
108
- const cbs = subscribers.get(event) ?? [];
109
- const cleanup = [];
110
- for (const subscriber of cbs) {
111
- subscriber.cb(...data);
112
- if (subscriber.once) {
113
- cleanup.push(() => cbs.splice(cbs.indexOf(subscriber), 1));
114
- }
115
- }
116
- for (const cb of cleanup) {
117
- cb();
118
- }
119
- }
120
- function unsubscribe() {
121
- subscribers.clear();
122
- }
123
- function onKeypress(char, key) {
124
- if (state === "error") {
125
- state = "active";
126
- }
127
- if (key?.name && !_track && aliases.has(key.name)) {
128
- emit("cursor", aliases.get(key.name));
129
- }
130
- if (key?.name && keys.has(key.name)) {
131
- emit("cursor", key.name);
132
- }
133
- if (char && (char.toLowerCase() === "y" || char.toLowerCase() === "n")) {
134
- emit("confirm", char.toLowerCase() === "y");
135
- }
136
- if (char === " " && _opts.placeholder) {
137
- if (!value) {
138
- _rl.write(_opts.placeholder);
139
- emit("value", _opts.placeholder);
140
- }
141
- }
142
- if (char) {
143
- emit("key", char.toLowerCase());
144
- }
145
- if (key?.name === "return") {
146
- if (_opts.validate) {
147
- const problem = _opts.validate(value);
148
- if (problem) {
149
- error = problem;
150
- state = "error";
151
- _rl.write(value);
152
- }
153
- }
154
- if (state !== "error") {
155
- state = "submit";
156
- }
157
- }
158
- if (char === "") {
159
- state = "cancel";
160
- }
161
- if (state === "submit" || state === "cancel") {
162
- emit("finalize");
163
- }
164
- render();
165
- if (state === "submit" || state === "cancel") {
166
- close();
167
- }
168
- }
169
- function close() {
170
- _input.unpipe();
171
- _input.removeListener("keypress", onKeypress);
172
- _output.write("\n");
173
- setRawMode(_input, false);
174
- _rl.close();
175
- emit(state, value);
176
- unsubscribe();
177
- }
178
- function restoreCursor() {
179
- const lines = wrap(_prevFrame, process.stdout.columns, { hard: true }).split("\n").length - 1;
180
- _output.write(cursor.move(-999, lines * -1));
181
- }
182
- function render() {
183
- const frame = wrap(_render() || "", process.stdout.columns, {
184
- hard: true
185
- });
186
- if (frame === _prevFrame) {
187
- return;
188
- }
189
- if (state === "initial") {
190
- _output.write(cursor.hide);
191
- } else {
192
- const diff = diffLines(_prevFrame, frame);
193
- restoreCursor();
194
- if (diff && diff.length === 1) {
195
- const diffLine = diff[0];
196
- _output.write(cursor.move(0, diffLine));
197
- _output.write(erase.lines(1));
198
- const lines = frame.split("\n");
199
- _output.write(lines[diffLine]);
200
- _prevFrame = frame;
201
- _output.write(cursor.move(0, lines.length - diffLine - 1));
202
- return;
203
- } else if (diff && diff.length > 1) {
204
- const diffLine = diff[0];
205
- _output.write(cursor.move(0, diffLine));
206
- _output.write(erase.down());
207
- const lines = frame.split("\n");
208
- const newLines = lines.slice(diffLine);
209
- _output.write(newLines.join("\n"));
210
- _prevFrame = frame;
211
- return;
212
- }
213
- _output.write(erase.down());
214
- }
215
- _output.write(frame);
216
- if (state === "initial") {
217
- state = "active";
218
- }
219
- _prevFrame = frame;
220
- }
221
- Object.assign(self, {
222
- prompt,
223
- on,
224
- once,
225
- emit,
226
- close,
227
- render,
228
- get state() {
229
- return state;
230
- },
231
- set state(val) {
232
- state = val;
233
- },
234
- get value() {
235
- return value;
236
- },
237
- set value(val) {
238
- value = val;
239
- },
240
- get error() {
241
- return error;
242
- },
243
- set error(val) {
244
- error = val;
245
- },
246
- _cursor,
247
- _track,
248
- _input,
249
- _output,
250
- _rl,
251
- _opts
252
- });
253
- return self;
254
- }
@@ -1,2 +0,0 @@
1
- export declare function resetCursorAndClear(stream: NodeJS.WritableStream, x: number, y?: number, callback?: () => void): void;
2
- export declare function moveCursorAndClear(stream: NodeJS.WritableStream, dx: number, dy: number, callback?: () => void): void;
@@ -1,9 +0,0 @@
1
- import readline from "node:readline";
2
- export function resetCursorAndClear(stream, x, y, callback) {
3
- readline.cursorTo(stream, x, y, callback);
4
- readline.clearScreenDown(stream, callback);
5
- }
6
- export function moveCursorAndClear(stream, dx, dy, callback) {
7
- readline.moveCursor(stream, dx, dy, callback);
8
- readline.clearScreenDown(stream, callback);
9
- }
@@ -1,7 +0,0 @@
1
- import type { RangePrompt } from "../components/range/range.js";
2
- import type { Keypress } from "../types/keypress.js";
3
- export declare const action: (key: Keypress) => string | false;
4
- declare const _default: ((p: RangePrompt) => Promise<number | null>) & {
5
- action: (key: Keypress) => string | false;
6
- };
7
- export default _default;
@@ -1,145 +0,0 @@
1
- import differ from "ansi-diff-stream";
2
- import esc from "ansi-escapes";
3
- import windowSize from "window-size";
4
- import listenForKeys from "../utils/keypress.js";
5
- export const action = (key) => {
6
- const code = key.raw.charCodeAt(0);
7
- if (key.ctrl) {
8
- if (key.name === "a") {
9
- return "first";
10
- }
11
- if (key.name === "c") {
12
- return "abort";
13
- }
14
- if (key.name === "d") {
15
- return "abort";
16
- }
17
- if (key.name === "e") {
18
- return "last";
19
- }
20
- if (key.name === "g") {
21
- return "reset";
22
- }
23
- }
24
- if (key.name === "return") {
25
- return "submit";
26
- }
27
- if (key.name === "enter") {
28
- return "submit";
29
- }
30
- if (key.name === "backspace") {
31
- return "delete";
32
- }
33
- if (key.name === "abort") {
34
- return "abort";
35
- }
36
- if (key.name === "escape") {
37
- return "abort";
38
- }
39
- if (key.name === "tab") {
40
- return "next";
41
- }
42
- if (key.name === "up") {
43
- return "up";
44
- }
45
- if (key.name === "down") {
46
- return "down";
47
- }
48
- if (key.name === "right") {
49
- return "right";
50
- }
51
- if (key.name === "left") {
52
- return "left";
53
- }
54
- if (code === 8747) {
55
- return "left";
56
- }
57
- if (code === 402) {
58
- return "right";
59
- }
60
- return false;
61
- };
62
- const onResize = (stream, cb) => {
63
- stream.on("resize", cb);
64
- const stopListening = () => {
65
- stream.removeListener("resize", cb);
66
- };
67
- return stopListening;
68
- };
69
- const wrap = (p) => {
70
- const wrappedPrompt = p;
71
- wrappedPrompt.out = differ();
72
- wrappedPrompt.out.pipe(process.stdout);
73
- wrappedPrompt.bell = () => {
74
- process.stdout.write(esc.beep);
75
- };
76
- if (typeof wrappedPrompt._ !== "function") {
77
- wrappedPrompt._ = wrappedPrompt.bell;
78
- }
79
- const onKey = (key) => {
80
- const a = action(key);
81
- if (a === "abort") {
82
- return wrappedPrompt.close();
83
- }
84
- if (a === false) {
85
- return wrappedPrompt._(key.raw);
86
- }
87
- if (typeof wrappedPrompt[a] === "function") {
88
- wrappedPrompt[a](key);
89
- } else {
90
- wrappedPrompt.bell();
91
- }
92
- };
93
- const onNewSize = () => {
94
- const { width, height } = windowSize;
95
- wrappedPrompt.out.reset();
96
- wrappedPrompt.render(true);
97
- };
98
- let offKeypress = null;
99
- let offResize = null;
100
- const pause = () => {
101
- if (!offKeypress) {
102
- return;
103
- }
104
- offKeypress();
105
- offKeypress = null;
106
- if (offResize) {
107
- offResize();
108
- offResize = null;
109
- }
110
- process.stdout.write(esc.cursorShow);
111
- };
112
- const resume = () => {
113
- if (offKeypress) {
114
- return;
115
- }
116
- offKeypress = listenForKeys(process.stdin, onKey);
117
- offResize = onResize(process.stdout, onNewSize);
118
- process.stdout.write(esc.cursorHide);
119
- };
120
- wrappedPrompt.pause = pause;
121
- wrappedPrompt.resume = resume;
122
- return new Promise((resolve, reject) => {
123
- let isClosed = false;
124
- wrappedPrompt.close = () => {
125
- if (isClosed) {
126
- return;
127
- }
128
- isClosed = true;
129
- wrappedPrompt.out.unpipe(process.stdout);
130
- pause();
131
- if (wrappedPrompt.aborted) {
132
- reject(new Error("Prompt aborted"));
133
- } else {
134
- resolve(wrappedPrompt.value);
135
- }
136
- };
137
- process.on("beforeExit", () => wrappedPrompt.close());
138
- if (typeof wrappedPrompt.submit !== "function") {
139
- wrappedPrompt.submit = wrappedPrompt.close;
140
- }
141
- resume();
142
- wrappedPrompt.render(true);
143
- });
144
- };
145
- export default Object.assign(wrap, { action });
@@ -1,5 +0,0 @@
1
- export declare function removeCursor(): void;
2
- export declare function restoreCursor(): void;
3
- export declare function deleteLastLine(): void;
4
- export declare function deleteLastLines(count: number): void;
5
- export declare function countLines(text: string): number;
@@ -1,33 +0,0 @@
1
- import ansiEscapes from "ansi-escapes";
2
- import { cursor } from "sisteransi";
3
- import wrapAnsi from "wrap-ansi";
4
- import { msg } from "./messages.js";
5
- export function removeCursor() {
6
- process.stdout.write(cursor.hide);
7
- }
8
- export function restoreCursor() {
9
- process.stdout.write(cursor.show);
10
- }
11
- export function deleteLastLine() {
12
- process.stdout.write(ansiEscapes.cursorUp(1) + ansiEscapes.eraseLine);
13
- }
14
- export function deleteLastLines(count) {
15
- if (count <= 0) {
16
- msg({
17
- type: "M_ERROR",
18
- title: "Count is less than or equal to 0. Nothing to delete."
19
- });
20
- return;
21
- }
22
- process.stdout.write(ansiEscapes.eraseLines(count));
23
- }
24
- export function countLines(text) {
25
- const terminalWidth = process.stdout.columns || 80;
26
- const lines = text.split("\n");
27
- let lineCount = 0;
28
- for (const line of lines) {
29
- const wrapped = wrapAnsi(line, terminalWidth, { hard: true });
30
- lineCount += wrapped.split("\n").length;
31
- }
32
- return lineCount;
33
- }
File without changes
File without changes
@@ -1,3 +0,0 @@
1
- export * from "./box.js";
2
- export * from "./color.js";
3
- export { stripAnsi, centerAlign, rightAlign, leftAlign, align, } from "./string.js";
@@ -1,9 +0,0 @@
1
- export * from "./box.js";
2
- export * from "./color.js";
3
- export {
4
- stripAnsi,
5
- centerAlign,
6
- rightAlign,
7
- leftAlign,
8
- align
9
- } from "./string.js";
@@ -1,9 +0,0 @@
1
- import type { ColorName, Variant } from "../types/general.js";
2
- export declare const variantMap: {
3
- doubleBox: typeof createDoubleBox;
4
- };
5
- export declare function applyVariant(lines: string[] | string, variant?: Variant, options?: {
6
- limit?: number;
7
- }, borderColor?: ColorName): Promise<string>;
8
- declare function createDoubleBox(lines: string[], limit?: number, borderColor?: ColorName): string;
9
- export {};
@@ -1,49 +0,0 @@
1
- import { colorMap } from "./mapping.js";
2
- export const variantMap = {
3
-
4
- doubleBox: createDoubleBox
5
-
6
-
7
- };
8
- export async function applyVariant(lines, variant, options, borderColor) {
9
- const linesArray = Array.isArray(lines) ? lines : [lines];
10
- switch (variant) {
11
-
12
-
13
- case "doubleBox":
14
- return createDoubleBox(linesArray, options?.limit, borderColor);
15
-
16
-
17
-
18
-
19
- default:
20
- return linesArray.join("\n");
21
- }
22
- }
23
- function createDoubleBox(lines, limit, borderColor) {
24
- const processedLines = processLines(lines, limit);
25
- const maxLength = Math.max(...processedLines.map((line) => line.length));
26
- const indentation = "";
27
- if (borderColor === void 0) {
28
- borderColor = "viceGradient";
29
- }
30
- const topBorder = borderColor ? colorMap[borderColor](`${"\u2550".repeat(maxLength)}\u2557`) : `${"\u2550".repeat(maxLength)}\u2557`;
31
- const bottomBorder = borderColor ? colorMap[borderColor](`${indentation}\u255A${"\u2550".repeat(maxLength + 2)}\u255D`) : `${indentation}\u255A${"\u2550".repeat(maxLength + 2)}\u255D`;
32
- const middle = processedLines.map((line, index) => {
33
- const lineIndentation = index === 0 ? indentation : indentation + " ";
34
- return `${lineIndentation}${borderColor ? colorMap[borderColor]("\u2551") : "\u2551"} ${colorMap[borderColor](line.padEnd(maxLength))} ${borderColor ? colorMap[borderColor]("\u2551") : "\u2551"}`;
35
- }).join("\n");
36
- return `${topBorder}
37
- ${middle}
38
- ${bottomBorder}`;
39
- }
40
- function processLines(lines, limit) {
41
- const linesArray = Array.isArray(lines) ? lines : [lines];
42
- return linesArray.map((line) => {
43
- let truncatedLine = line;
44
- if (limit && line.length > limit) {
45
- truncatedLine = `${line.slice(0, limit - 3)}...`;
46
- }
47
- return truncatedLine.padEnd(limit || truncatedLine.length);
48
- });
49
- }
File without changes