@inquirer/core 11.0.0 → 11.0.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 (75) hide show
  1. package/package.json +11 -16
  2. package/dist/commonjs/index.d.ts +0 -13
  3. package/dist/commonjs/index.js +0 -46
  4. package/dist/commonjs/lib/Separator.d.ts +0 -10
  5. package/dist/commonjs/lib/Separator.js +0 -28
  6. package/dist/commonjs/lib/create-prompt.d.ts +0 -4
  7. package/dist/commonjs/lib/create-prompt.js +0 -156
  8. package/dist/commonjs/lib/errors.d.ts +0 -20
  9. package/dist/commonjs/lib/errors.js +0 -29
  10. package/dist/commonjs/lib/hook-engine.d.ts +0 -23
  11. package/dist/commonjs/lib/hook-engine.js +0 -118
  12. package/dist/commonjs/lib/key.d.ts +0 -12
  13. package/dist/commonjs/lib/key.js +0 -29
  14. package/dist/commonjs/lib/make-theme.d.ts +0 -3
  15. package/dist/commonjs/lib/make-theme.js +0 -33
  16. package/dist/commonjs/lib/pagination/use-pagination.d.ts +0 -16
  17. package/dist/commonjs/lib/pagination/use-pagination.js +0 -124
  18. package/dist/commonjs/lib/promise-polyfill.d.ts +0 -7
  19. package/dist/commonjs/lib/promise-polyfill.js +0 -18
  20. package/dist/commonjs/lib/screen-manager.d.ts +0 -14
  21. package/dist/commonjs/lib/screen-manager.js +0 -82
  22. package/dist/commonjs/lib/theme.d.ts +0 -155
  23. package/dist/commonjs/lib/theme.js +0 -27
  24. package/dist/commonjs/lib/use-effect.d.ts +0 -2
  25. package/dist/commonjs/lib/use-effect.js +0 -14
  26. package/dist/commonjs/lib/use-keypress.d.ts +0 -3
  27. package/dist/commonjs/lib/use-keypress.js +0 -23
  28. package/dist/commonjs/lib/use-memo.d.ts +0 -1
  29. package/dist/commonjs/lib/use-memo.js +0 -17
  30. package/dist/commonjs/lib/use-prefix.d.ts +0 -5
  31. package/dist/commonjs/lib/use-prefix.js +0 -38
  32. package/dist/commonjs/lib/use-ref.d.ts +0 -6
  33. package/dist/commonjs/lib/use-ref.js +0 -7
  34. package/dist/commonjs/lib/use-state.d.ts +0 -4
  35. package/dist/commonjs/lib/use-state.js +0 -23
  36. package/dist/commonjs/lib/utils.d.ts +0 -13
  37. package/dist/commonjs/lib/utils.js +0 -32
  38. package/dist/commonjs/package.json +0 -3
  39. package/dist/esm/index.d.ts +0 -13
  40. package/dist/esm/index.js +0 -12
  41. package/dist/esm/lib/Separator.d.ts +0 -10
  42. package/dist/esm/lib/Separator.js +0 -21
  43. package/dist/esm/lib/create-prompt.d.ts +0 -4
  44. package/dist/esm/lib/create-prompt.js +0 -117
  45. package/dist/esm/lib/errors.d.ts +0 -20
  46. package/dist/esm/lib/errors.js +0 -21
  47. package/dist/esm/lib/hook-engine.d.ts +0 -23
  48. package/dist/esm/lib/hook-engine.js +0 -110
  49. package/dist/esm/lib/key.d.ts +0 -12
  50. package/dist/esm/lib/key.js +0 -19
  51. package/dist/esm/lib/make-theme.d.ts +0 -3
  52. package/dist/esm/lib/make-theme.js +0 -30
  53. package/dist/esm/lib/pagination/use-pagination.d.ts +0 -16
  54. package/dist/esm/lib/pagination/use-pagination.js +0 -121
  55. package/dist/esm/lib/promise-polyfill.d.ts +0 -7
  56. package/dist/esm/lib/promise-polyfill.js +0 -14
  57. package/dist/esm/lib/screen-manager.d.ts +0 -14
  58. package/dist/esm/lib/screen-manager.js +0 -79
  59. package/dist/esm/lib/theme.d.ts +0 -155
  60. package/dist/esm/lib/theme.js +0 -21
  61. package/dist/esm/lib/use-effect.d.ts +0 -2
  62. package/dist/esm/lib/use-effect.js +0 -11
  63. package/dist/esm/lib/use-keypress.d.ts +0 -3
  64. package/dist/esm/lib/use-keypress.js +0 -20
  65. package/dist/esm/lib/use-memo.d.ts +0 -1
  66. package/dist/esm/lib/use-memo.js +0 -14
  67. package/dist/esm/lib/use-prefix.d.ts +0 -5
  68. package/dist/esm/lib/use-prefix.js +0 -35
  69. package/dist/esm/lib/use-ref.d.ts +0 -6
  70. package/dist/esm/lib/use-ref.js +0 -4
  71. package/dist/esm/lib/use-state.d.ts +0 -4
  72. package/dist/esm/lib/use-state.js +0 -20
  73. package/dist/esm/lib/utils.d.ts +0 -13
  74. package/dist/esm/lib/utils.js +0 -25
  75. package/dist/esm/package.json +0 -3
