@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.
- package/README.md +35 -28
- package/dist-npm/components/checkbox/index.js +8 -6
- package/dist-npm/components/confirm/index.js +7 -4
- package/dist-npm/components/core/Separator.d.ts +0 -4
- package/dist-npm/components/core/create-prompt.js +1 -1
- package/dist-npm/components/core/key.js +6 -6
- package/dist-npm/components/core/lines.d.ts +5 -17
- package/dist-npm/components/core/lines.js +6 -2
- package/dist-npm/components/core/make-theme.js +3 -1
- package/dist-npm/components/core/position.d.ts +0 -8
- package/dist-npm/components/core/position.js +9 -3
- package/dist-npm/components/core/promise-polyfill.js +2 -2
- package/dist-npm/components/core/screen-manager.js +2 -1
- package/dist-npm/components/core/theme.d.ts +12 -146
- package/dist-npm/components/core/theme.js +1 -1
- package/dist-npm/components/core/use-keypress.js +3 -1
- package/dist-npm/components/core/use-pagination.d.ts +4 -8
- package/dist-npm/components/core/use-prefix.js +1 -1
- package/dist-npm/components/core/useKeyPress.js +3 -1
- package/dist-npm/components/core/utils.d.ts +0 -11
- package/dist-npm/components/date/date.d.ts +1 -1
- package/dist-npm/components/date/date.js +74 -12
- package/dist-npm/components/expand/index.js +4 -2
- package/dist-npm/components/figures/index.js +5 -5
- package/dist-npm/components/instance/basic.d.ts +0 -12
- package/dist-npm/components/instance/basic.js +1 -1
- package/dist-npm/components/instance/browser.d.ts +0 -14
- package/dist-npm/components/instance/reporter/browser.js +5 -5
- package/dist-npm/components/instance/reporter/fancy.d.ts +1 -1
- package/dist-npm/components/instance/reporter/fancy.js +1 -1
- package/dist-npm/components/mono/mono.js +9 -9
- package/dist-npm/components/mono/monoTwo.d.ts +13 -76
- package/dist-npm/components/multiselect/multiselect-main.d.ts +4 -2
- package/dist-npm/components/multiselect/multiselect-main.js +12 -10
- package/dist-npm/components/password/password-main.js +1 -1
- package/dist-npm/components/progressbar/ProgressBar.d.ts +3 -14
- package/dist-npm/components/progressbar/ProgressBar.js +3 -14
- package/dist-npm/components/progressbar/helper.d.ts +2 -18
- package/dist-npm/components/prompts/create.d.ts +0 -13
- package/dist-npm/components/prompts/prompt.js +3 -3
- package/dist-npm/components/prompts/promptTwo.d.ts +34 -252
- package/dist-npm/components/prompts/promptTwo.js +6 -27
- package/dist-npm/components/prompts/relinka.d.ts +17 -114
- package/dist-npm/components/prompts/relinka.js +18 -103
- package/dist-npm/components/range/range.d.ts +12 -64
- package/dist-npm/components/range/range.js +36 -59
- package/dist-npm/components/rawlist/index.js +6 -4
- package/dist-npm/components/search/index.js +7 -5
- package/dist-npm/components/select/index.js +9 -3
- package/dist-npm/components/select/select-main.d.ts +1 -1
- package/dist-npm/components/select/select-main.js +4 -3
- package/dist-npm/components/select/select-two.js +3 -1
- package/dist-npm/components/toggle/index.js +3 -1
- package/dist-npm/testing/index.js +1 -1
- package/dist-npm/types/general.d.ts +30 -141
- package/dist-npm/types/keypress.d.ts +0 -3
- package/dist-npm/types/keypress.js +1 -1
- package/dist-npm/types/readline.d.ts +1 -9
- package/dist-npm/types/relinka.d.ts +1 -9
- package/dist-npm/types/utils.d.ts +0 -12
- package/dist-npm/utils/box.d.ts +14 -104
- package/dist-npm/utils/color.d.ts +0 -20
- package/dist-npm/utils/colorize.js +2 -1
- package/dist-npm/utils/component.d.ts +5 -26
- package/dist-npm/utils/component.js +1 -2
- package/dist-npm/utils/constants.d.ts +0 -21
- package/dist-npm/utils/constants.js +8 -8
- package/dist-npm/utils/decoder.d.ts +2 -17
- package/dist-npm/utils/decoder.js +54 -25
- package/dist-npm/utils/error.d.ts +0 -5
- package/dist-npm/utils/errors.d.ts +1 -1
- package/dist-npm/utils/errors.js +8 -4
- package/dist-npm/utils/format.d.ts +0 -12
- package/dist-npm/utils/keypress.d.ts +0 -6
- package/dist-npm/utils/keypress.js +12 -23
- package/dist-npm/utils/log.d.ts +0 -11
- package/dist-npm/utils/prompt-tmp.js +2 -2
- package/dist-npm/utils/prompt-two.js +2 -2
- package/dist-npm/utils/skeleton.d.ts +0 -3
- package/dist-npm/utils/skeleton.js +66 -22
- package/dist-npm/utils/stream.d.ts +0 -13
- package/dist-npm/utils/string.d.ts +0 -45
- package/dist-npm/utils/tree.d.ts +5 -34
- package/dist-npm/utils/variants.js +9 -9
- 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
|
-
| **
|
|
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))
|
|
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
|
-
|
|
64
|
+
|
|
63
65
|
value: choice.value,
|
|
64
66
|
name,
|
|
65
|
-
|
|
67
|
+
|
|
66
68
|
short: choice.short ?? name,
|
|
67
|
-
|
|
69
|
+
|
|
68
70
|
description: choice.description,
|
|
69
|
-
|
|
71
|
+
|
|
70
72
|
disabled: choice.disabled ?? false,
|
|
71
|
-
|
|
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
|
|
18
|
-
if (/^(y|yes)/i.test(value))
|
|
19
|
-
|
|
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
|
|
36
|
+
!config.default ? "y/N" : "Y/n"
|
|
34
37
|
)}`;
|
|
35
38
|
}
|
|
36
39
|
const message = theme.style.message(config.message, status);
|
|
@@ -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 =
|
|
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
|
-
|
|
3
|
-
key.name === "up" ||
|
|
4
|
-
key.name === "k" ||
|
|
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
|
-
|
|
9
|
-
key.name === "down" ||
|
|
10
|
-
key.name === "j" ||
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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)
|
|
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)
|
|
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)
|
|
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)
|
|
8
|
-
|
|
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)
|
|
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
|
}
|
|
@@ -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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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>;
|
|
@@ -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)
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
|
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)
|
|
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 {
|
|
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;
|