@reliverse/relinka 1.1.2 → 1.1.4

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 (85) hide show
  1. package/README.md +35 -28
  2. package/dist-npm/components/checkbox/index.js +8 -6
  3. package/dist-npm/components/confirm/index.js +7 -4
  4. package/dist-npm/components/core/Separator.d.ts +0 -4
  5. package/dist-npm/components/core/create-prompt.js +1 -1
  6. package/dist-npm/components/core/key.js +6 -6
  7. package/dist-npm/components/core/lines.d.ts +5 -17
  8. package/dist-npm/components/core/lines.js +6 -2
  9. package/dist-npm/components/core/make-theme.js +3 -1
  10. package/dist-npm/components/core/position.d.ts +0 -8
  11. package/dist-npm/components/core/position.js +9 -3
  12. package/dist-npm/components/core/promise-polyfill.js +2 -2
  13. package/dist-npm/components/core/screen-manager.js +2 -1
  14. package/dist-npm/components/core/theme.d.ts +12 -146
  15. package/dist-npm/components/core/theme.js +1 -1
  16. package/dist-npm/components/core/use-keypress.js +3 -1
  17. package/dist-npm/components/core/use-pagination.d.ts +4 -8
  18. package/dist-npm/components/core/use-prefix.js +1 -1
  19. package/dist-npm/components/core/useKeyPress.js +3 -1
  20. package/dist-npm/components/core/utils.d.ts +0 -11
  21. package/dist-npm/components/date/date.d.ts +1 -1
  22. package/dist-npm/components/date/date.js +74 -12
  23. package/dist-npm/components/expand/index.js +4 -2
  24. package/dist-npm/components/figures/index.js +5 -5
  25. package/dist-npm/components/instance/basic.d.ts +0 -12
  26. package/dist-npm/components/instance/basic.js +1 -1
  27. package/dist-npm/components/instance/browser.d.ts +0 -14
  28. package/dist-npm/components/instance/reporter/browser.js +5 -5
  29. package/dist-npm/components/instance/reporter/fancy.d.ts +1 -1
  30. package/dist-npm/components/instance/reporter/fancy.js +1 -1
  31. package/dist-npm/components/mono/mono.js +9 -9
  32. package/dist-npm/components/mono/monoTwo.d.ts +13 -76
  33. package/dist-npm/components/multiselect/multiselect-main.d.ts +4 -2
  34. package/dist-npm/components/multiselect/multiselect-main.js +12 -10
  35. package/dist-npm/components/password/password-main.js +1 -1
  36. package/dist-npm/components/progressbar/ProgressBar.d.ts +3 -14
  37. package/dist-npm/components/progressbar/ProgressBar.js +3 -14
  38. package/dist-npm/components/progressbar/helper.d.ts +2 -18
  39. package/dist-npm/components/prompts/create.d.ts +0 -13
  40. package/dist-npm/components/prompts/prompt.js +3 -3
  41. package/dist-npm/components/prompts/promptTwo.d.ts +34 -252
  42. package/dist-npm/components/prompts/promptTwo.js +6 -27
  43. package/dist-npm/components/prompts/relinka.d.ts +17 -114
  44. package/dist-npm/components/prompts/relinka.js +18 -103
  45. package/dist-npm/components/range/range.d.ts +12 -64
  46. package/dist-npm/components/range/range.js +36 -59
  47. package/dist-npm/components/rawlist/index.js +6 -4
  48. package/dist-npm/components/search/index.js +7 -5
  49. package/dist-npm/components/select/index.js +9 -3
  50. package/dist-npm/components/select/select-main.d.ts +1 -1
  51. package/dist-npm/components/select/select-main.js +4 -3
  52. package/dist-npm/components/select/select-two.js +3 -1
  53. package/dist-npm/components/toggle/index.js +3 -1
  54. package/dist-npm/testing/index.js +1 -1
  55. package/dist-npm/types/general.d.ts +30 -141
  56. package/dist-npm/types/keypress.d.ts +0 -3
  57. package/dist-npm/types/keypress.js +1 -1
  58. package/dist-npm/types/readline.d.ts +1 -9
  59. package/dist-npm/types/relinka.d.ts +1 -9
  60. package/dist-npm/types/utils.d.ts +0 -12
  61. package/dist-npm/utils/box.d.ts +14 -104
  62. package/dist-npm/utils/color.d.ts +0 -20
  63. package/dist-npm/utils/colorize.js +2 -1
  64. package/dist-npm/utils/component.d.ts +5 -26
  65. package/dist-npm/utils/component.js +1 -2
  66. package/dist-npm/utils/constants.d.ts +0 -21
  67. package/dist-npm/utils/constants.js +8 -8
  68. package/dist-npm/utils/decoder.d.ts +2 -17
  69. package/dist-npm/utils/decoder.js +54 -25
  70. package/dist-npm/utils/error.d.ts +0 -5
  71. package/dist-npm/utils/errors.d.ts +1 -1
  72. package/dist-npm/utils/errors.js +8 -4
  73. package/dist-npm/utils/format.d.ts +0 -12
  74. package/dist-npm/utils/keypress.d.ts +0 -6
  75. package/dist-npm/utils/keypress.js +12 -23
  76. package/dist-npm/utils/log.d.ts +0 -11
  77. package/dist-npm/utils/prompt-tmp.js +2 -2
  78. package/dist-npm/utils/prompt-two.js +2 -2
  79. package/dist-npm/utils/skeleton.d.ts +0 -3
  80. package/dist-npm/utils/skeleton.js +66 -22
  81. package/dist-npm/utils/stream.d.ts +0 -13
  82. package/dist-npm/utils/string.d.ts +0 -45
  83. package/dist-npm/utils/tree.d.ts +5 -34
  84. package/dist-npm/utils/variants.js +9 -9
  85. package/package.json +12 -5