@@ -1,79 +0,0 @@
1
- import { stripVTControlCharacters } from 'node:util';
2
- import { breakLines, readlineWidth } from "./utils.js";
3
- import { cursorDown, cursorUp, cursorTo, cursorShow, eraseLines } from '@inquirer/ansi';
4
- const height = (content) => content.split('\n').length;
5
- const lastLine = (content) => content.split('\n').pop() ?? '';
6
- export default class ScreenManager {
7
- // These variables are keeping information to allow correct prompt re-rendering
8
- height = 0;
9
- extraLinesUnderPrompt = 0;
10
- cursorPos;
11
- rl;
12
- constructor(rl) {
13
- this.rl = rl;
14
- this.cursorPos = rl.getCursorPos();
15
- }
16
- write(content) {
17
- this.rl.output.unmute();
18
- this.rl.output.write(content);
19
- this.rl.output.mute();
20
- }
21
- render(content, bottomContent = '') {
22
- // Write message to screen and setPrompt to control backspace
23
- const promptLine = lastLine(content);
24
- const rawPromptLine = stripVTControlCharacters(promptLine);
25
- // Remove the rl.line from our prompt. We can't rely on the content of
26
- // rl.line (mainly because of the password prompt), so just rely on it's
27
- // length.
28
- let prompt = rawPromptLine;
29
- if (this.rl.line.length > 0) {
30
- prompt = prompt.slice(0, -this.rl.line.length);
31
- }
32
- this.rl.setPrompt(prompt);
33
- // SetPrompt will change cursor position, now we can get correct value
34
- this.cursorPos = this.rl.getCursorPos();
35
- const width = readlineWidth();
36
- content = breakLines(content, width);
37
- bottomContent = breakLines(bottomContent, width);
38
- // Manually insert an extra line if we're at the end of the line.
39
- // This prevent the cursor from appearing at the beginning of the
40
- // current line.
41
- if (rawPromptLine.length % width === 0) {
42
- content += '\n';
43
- }
44
- let output = content + (bottomContent ? '\n' + bottomContent : '');
45
- /**
46
- * Re-adjust the cursor at the correct position.
47
- */
48
- // We need to consider parts of the prompt under the cursor as part of the bottom
49
- // content in order to correctly cleanup and re-render.
50
- const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - this.cursorPos.rows;
51
- const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
52
- // Return cursor to the input position (on top of the bottomContent)
53
- if (bottomContentHeight > 0)
54
- output += cursorUp(bottomContentHeight);
55
- // Return cursor to the initial left offset.
56
- output += cursorTo(this.cursorPos.cols);
57
- /**
58
- * Render and store state for future re-rendering
59
- */
60
- this.write(cursorDown(this.extraLinesUnderPrompt) + eraseLines(this.height) + output);
61
- this.extraLinesUnderPrompt = bottomContentHeight;
62
- this.height = height(output);
63
- }
64
- checkCursorPos() {
65
- const cursorPos = this.rl.getCursorPos();
66
- if (cursorPos.cols !== this.cursorPos.cols) {
67
- this.write(cursorTo(cursorPos.cols));
68
- this.cursorPos = cursorPos;
69
- }
70
- }
71
- done({ clearContent }) {
72
- this.rl.setPrompt('');
73
- let output = cursorDown(this.extraLinesUnderPrompt);
74
- output += clearContent ? eraseLines(this.height) : '\n';
75
- output += cursorShow;
76
- this.write(output);
77
- this.rl.close();
78
- }
79
- }
@@ -1,155 +0,0 @@
1
- import type { Prettify } from '@inquirer/type';
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
- export type Status = 'loading' | 'idle' | 'done' | (string & {});
12
- 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[];
54
- };
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;
151
- };
152
- };
153
- export type Theme<Extension extends object = object> = Prettify<Extension & DefaultTheme>;
154
- export declare const defaultTheme: DefaultTheme;
155
- export {};
@@ -1,21 +0,0 @@
1
- import colors from 'yoctocolors-cjs';
2
- import figures from '@inquirer/figures';
3
- export const defaultTheme = {
4
- prefix: {
5
- idle: colors.blue('?'),
6
- done: colors.green(figures.tick),
7
- },
8
- spinner: {
9
- interval: 80,
10
- frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'].map((frame) => colors.yellow(frame)),
11
- },
12
- style: {
13
- answer: colors.cyan,
14
- message: colors.bold,
15
- error: (text) => colors.red(`> ${text}`),
16
- defaultAnswer: (text) => colors.dim(`(${text})`),
17
- help: colors.dim,
18
- highlight: colors.cyan,
19
- key: (text) => colors.cyan(colors.bold(`<${text}>`)),
20
- },
21
- };
@@ -1,2 +0,0 @@
1
- import type { InquirerReadline } from '@inquirer/type';
2
- export declare function useEffect(cb: (rl: InquirerReadline) => void | (() => void), depArray: ReadonlyArray<unknown>): void;
@@ -1,11 +0,0 @@
1
- import { withPointer, effectScheduler } from "./hook-engine.js";
2
- export function useEffect(cb, depArray) {
3
- withPointer((pointer) => {
4
- const oldDeps = pointer.get();
5
- const hasChanged = !Array.isArray(oldDeps) || depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
6
- if (hasChanged) {
7
- effectScheduler.queue(cb);
8
- }
9
- pointer.set(depArray);
10
- });
11
- }
@@ -1,3 +0,0 @@
1
- import { type InquirerReadline } from '@inquirer/type';
2
- import { type KeypressEvent } from './key.ts';
3
- export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void | Promise<void>): void;
@@ -1,20 +0,0 @@
1
- import { useRef } from "./use-ref.js";
2
- import { useEffect } from "./use-effect.js";
3
- import { withUpdates } from "./hook-engine.js";
4
- export function useKeypress(userHandler) {
5
- const signal = useRef(userHandler);
6
- signal.current = userHandler;
7
- useEffect((rl) => {
8
- let ignore = false;
9
- const handler = withUpdates((_input, event) => {
10
- if (ignore)
11
- return;
12
- void signal.current(event, rl);
13
- });
14
- rl.input.on('keypress', handler);
15
- return () => {
16
- ignore = true;
17
- rl.input.removeListener('keypress', handler);
18
- };
19
- }, []);
20
- }
@@ -1 +0,0 @@
1
- export declare function useMemo<Value>(fn: () => Value, dependencies: ReadonlyArray<unknown>): Value;
@@ -1,14 +0,0 @@
1
- import { withPointer } from "./hook-engine.js";
2
- export function useMemo(fn, dependencies) {
3
- return withPointer((pointer) => {
4
- const prev = pointer.get();
5
- if (!prev ||
6
- prev.dependencies.length !== dependencies.length ||
7
- prev.dependencies.some((dep, i) => dep !== dependencies[i])) {
8
- const value = fn();
9
- pointer.set({ value, dependencies });
10
- return value;
11
- }
12
- return prev.value;
13
- });
14
- }
@@ -1,5 +0,0 @@
1
- import type { Theme, Status } from './theme.ts';
2
- export declare function usePrefix({ status, theme, }: {
3
- status?: Status;
4
- theme?: Theme;
5
- }): string;
@@ -1,35 +0,0 @@
1
- import { useState } from "./use-state.js";
2
- import { useEffect } from "./use-effect.js";
3
- import { makeTheme } from "./make-theme.js";
4
- export function usePrefix({ status = 'idle', theme, }) {
5
- const [showLoader, setShowLoader] = useState(false);
6
- const [tick, setTick] = useState(0);
7
- const { prefix, spinner } = makeTheme(theme);
8
- useEffect(() => {
9
- if (status === 'loading') {
10
- let tickInterval;
11
- let inc = -1;
12
- // Delay displaying spinner by 300ms, to avoid flickering
13
- const delayTimeout = setTimeout(() => {
14
- setShowLoader(true);
15
- tickInterval = setInterval(() => {
16
- inc = inc + 1;
17
- setTick(inc % spinner.frames.length);
18
- }, spinner.interval);
19
- }, 300);
20
- return () => {
21
- clearTimeout(delayTimeout);
22
- clearInterval(tickInterval);
23
- };
24
- }
25
- else {
26
- setShowLoader(false);
27
- }
28
- }, [status]);
29
- if (showLoader) {
30
- return spinner.frames[tick];
31
- }
32
- // There's a delay before we show the loader. So we want to ignore `loading` here, and pass idle instead.
33
- const iconName = status === 'loading' ? 'idle' : status;
34
- return typeof prefix === 'string' ? prefix : (prefix[iconName] ?? prefix['idle']);
35
- }
@@ -1,6 +0,0 @@
1
- export declare function useRef<Value>(val: Value): {
2
- current: Value;
3
- };
4
- export declare function useRef<Value>(val?: Value): {
5
- current: Value | undefined;
6
- };
@@ -1,4 +0,0 @@
1
- import { useState } from "./use-state.js";
2
- export function useRef(val) {
3
- return useState({ current: val })[0];
4
- }
@@ -1,4 +0,0 @@
1
- type NotFunction<T> = T extends (...args: never) => unknown ? never : T;
2
- export declare function useState<Value>(defaultValue: NotFunction<Value> | (() => Value)): [Value, (newValue: Value) => void];
3
- export declare function useState<Value>(defaultValue?: NotFunction<Value> | (() => Value)): [Value | undefined, (newValue?: Value) => void];
4
- export {};
@@ -1,20 +0,0 @@
1
- import { AsyncResource } from 'node:async_hooks';
2
- import { withPointer, handleChange } from "./hook-engine.js";
3
- export function useState(defaultValue) {
4
- return withPointer((pointer) => {
5
- const setState = AsyncResource.bind(function setState(newValue) {
6
- // Noop if the value is still the same.
7
- if (pointer.get() !== newValue) {
8
- pointer.set(newValue);
9
- // Trigger re-render
10
- handleChange();
11
- }
12
- });
13
- if (pointer.initialized) {
14
- return [pointer.get(), setState];
15
- }
16
- const value = typeof defaultValue === 'function' ? defaultValue() : defaultValue;
17
- pointer.set(value);
18
- return [value, setState];
19
- });
20
- }
@@ -1,13 +0,0 @@
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
- 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
- export declare function readlineWidth(): number;
@@ -1,25 +0,0 @@
1
- import cliWidth from 'cli-width';
2
- import wrapAnsi from 'wrap-ansi';
3
- import { readline } from "./hook-engine.js";
4
- /**
5
- * Force line returns at specific width. This function is ANSI code friendly and it'll
6
- * ignore invisible codes during width calculation.
7
- * @param {string} content
8
- * @param {number} width
9
- * @return {string}
10
- */
11
- export function breakLines(content, width) {
12
- return content
13
- .split('\n')
14
- .flatMap((line) => wrapAnsi(line, width, { trim: false, hard: true })
15
- .split('\n')
16
- .map((str) => str.trimEnd()))
17
- .join('\n');
18
- }
19
- /**
20
- * Returns the width of the active readline, or 80 as default value.
21
- * @returns {number}
22
- */
23
- export function readlineWidth() {
24
- return cliWidth({ defaultWidth: 80, output: readline().output });
25
- }
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }