@reliverse/relinka 1.1.4 → 1.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist-npm/components/anykey/index.js +77 -57
  2. package/dist-npm/components/block/block.js +61 -48
  3. package/dist-npm/components/checkbox/index.js +211 -178
  4. package/dist-npm/components/confirm/confirm-main.js +122 -86
  5. package/dist-npm/components/confirm/confirm-three.js +27 -24
  6. package/dist-npm/components/confirm/index.js +45 -36
  7. package/dist-npm/components/core/Separator.js +17 -15
  8. package/dist-npm/components/core/create-prompt.js +124 -101
  9. package/dist-npm/components/core/errors.js +15 -19
  10. package/dist-npm/components/core/hook-engine.js +120 -91
  11. package/dist-npm/components/core/index.js +12 -12
  12. package/dist-npm/components/core/key.js +6 -16
  13. package/dist-npm/components/core/lines.js +54 -45
  14. package/dist-npm/components/core/make-theme.js +30 -21
  15. package/dist-npm/components/core/position.js +23 -27
  16. package/dist-npm/components/core/promise-polyfill.js +14 -11
  17. package/dist-npm/components/core/screen-manager.js +74 -59
  18. package/dist-npm/components/core/theme.js +32 -22
  19. package/dist-npm/components/core/use-effect.js +15 -9
  20. package/dist-npm/components/core/use-keypress.js +23 -19
  21. package/dist-npm/components/core/use-memo.js +16 -10
  22. package/dist-npm/components/core/use-pagination.js +32 -33
  23. package/dist-npm/components/core/use-prefix.js +38 -40
  24. package/dist-npm/components/core/use-ref.js +5 -2
  25. package/dist-npm/components/core/use-state.js +23 -15
  26. package/dist-npm/components/core/useKeyPress.js +17 -14
  27. package/dist-npm/components/core/usePromptState.js +14 -8
  28. package/dist-npm/components/core/utils.js +16 -7
  29. package/dist-npm/components/date/date.js +204 -168
  30. package/dist-npm/components/editor/index.js +92 -71
  31. package/dist-npm/components/expand/index.js +124 -96
  32. package/dist-npm/components/figures/index.js +294 -283
  33. package/dist-npm/components/input/index.js +87 -61
  34. package/dist-npm/components/input/text-main.js +124 -86
  35. package/dist-npm/components/input/text.js +28 -24
  36. package/dist-npm/components/instance/basic.js +25 -17
  37. package/dist-npm/components/instance/browser.js +18 -14
  38. package/dist-npm/components/instance/reporter/basic.js +65 -46
  39. package/dist-npm/components/instance/reporter/browser.js +47 -44
  40. package/dist-npm/components/instance/reporter/fancy.js +96 -83
  41. package/dist-npm/components/instance/shared.js +2 -2
  42. package/dist-npm/components/mono/mono.js +62 -52
  43. package/dist-npm/components/mono/monoTwo.js +49 -35
  44. package/dist-npm/components/multiselect/group-multiselect.js +71 -55
  45. package/dist-npm/components/multiselect/multi-select-two.js +130 -98
  46. package/dist-npm/components/multiselect/multi-select.js +49 -43
  47. package/dist-npm/components/multiselect/multiselect-main.js +146 -120
  48. package/dist-npm/components/multiselect/num-multi-select.js +130 -98
  49. package/dist-npm/components/multiselect/num-multiselect-main.js +35 -24
  50. package/dist-npm/components/next-steps/next-steps.js +25 -24
  51. package/dist-npm/components/number/index.js +112 -78
  52. package/dist-npm/components/number/number-main.js +2 -96
  53. package/dist-npm/components/password/index.js +73 -54
  54. package/dist-npm/components/password/password-main.js +2 -120
  55. package/dist-npm/components/password/password-three.js +30 -26
  56. package/dist-npm/components/progressbar/ProgressBar.js +64 -45
  57. package/dist-npm/components/progressbar/helper.js +40 -33
  58. package/dist-npm/components/progressbar/index.js +1 -1
  59. package/dist-npm/components/prompts/create.js +44 -29
  60. package/dist-npm/components/prompts/index.js +45 -45
  61. package/dist-npm/components/prompts/prompt.js +260 -211
  62. package/dist-npm/components/prompts/promptTwo.js +605 -561
  63. package/dist-npm/components/prompts/relinka.js +295 -237
  64. package/dist-npm/components/range/range.js +294 -247
  65. package/dist-npm/components/rawlist/index.js +107 -87
  66. package/dist-npm/components/results/results.js +37 -31
  67. package/dist-npm/components/search/index.js +193 -148
  68. package/dist-npm/components/select/index.js +186 -148
  69. package/dist-npm/components/select/num-select-main.js +27 -27
  70. package/dist-npm/components/select/num-select.js +5 -125
  71. package/dist-npm/components/select/select-key.js +25 -24
  72. package/dist-npm/components/select/select-main.js +133 -109
  73. package/dist-npm/components/select/select-three.js +36 -32
  74. package/dist-npm/components/select/select-two.js +87 -95
  75. package/dist-npm/components/spinner/index.js +136 -107
  76. package/dist-npm/components/st-end/end.d.ts +1 -1
  77. package/dist-npm/components/st-end/end.js +26 -35
  78. package/dist-npm/components/st-end/start.d.ts +1 -1
  79. package/dist-npm/components/st-end/start.js +15 -30
  80. package/dist-npm/components/toggle/index.js +137 -113
  81. package/dist-npm/components/visual/animate/animate.js +10 -53
  82. package/dist-npm/components/visual/ascii-art/ascii-art.js +1 -12
  83. package/dist-npm/mod.js +2 -1
  84. package/dist-npm/testing/index.js +83 -58
  85. package/dist-npm/types/general.d.ts +2 -1
  86. package/dist-npm/types/general.js +1 -0
  87. package/dist-npm/types/index.js +3 -2
  88. package/dist-npm/types/keypress.js +36 -35
  89. package/dist-npm/types/readline.js +1 -0
  90. package/dist-npm/types/relinka.js +1 -0
  91. package/dist-npm/types/utils.js +1 -0
  92. package/dist-npm/utils/box.js +137 -135
  93. package/dist-npm/utils/color.js +74 -65
  94. package/dist-npm/utils/colorize.js +156 -124
  95. package/dist-npm/utils/component.js +657 -532
  96. package/dist-npm/utils/constants.js +63 -64
  97. package/dist-npm/utils/core.js +3 -2
  98. package/dist-npm/utils/decoder.js +223 -244
  99. package/dist-npm/utils/error.js +9 -4
  100. package/dist-npm/utils/errors.js +4 -14
  101. package/dist-npm/utils/format.js +24 -19
  102. package/dist-npm/utils/keypress.js +414 -316
  103. package/dist-npm/utils/log.js +15 -11
  104. package/dist-npm/utils/mapping.js +52 -45
  105. package/dist-npm/utils/messages.js +183 -183
  106. package/dist-npm/utils/platforms.js +20 -16
  107. package/dist-npm/utils/prompt-tmp.js +286 -235
  108. package/dist-npm/utils/prompt-two.js +286 -235
  109. package/dist-npm/utils/readline.js +7 -5
  110. package/dist-npm/utils/skeleton.js +170 -130
  111. package/dist-npm/utils/stream.js +2 -2
  112. package/dist-npm/utils/string.js +58 -44
  113. package/dist-npm/utils/terminal.js +34 -23
  114. package/dist-npm/utils/tree.js +41 -30
  115. package/dist-npm/utils/types.js +1 -0
  116. package/dist-npm/utils/utils.js +8 -8
  117. package/dist-npm/utils/variants.js +44 -36
  118. package/package.json +20 -28