package/README.md CHANGED
@@ -91,34 +91,41 @@ Run `bun dev` to launch the [examples/run-example.ts](./examples/run-example.ts)
91
91
  - 🔵: Partially supported
92
92
  - 🔴: Not supported
93
93
 
94
- | **Feature** | **@reliverse/relinka** | **@inquirer/prompts** | **@enquirer/enquirer** | **@clack/prompts** | **@terkelg/prompts** | **@cronvel/terminal-kit** | **@unjs/consola** |
95
- |------------------------------------------------------------|----------------------------------------------------|-----------------------|------------------------|---------------------|------------------------------|-----------------------------|-------------------|
96
- | **Full Node.js Modules Support** | 🟢 Native ES module package | 🟡 | 🟡 | 🟡 | 🔴 CJS-only | 🔴 CJS-only | 🟡 |
97
- | **Both terminal and browser support** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 |
98
- | **Codebase typesafety with intellisense** | 🔵 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
99
- | **Runtime typesafety with schema validation** | 🟢 TypeBox & Custom | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
100
- | **Usage Examples** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
101
- | **Mono Component** | 🟢 Mono (All-In-One) & Separate | 🟡 | 🟡 | 🟡 | 🔵 Mono-only | 🟡 | 🟡 |
102
- | **Start Component** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
103
- | **Text Component** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
104
- | **Customization** | 🟢 Colors, typography, variants, borders, and more | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
105
- | **Visual Components: Separator, Animated Text, ASCII Art** | 🟢 Includes 6 animations and 290 ASCII fonts | 🔵 Separator only | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
106
- | **Password Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
107
- | **Number Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
108
- | **Confirm Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
109
- | **Select Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
110
- | **Multiselect Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
111
- | **Search/Autocomplete Component** | 🔵 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
112
- | **Spinner & Progressbar Components** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
113
- | **Image Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
114
- | **Custom Validation** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
115
- | **Error Handling** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
116
- | **Ease of Setup** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
117
- | **Crash Resilience** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
118
- | **General DX** | 🔵 Clean and understandable TypeScript code | 🟡 | 🟡 | 🟡 | 🔴 JS-only | 🔴 JS-only | 🟡 |
119
- | **DX: Classes** | 🟢 Minimal number of classes as possible | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
120
- | **Documentation** | 🔵 | 🟡 | 🟡 | 🟡 | 🔵 | 🟢 | 🟡 |
121
- | **Designed With UX in Mind** | 🔵 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
94
+ | **Feature** | **@reliverse/relinka** | **@inquirer/prompts** | **@enquirer/enquirer** | **@clack/prompts** | **@terkelg/prompts** | **@cronvel/terminal-kit** | **@unjs/citty** | **@unjs/consola** |
95
+ |------------------------------------------------------------|----------------------------------------------------|-----------------------|------------------------|---------------------|------------------------------|-----------------------------|-------------------|-------------------|
96
+ | **Full Node.js Modules Support** | 🟢 Native ES module package | 🟡 | 🟡 | 🟡 | 🔴 CJS-only | 🔴 CJS-only | 🟡 | 🟡 |
97
+ | **Works both in node, bun, and deno environments** | 🔵 node+bun (deno support is coming soon) | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟢 |
98
+ | **Codebase typesafety with intellisense** | 🔵 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
99
+ | **Runtime typesafety with schema validation** | 🟢 TypeBox & Custom | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
100
+ | **Usage Examples** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
101
+ | **Mono Component** | 🟢 Mono (All-In-One) & Separate | 🟡 | 🟡 | 🟡 | 🔵 Mono-only | 🟡 | 🟡 | 🟡 |
102
+ | **Start Component** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
103
+ | **Text Component** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
104
+ | **Customization** | 🟢 Colors, typography, variants, borders, and more | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
105
+ | **Visual Components: Separator, Animated Text, ASCII Art** | 🟢 Includes 6 animations and 290 ASCII fonts | 🔵 Separator only | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
106
+ | **Password Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
107
+ | **Number Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
108
+ | **Confirm Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
109
+ | **Select Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
110
+ | **Multiselect Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
111
+ | **Search/Autocomplete Component** | 🔵 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
112
+ | **Spinner & Progressbar Components** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 | 🟡 |
113
+ | **Image Component** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 | 🟡 |
114
+ | **Custom Validation** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
115
+ | **Error Handling** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
116
+ | **Ease of Setup** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
117
+ | **Crash Resilience** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
118
+ | **General DX** | 🔵 Clean and understandable TypeScript code | 🟡 | 🟡 | 🟡 | 🔴 JS-only | 🔴 JS-only | 🟡 | 🟡 |
119
+ | **DX: Classes** | 🟢 Minimal number of classes as possible | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
120
+ | **Documentation** | 🔵 | 🟡 | 🟡 | 🟡 | 🔵 | 🟢 | 🟡 | 🟡 |
121
+ | **Designed With UX/DX in Mind** | 🟢 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 |
122
+ | **Fast and lightweight argument parser** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
123
+ | **Smart value parsing with typecast** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
124
+ | **Boolean shortcuts and unknown flag handling** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
125
+ | **Nested sub-commands** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
126
+ | **Lazy and Async commands** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
127
+ | **Pluggable and composable API** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
128
+ | **Auto generated usage and help** | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟡 | 🟢 | 🟡 |
122
129
 
123
130
  **Related Links**: [ESM/CJS](https://dev.to/iggredible/what-the-heck-are-cjs-amd-umd-and-esm-ikm), ["Pure ESM package"](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c), [Clean code](https://github.com/ryanmcdermott/clean-code-javascript#readme), ["UX patterns for CLI tools"](https://lucasfcosta.com/2022/06/01/ux-patterns-cli-tools.html), [DX (Developer Experience)](https://github.blog/enterprise-software/collaboration/developer-experience-what-is-it-and-why-should-you-care), [TypeBox](https://github.com/sinclairzx81/typebox#readme), ["ANSI Escape Sequences"](https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b)
124
131
 
@@ -47,7 +47,9 @@ function check(checked) {
47
47
  }
48
48
  function normalizeChoices(choices) {
49
49
  return choices.map((choice) => {
50
- if (Separator.isSeparator(choice)) return choice;
50
+ if (Separator.isSeparator(choice)) {
51
+ return choice;
52
+ }
51
53
  if (typeof choice === "string") {
52
54
  return {
53
55
  value: choice,
@@ -59,16 +61,16 @@ function normalizeChoices(choices) {
59
61
  }
60
62
  const name = choice.name ?? String(choice.value);
61
63
  return {
62
- // @ts-expect-error - TODO: fix ts
64
+
63
65
  value: choice.value,
64
66
  name,
65
- // @ts-expect-error - TODO: fix ts
67
+
66
68
  short: choice.short ?? name,
67
- // @ts-expect-error - TODO: fix ts
69
+
68
70
  description: choice.description,
69
- // @ts-expect-error - TODO: fix ts
71
+
70
72
  disabled: choice.disabled ?? false,
71
- // @ts-expect-error - TODO: fix ts
73
+
72
74
  checked: choice.checked ?? false
73
75
  };
74
76
  });
@@ -14,9 +14,12 @@ export default createPrompt((config, done) => {
14
14
  const prefix = usePrefix({ status, theme });
15
15
  useKeypress((key, rl) => {
16
16
  if (isEnterKey(key)) {
17
- let answer = config.default !== false;
18
- if (/^(y|yes)/i.test(value)) answer = true;
19
- else if (/^(n|no)/i.test(value)) answer = false;
17
+ let answer = config.default;
18
+ if (/^(y|yes)/i.test(value)) {
19
+ answer = true;
20
+ } else if (/^(n|no)/i.test(value)) {
21
+ answer = false;
22
+ }
20
23
  setValue(transformer(answer));
21
24
  setStatus("done");
22
25
  done(answer);
@@ -30,7 +33,7 @@ export default createPrompt((config, done) => {
30
33
  formattedValue = theme.style.answer(value);
31
34
  } else {
32
35
  defaultValue = ` ${theme.style.defaultAnswer(
33
- config.default === false ? "y/N" : "Y/n"
36
+ !config.default ? "y/N" : "Y/n"
34
37
  )}`;
35
38
  }
36
39
  const message = theme.style.message(config.message, status);
@@ -1,7 +1,3 @@
1
- /**
2
- * Separator object
3
- * Used to space/separate choices group
4
- */
5
1
  export declare class Separator {
6
2
  readonly separator: any;
7
3
  readonly type = "separator";
@@ -30,7 +30,7 @@ export function createPrompt(view) {
30
30
  const callerFilename = callSites[1]?.getFileName?.();
31
31
  const prompt = (config, context = {}) => {
32
32
  const { input = process.stdin, signal } = context;
33
- const cleanups = /* @__PURE__ */ new Set();
33
+ const cleanups = new Set();
34
34
  const output = new MuteStream();
35
35
  output.pipe(context.output ?? process.stdout);
36
36
  const rl = readline.createInterface({
@@ -1,13 +1,13 @@
1
1
  export const isUpKey = (key) => (
2
- // The up key
3
- key.name === "up" || // Vim keybinding
4
- key.name === "k" || // Emacs keybinding
2
+
3
+ key.name === "up" ||
4
+ key.name === "k" ||
5
5
  key.ctrl && key.name === "p"
6
6
  );
7
7
  export const isDownKey = (key) => (
8
- // The down key
9
- key.name === "down" || // Vim keybinding
10
- key.name === "j" || // Emacs keybinding
8
+
9
+ key.name === "down" ||
10
+ key.name === "j" ||
11
11
  key.ctrl && key.name === "n"
12
12
  );
13
13
  export const isSpaceKey = (key) => key.name === "space";
@@ -1,26 +1,14 @@
1
1
  import { type Prettify } from "../../types/index.js";
2
- /** Represents an item that's part of a layout, about to be rendered */
3
2
  export type Layout<T> = {
4
3
  item: T;
5
4
  index: number;
6
5
  isActive: boolean;
7
6
  };
8
- /**
9
- * Renders a page of items as lines that fit within the given width ensuring
10
- * that the number of lines is not greater than the page size, and the active
11
- * item renders at the provided position, while prioritizing that as many lines
12
- * of the active item get rendered as possible.
13
- */
14
7
  export declare function lines<T>({ items, width, renderItem, active, position: requested, pageSize, }: {
15
8
  items: readonly T[];
16
- /** The width of a rendered line in characters. */
17
- width: number;
18
- /** Renders an item as part of a page. */
19
- renderItem: (layout: Prettify<Layout<T>>) => string;
20
- /** The index of the active item in the list of items. */
21
- active: number;
22
- /** The position on the page at which to render the active item. */
23
- position: number;
24
- /** The number of lines to render per page. */
25
- pageSize: number;
9
+ width: number;
10
+ renderItem: (layout: Prettify<Layout<T>>) => string;
11
+ active: number;
12
+ position: number;
13
+ pageSize: number;
26
14
  }): string[];
@@ -31,7 +31,9 @@ export function lines({
31
31
  while (bufferPointer < pageSize && layoutPointer < layoutsInPage.length) {
32
32
  for (const line of renderItemAt(layoutPointer)) {
33
33
  pageBuffer[bufferPointer++] = line;
34
- if (bufferPointer >= pageSize) break;
34
+ if (bufferPointer >= pageSize) {
35
+ break;
36
+ }
35
37
  }
36
38
  layoutPointer++;
37
39
  }
@@ -40,7 +42,9 @@ export function lines({
40
42
  while (bufferPointer >= 0 && layoutPointer >= 0) {
41
43
  for (const line of renderItemAt(layoutPointer).reverse()) {
42
44
  pageBuffer[bufferPointer--] = line;
43
- if (bufferPointer < 0) break;
45
+ if (bufferPointer < 0) {
46
+ break;
47
+ }
44
48
  }
45
49
  layoutPointer--;
46
50
  }
@@ -1,6 +1,8 @@
1
1
  import { defaultTheme } from "./theme.js";
2
2
  function isPlainObject(value) {
3
- if (typeof value !== "object" || value === null) return false;
3
+ if (typeof value !== "object" || value === null) {
4
+ return false;
5
+ }
4
6
  let proto = value;
5
7
  while (Object.getPrototypeOf(proto) !== null) {
6
8
  proto = Object.getPrototypeOf(proto);
@@ -1,16 +1,8 @@
1
- /**
2
- * Creates the next position for the active item considering a finite list of
3
- * items to be rendered on a page.
4
- */
5
1
  export declare function finite({ active, pageSize, total, }: {
6
2
  active: number;
7
3
  pageSize: number;
8
4
  total: number;
9
5
  }): number;
10
- /**
11
- * Creates the next position for the active item considering an infinitely
12
- * looping list of items to be rendered on the page.
13
- */
14
6
  export declare function infinite({ active, lastActive, total, pageSize, pointer, }: {
15
7
  active: number;
16
8
  lastActive: number;
@@ -4,8 +4,12 @@ export function finite({
4
4
  total
5
5
  }) {
6
6
  const middle = Math.floor(pageSize / 2);
7
- if (total <= pageSize || active < middle) return active;
8
- if (active >= total - middle) return active + pageSize - total;
7
+ if (total <= pageSize || active < middle) {
8
+ return active;
9
+ }
10
+ if (active >= total - middle) {
11
+ return active + pageSize - total;
12
+ }
9
13
  return middle;
10
14
  }
11
15
  export function infinite({
@@ -15,7 +19,9 @@ export function infinite({
15
19
  pageSize,
16
20
  pointer
17
21
  }) {
18
- if (total <= pageSize) return active;
22
+ if (total <= pageSize) {
23
+ return active;
24
+ }
19
25
  if (lastActive < active && active - lastActive < pageSize) {
20
26
  return Math.min(Math.floor(pageSize / 2), pointer + active - lastActive);
21
27
  }
@@ -1,6 +1,6 @@
1
1
  export class PromisePolyfill extends Promise {
2
- // Available starting from Node 22
3
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers
2
+
3
+
4
4
  static withResolver() {
5
5
  let resolve;
6
6
  let reject;
@@ -39,8 +39,9 @@ export default class ScreenManager {
39
39
  let output = content + (bottomContent ? "\n" + bottomContent : "");
40
40
  const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
41
41
  const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
42
- if (bottomContentHeight > 0)
42
+ if (bottomContentHeight > 0) {
43
43
  output += ansiEscapes.cursorUp(bottomContentHeight);
44
+ }
44
45
  output += ansiEscapes.cursorTo(this.cursorPos.cols);
45
46
  this.write(
46
47
  cursorDown(this.extraLinesUnderPrompt) + ansiEscapes.eraseLines(this.height) + output
@@ -1,153 +1,19 @@
1
1
  import type { Prettify } from "../../types/index.js";
2
- /**
3
- * Union type representing the possible statuses of a prompt.
4
- *
5
- * - `'loading'`: The prompt is currently loading.
6
- * - `'idle'`: The prompt is loaded and currently waiting for the user to
7
- * submit an answer.
8
- * - `'done'`: The user has submitted an answer and the prompt is finished.
9
- * - `string`: Any other string: The prompt is in a custom state.
10
- */
11
2
  export type Status = "loading" | "idle" | "done" | (string & {});
12
3
  type DefaultTheme = {
13
- /**
14
- * Prefix to prepend to the message. If a function is provided, it will be
15
- * called with the current status of the prompt, and the return value will be
16
- * used as the prefix.
17
- *
18
- * @remarks
19
- * If `status === 'loading'`, this property is ignored and the spinner (styled
20
- * by the `spinner` property) will be displayed instead.
21
- *
22
- * @defaultValue
23
- * ```ts
24
- * // import colors from 'yoctocolors-cjs';
25
- * (status) => status === 'done' ? colors.green('✔') : colors.blue('?')
26
- * ```
27
- */
28
- prefix: string | Prettify<Omit<Record<Status, string>, "loading">>;
29
- /**
30
- * Configuration for the spinner that is displayed when the prompt is in the
31
- * `'loading'` state.
32
- *
33
- * We recommend the use of {@link https://github.com/sindresorhus/cli-spinners|cli-spinners} for a list of available spinners.
34
- */
35
- spinner: {
36
- /**
37
- * The time interval between frames, in milliseconds.
38
- *
39
- * @defaultValue
40
- * ```ts
41
- * 80
42
- * ```
43
- */
44
- interval: number;
45
- /**
46
- * A list of frames to show for the spinner.
47
- *
48
- * @defaultValue
49
- * ```ts
50
- * ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
51
- * ```
52
- */
53
- frames: string[];
4
+ prefix: string | Prettify<Omit<Record<Status, string>, "loading">>;
5
+ spinner: {
6
+ interval: number;
7
+ frames: string[];
54
8
  };
55
- /**
56
- * Object containing functions to style different parts of the prompt.
57
- */
58
- style: {
59
- /**
60
- * Style to apply to the user's answer once it has been submitted.
61
- *
62
- * @param text - The user's answer.
63
- * @returns The styled answer.
64
- *
65
- * @defaultValue
66
- * ```ts
67
- * // import colors from 'yoctocolors-cjs';
68
- * (text) => colors.cyan(text)
69
- * ```
70
- */
71
- answer: (text: string) => string;
72
- /**
73
- * Style to apply to the message displayed to the user.
74
- *
75
- * @param text - The message to style.
76
- * @param status - The current status of the prompt.
77
- * @returns The styled message.
78
- *
79
- * @defaultValue
80
- * ```ts
81
- * // import colors from 'yoctocolors-cjs';
82
- * (text, status) => colors.bold(text)
83
- * ```
84
- */
85
- message: (text: string, status: Status) => string;
86
- /**
87
- * Style to apply to error messages.
88
- *
89
- * @param text - The error message.
90
- * @returns The styled error message.
91
- *
92
- * @defaultValue
93
- * ```ts
94
- * // import colors from 'yoctocolors-cjs';
95
- * (text) => colors.red(`> ${text}`)
96
- * ```
97
- */
98
- error: (text: string) => string;
99
- /**
100
- * Style to apply to the default answer when one is provided.
101
- *
102
- * @param text - The default answer.
103
- * @returns The styled default answer.
104
- *
105
- * @defaultValue
106
- * ```ts
107
- * // import colors from 'yoctocolors-cjs';
108
- * (text) => colors.dim(`(${text})`)
109
- * ```
110
- */
111
- defaultAnswer: (text: string) => string;
112
- /**
113
- * Style to apply to help text.
114
- *
115
- * @param text - The help text.
116
- * @returns The styled help text.
117
- *
118
- * @defaultValue
119
- * ```ts
120
- * // import colors from 'yoctocolors-cjs';
121
- * (text) => colors.dim(text)
122
- * ```
123
- */
124
- help: (text: string) => string;
125
- /**
126
- * Style to apply to highlighted text.
127
- *
128
- * @param text - The text to highlight.
129
- * @returns The highlighted text.
130
- *
131
- * @defaultValue
132
- * ```ts
133
- * // import colors from 'yoctocolors-cjs';
134
- * (text) => colors.cyan(text)
135
- * ```
136
- */
137
- highlight: (text: string) => string;
138
- /**
139
- * Style to apply to keyboard keys referred to in help texts.
140
- *
141
- * @param text - The key to style.
142
- * @returns The styled key.
143
- *
144
- * @defaultValue
145
- * ```ts
146
- * // import colors from 'yoctocolors-cjs';
147
- * (text) => colors.cyan(colors.bold(`<${text}>`))
148
- * ```
149
- */
150
- key: (text: string) => string;
9
+ style: {
10
+ answer: (text: string) => string;
11
+ message: (text: string, status: Status) => string;
12
+ error: (text: string) => string;
13
+ defaultAnswer: (text: string) => string;
14
+ help: (text: string) => string;
15
+ highlight: (text: string) => string;
16
+ key: (text: string) => string;
151
17
  };
152
18
  };
153
19
  export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
@@ -3,7 +3,7 @@ import figures from "../../components/figures/index.js";
3
3
  export const defaultTheme = {
4
4
  prefix: {
5
5
  idle: colors.blue("?"),
6
- // TODO: use figure
6
+
7
7
  done: colors.green(figures.tick)
8
8
  },
9
9
  spinner: {
@@ -7,7 +7,9 @@ export function useKeypress(userHandler) {
7
7
  useEffect((rl) => {
8
8
  let ignore = false;
9
9
  const handler = withUpdates((_input, event) => {
10
- if (ignore) return;
10
+ if (ignore) {
11
+ return;
12
+ }
11
13
  void signal.current(event, rl);
12
14
  });
13
15
  rl.input.on("keypress", handler);
@@ -3,13 +3,9 @@ import { type Layout } from "./lines.js";
3
3
  import { type Theme } from "./theme.js";
4
4
  export declare function usePagination<T>({ items, active, renderItem, pageSize, loop, }: {
5
5
  items: readonly T[];
6
- /** The index of the active item. */
7
- active: number;
8
- /** Renders an item as part of a page. */
9
- renderItem: (layout: Prettify<Layout<T>>) => string;
10
- /** The size of the page. */
11
- pageSize: number;
12
- /** Allows creating an infinitely looping list. `true` if unspecified. */
13
- loop?: boolean;
6
+ active: number;
7
+ renderItem: (layout: Prettify<Layout<T>>) => string;
8
+ pageSize: number;
9
+ loop?: boolean;
14
10
  theme?: Theme;
15
11
  }): string;
@@ -38,5 +38,5 @@ export function usePrefix({
38
38
  return spinner.frames[tick];
39
39
  }
40
40
  const iconName = status === "loading" ? "idle" : status;
41
- return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix["idle"];
41
+ return typeof prefix === "string" ? prefix : prefix[iconName] ?? prefix.idle;
42
42
  }
@@ -2,7 +2,9 @@ import { stdin } from "node:process";
2
2
  import readline from "node:readline";
3
3
  export function useKeyPress(callback) {
4
4
  readline.emitKeypressEvents(stdin);
5
- if (stdin.isTTY) stdin.setRawMode(true);
5
+ if (stdin.isTTY) {
6
+ stdin.setRawMode(true);
7
+ }
6
8
  const onKeypress = (str, key) => {
7
9
  callback(str, key);
8
10
  };
@@ -1,13 +1,2 @@
1
- /**
2
- * Force line returns at specific width. This function is ANSI code friendly and it'll
3
- * ignore invisible codes during width calculation.
4
- * @param {string} content
5
- * @param {number} width
6
- * @return {string}
7
- */
8
1
  export declare function breakLines(content: string, width: number): string;
9
- /**
10
- * Returns the width of the active readline, or 80 as default value.
11
- * @returns {number}
12
- */
13
2
  export declare function readlineWidth(): number;
@@ -1,4 +1,4 @@
1
- import { type TSchema } from "@sinclair/typebox";
1
+ import type { TSchema } from "@sinclair/typebox";
2
2
  import type { PromptOptions } from "../../types/general.js";
3
3
  export declare function datePrompt<T extends TSchema>(options: PromptOptions<T> & {
4
4
  dateFormat: string;