@@ -1,61 +1,81 @@
1
- import logUpdate from "log-update";
2
- import { fmt } from "../../utils/messages.js";
3
- import { restoreCursor } from "../../utils/terminal.js";
4
- const DEFAULT_MESSAGE = "Press any key to continue...";
1
+ import logUpdate from 'log-update';
2
+ import process from 'node:process';
3
+ import {fmt} from '../../utils/messages.js';
4
+ import {restoreCursor} from '../../utils/terminal.js';
5
+
6
+ const isNumber = (a) => typeof a === 'number';
7
+ const isFn = (a) => typeof a === 'function';
8
+ const DEFAULT_MESSAGE = 'Press any key to continue...';
5
9
  const CTRL_C_CODE = 3;
10
+
6
11
  export async function anykeyPrompt(message = DEFAULT_MESSAGE, options = {}) {
7
- const { ctrlC = 1, preserveLog = false, hideMessage = false } = options;
8
- if (message) {
9
- message = fmt({
10
- type: "M_GENERAL",
11
- title: message,
12
- titleColor: "dim",
13
- dontRemoveBar: true
14
- });
15
- }
16
- if (message && !hideMessage) {
17
- logUpdate(message);
18
- }
19
- return new Promise((resolve, reject) => {
20
- const cleanup = () => {
21
- process.stdin.removeListener("data", handler);
22
- if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
23
- process.stdin.setRawMode(false);
24
- }
25
- process.stdin.pause();
26
- restoreCursor();
27
- };
28
- const handleCtrlC = () => {
29
- cleanup();
30
- if (ctrlC === "reject") {
31
- reject(new Error("User pressed CTRL+C"));
32
- } else if (ctrlC === false) {
33
- resolve();
34
- } else if (typeof ctrlC === "number") {
35
- process.exit(ctrlC);
36
- } else {
37
- throw new TypeError("Invalid ctrlC option");
38
- }
39
- };
40
- const handler = (buffer) => {
41
- cleanup();
42
- if (message && !preserveLog) {
43
- logUpdate.clear();
44
- } else {
45
- logUpdate.done();
46
- process.stdout.write("\n");
47
- }
48
- const [firstByte] = buffer;
49
- if (firstByte === CTRL_C_CODE) {
50
- handleCtrlC();
51
- } else {
52
- resolve();
53
- }
54
- };
55
- process.stdin.resume();
56
- if (process.stdin.isTTY && typeof process.stdin.setRawMode === "function") {
57
- process.stdin.setRawMode(true);
12
+ const {
13
+ ctrlC = 1,
14
+ preserveLog = false,
15
+ hideMessage = false,
16
+ } = options;
17
+
18
+ if (message) {
19
+ message = fmt({
20
+ type: 'M_GENERAL',
21
+ title: message,
22
+ titleColor: 'dim',
23
+ dontRemoveBar: true,
24
+ });
25
+ }
26
+
27
+ if (message && !hideMessage) {
28
+ logUpdate(message);
58
29
  }
59
- process.stdin.once("data", handler);
60
- });
30
+
31
+ return new Promise((resolve, reject) => {
32
+ const cleanup = () => {
33
+ process.stdin.removeListener('data', handler);
34
+ if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
35
+ process.stdin.setRawMode(false);
36
+ }
37
+
38
+ process.stdin.pause();
39
+ restoreCursor();
40
+ };
41
+
42
+ const handleCtrlC = () => {
43
+ cleanup();
44
+ if (ctrlC === 'reject') {
45
+ reject(Error('User pressed CTRL+C'));
46
+ } else if (!ctrlC) {
47
+ resolve();
48
+ } else if (isNumber(ctrlC)) {
49
+ process.exit(ctrlC);
50
+ } else {
51
+ throw TypeError('Invalid ctrlC option');
52
+ }
53
+
54
+ };
55
+
56
+ const handler = (buffer) => {
57
+ cleanup();
58
+ if (message && !preserveLog) {
59
+ logUpdate.clear();
60
+ } else {
61
+ logUpdate.done();
62
+ process.stdout.write('\n');
63
+ }
64
+
65
+ const [firstByte] = buffer;
66
+
67
+ if (firstByte === CTRL_C_CODE) {
68
+ handleCtrlC();
69
+ } else {
70
+ resolve();
71
+ }
72
+ };
73
+
74
+ process.stdin.resume();
75
+ if (process.stdin.isTTY && isFn(process.stdin.setRawMode)) {
76
+ process.stdin.setRawMode(true);
77
+ }
78
+
79
+ process.stdin.once('data', handler);
80
+ });
61
81
  }
@@ -1,52 +1,65 @@
1
- import { stdin, stdout } from "node:process";
2
- import * as readline from "node:readline";
3
- import { removeCursor, restoreCursor } from "../../utils/terminal.js";
4
- const isWindows = globalThis.process.platform.startsWith("win");
5
- export default function block({
6
- input = stdin,
7
- output = stdout,
8
- overwrite = true,
9
- hideCursor = true
10
- } = {}) {
11
- const rl = readline.createInterface({
12
- input,
13
- output,
14
- prompt: "",
15
- tabSize: 1
16
- });
17
- readline.emitKeypressEvents(input, rl);
18
- if (input.isTTY) {
19
- input.setRawMode(true);
20
- }
21
- const clear = (data, { name }) => {
22
- const str = String(data);
23
- if (str === "") {
24
- process.exit(0);
25
- }
26
- if (!overwrite) {
27
- return;
28
- }
29
- const dx = name === "return" ? 0 : -1;
30
- const dy = name === "return" ? -1 : 0;
31
- readline.moveCursor(output, dx, dy, () => {
32
- readline.clearLine(output, 1, () => {
33
- input.once("keypress", clear);
34
- });
1
+ import process, {stdin, stdout} from 'node:process';
2
+ import * as readline from 'node:readline';
3
+ import {removeCursor, restoreCursor} from '../../utils/terminal.js';
4
+
5
+ const isWindows = globalThis.process.platform.startsWith('win');
6
+
7
+ export default function block(overrides = {}) {
8
+ const {
9
+ input = stdin,
10
+ output = stdout,
11
+ overwrite = true,
12
+ hideCursor = true,
13
+ } = overrides;
14
+ const rl = readline.createInterface({
15
+ input,
16
+ output,
17
+ prompt: '',
18
+ tabSize: 1,
35
19
  });
36
- };
37
- if (hideCursor) {
38
- removeCursor();
39
- }
40
- input.once("keypress", clear);
41
- return () => {
42
- input.off("keypress", clear);
43
- if (hideCursor) {
44
- restoreCursor();
20
+
21
+ readline.emitKeypressEvents(input, rl);
22
+ if (input.isTTY) {
23
+ input.setRawMode(true);
45
24
  }
46
- if (input.isTTY && !isWindows) {
47
- input.setRawMode(false);
25
+
26
+ const clear = (data, {name}) => {
27
+ const str = String(data);
28
+
29
+ if (str === '') {
30
+ process.exit(0);
31
+ }
32
+
33
+ if (!overwrite) {
34
+ return;
35
+ }
36
+
37
+ const dx = name === 'return' ? 0 : -1;
38
+ const dy = name === 'return' ? -1 : 0;
39
+
40
+ readline.moveCursor(output, dx, dy, () => {
41
+ readline.clearLine(output, 1, () => {
42
+ input.once('keypress', clear);
43
+ });
44
+ });
45
+ };
46
+
47
+ if (hideCursor) {
48
+ removeCursor();
48
49
  }
49
- rl.terminal = false;
50
- rl.close();
51
- };
50
+
51
+ input.once('keypress', clear);
52
+ return () => {
53
+ input.off('keypress', clear);
54
+ if (hideCursor) {
55
+ restoreCursor();
56
+ }
57
+
58
+ if (input.isTTY && !isWindows) {
59
+ input.setRawMode(false);
60
+ }
61
+
62
+ rl.terminal = false;
63
+ rl.close();
64
+ };
52
65
  }