@inquirer/core 0.0.19-alpha.0 → 0.0.22-alpha.0

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.
@@ -0,0 +1,34 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ import readline from 'node:readline';
4
+ import MuteStream from 'mute-stream';
5
+ export { usePrefix } from './lib/prefix.js';
6
+ export * from './lib/key.js';
7
+ export * from './lib/Paginator.js';
8
+ declare type StdioOptions = {
9
+ input?: NodeJS.ReadableStream;
10
+ output?: NodeJS.WritableStream;
11
+ };
12
+ export declare type InquirerReadline = readline.ReadLine & {
13
+ output: MuteStream;
14
+ input: NodeJS.ReadableStream;
15
+ };
16
+ export declare type KeypressEvent = {
17
+ name: string;
18
+ ctrl: boolean;
19
+ };
20
+ export declare function useState<Value>(defaultValue: Value): [Value, (newValue: Value) => void];
21
+ export declare function useEffect(cb: () => void | (() => void), depArray: unknown[]): void;
22
+ export declare function useKeypress(userHandler: (event: KeypressEvent, rl: InquirerReadline) => void): void;
23
+ export declare function useRef<Value>(val: Value): {
24
+ current: Value;
25
+ };
26
+ export declare type AsyncPromptConfig = {
27
+ message: string | Promise<string> | (() => Promise<string>);
28
+ validate?: (value: string) => boolean | string | Promise<string | boolean>;
29
+ };
30
+ export declare type ResolvedPromptConfig = {
31
+ message: string;
32
+ validate: (value: string) => boolean | string | Promise<string | boolean>;
33
+ };
34
+ export declare function createPrompt<Value, Config extends AsyncPromptConfig>(view: (config: Config & ResolvedPromptConfig, done: (value: Value) => void) => string | [string, string | undefined]): (options: Config, stdio?: StdioOptions) => Promise<Value>;
package/dist/index.js ADDED
@@ -0,0 +1,105 @@
1
+ import readline from 'node:readline';
2
+ import MuteStream from 'mute-stream';
3
+ import ScreenManager from './lib/screen-manager.js';
4
+ import { getPromptConfig } from './lib/options.js';
5
+ export { usePrefix } from './lib/prefix.js';
6
+ export * from './lib/key.js';
7
+ export * from './lib/Paginator.js';
8
+ let sessionRl;
9
+ let hooks = [];
10
+ const hooksCleanup = [];
11
+ let index = 0;
12
+ let handleChange = () => { };
13
+ const cleanupHook = (index) => {
14
+ const cleanFn = hooksCleanup[index];
15
+ if (typeof cleanFn === 'function') {
16
+ cleanFn();
17
+ }
18
+ };
19
+ export function useState(defaultValue) {
20
+ const _idx = index;
21
+ const value = _idx in hooks ? hooks[_idx] : defaultValue;
22
+ index++;
23
+ return [
24
+ value,
25
+ (newValue) => {
26
+ hooks[_idx] = newValue;
27
+ // Trigger re-render
28
+ handleChange();
29
+ },
30
+ ];
31
+ }
32
+ export function useEffect(cb, depArray) {
33
+ const _idx = index;
34
+ const oldDeps = hooks[_idx];
35
+ let hasChanged = true;
36
+ if (oldDeps) {
37
+ hasChanged = depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
38
+ }
39
+ if (hasChanged) {
40
+ cleanupHook(_idx);
41
+ hooksCleanup[_idx] = cb();
42
+ }
43
+ hooks[_idx] = depArray;
44
+ index++;
45
+ }
46
+ export function useKeypress(userHandler) {
47
+ const rl = sessionRl;
48
+ if (!rl) {
49
+ throw new Error('useKeypress must be used within a prompt');
50
+ }
51
+ useEffect(() => {
52
+ const handler = (_input, event) => {
53
+ userHandler(event, rl);
54
+ };
55
+ rl.input.on('keypress', handler);
56
+ return () => {
57
+ rl.input.removeListener('keypress', handler);
58
+ };
59
+ }, [userHandler]);
60
+ }
61
+ export function useRef(val) {
62
+ return useState({ current: val })[0];
63
+ }
64
+ export function createPrompt(view) {
65
+ return async function (options, stdio) {
66
+ // Default `input` to stdin
67
+ const input = stdio?.input ?? process.stdin;
68
+ // Add mute capabilities to the output
69
+ const output = new MuteStream();
70
+ output.pipe(stdio?.output ?? process.stdout);
71
+ const rl = readline.createInterface({
72
+ terminal: true,
73
+ input,
74
+ output,
75
+ });
76
+ const screen = new ScreenManager(rl);
77
+ // TODO: we should display a loader while we get the default options.
78
+ const resolvedConfig = await getPromptConfig(options);
79
+ return new Promise((resolve) => {
80
+ const done = (value) => {
81
+ let len = cleanupHook.length;
82
+ while (len--) {
83
+ cleanupHook(len);
84
+ }
85
+ screen.done();
86
+ // Reset hooks state
87
+ hooks = [];
88
+ index = 0;
89
+ sessionRl = undefined;
90
+ // Finally we resolve our promise
91
+ resolve(value);
92
+ };
93
+ hooks = [];
94
+ const workLoop = (config) => {
95
+ sessionRl = rl;
96
+ index = 0;
97
+ handleChange = () => workLoop(config);
98
+ const nextView = view(config, done);
99
+ const [content, bottomContent] = typeof nextView === 'string' ? [nextView] : nextView;
100
+ screen.render(content, bottomContent);
101
+ };
102
+ workLoop(resolvedConfig);
103
+ });
104
+ };
105
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The paginator keeps track of a pointer index in a list and returns
3
+ * a subset of the choices if the list is too long.
4
+ */
5
+ export declare class Paginator {
6
+ pointer: number;
7
+ lastIndex: number;
8
+ paginate(output: string, active: number, pageSize?: number): string;
9
+ }
@@ -0,0 +1,46 @@
1
+ import chalk from 'chalk';
2
+ import cliWidth from 'cli-width';
3
+ import { breakLines } from './utils.js';
4
+ /**
5
+ * The paginator keeps track of a pointer index in a list and returns
6
+ * a subset of the choices if the list is too long.
7
+ */
8
+ export class Paginator {
9
+ constructor() {
10
+ Object.defineProperty(this, "pointer", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: 0
15
+ });
16
+ Object.defineProperty(this, "lastIndex", {
17
+ enumerable: true,
18
+ configurable: true,
19
+ writable: true,
20
+ value: 0
21
+ });
22
+ }
23
+ paginate(output, active, pageSize = 7) {
24
+ const middleOfList = Math.floor(pageSize / 2);
25
+ // TODO: I've remove the dependency on readline here. But we should refactor the
26
+ // paginator to also rely on hook.
27
+ const width = cliWidth({ defaultWidth: 80, output: process.stdout });
28
+ const lines = breakLines(output, width).split('\n');
29
+ // Make sure there's enough lines to paginate
30
+ if (lines.length <= pageSize) {
31
+ return output;
32
+ }
33
+ // Move the pointer only when the user go down and limit it to the middle of the list
34
+ if (this.pointer < middleOfList &&
35
+ this.lastIndex < active &&
36
+ active - this.lastIndex < pageSize) {
37
+ this.pointer = Math.min(middleOfList, this.pointer + active - this.lastIndex);
38
+ }
39
+ this.lastIndex = active;
40
+ // Duplicate the lines so it give an infinite list look
41
+ const infinite = [lines, lines, lines].flat();
42
+ const topIndex = Math.max(0, active + lines.length - this.pointer);
43
+ const section = infinite.splice(topIndex, pageSize).join('\n');
44
+ return section + '\n' + chalk.dim('(Move up and down to reveal more choices)');
45
+ }
46
+ }
@@ -0,0 +1,11 @@
1
+ declare type KeypressEvent = {
2
+ name: string;
3
+ ctrl: boolean;
4
+ };
5
+ export declare const isUpKey: (key: KeypressEvent) => boolean;
6
+ export declare const isDownKey: (key: KeypressEvent) => boolean;
7
+ export declare const isSpaceKey: (key: KeypressEvent) => boolean;
8
+ export declare const isBackspaceKey: (key: KeypressEvent) => boolean;
9
+ export declare const isNumberKey: (key: KeypressEvent) => boolean;
10
+ export declare const isEnterKey: (key: KeypressEvent) => boolean;
11
+ export {};
@@ -0,0 +1,6 @@
1
+ export const isUpKey = (key) => key.name === 'up' || key.name === 'k' || (key.name === 'p' && key.ctrl);
2
+ export const isDownKey = (key) => key.name === 'down' || key.name === 'j' || (key.name === 'n' && key.ctrl);
3
+ export const isSpaceKey = (key) => key.name === 'space';
4
+ export const isBackspaceKey = (key) => key.name === 'backspace';
5
+ export const isNumberKey = (key) => '123456789'.includes(key.name);
6
+ export const isEnterKey = (key) => key.name === 'enter' || key.name === 'return';
@@ -0,0 +1,2 @@
1
+ import type { AsyncPromptConfig, ResolvedPromptConfig } from '../index.js';
2
+ export declare function getPromptConfig<In extends AsyncPromptConfig>(option: In): Promise<In & ResolvedPromptConfig>;
@@ -0,0 +1,8 @@
1
+ export async function getPromptConfig(option) {
2
+ const message = typeof option.message === 'function' ? option.message() : option.message;
3
+ return {
4
+ validate: () => true,
5
+ ...option,
6
+ message: await message,
7
+ };
8
+ }
@@ -0,0 +1 @@
1
+ export declare function usePrefix(isLoading?: boolean): string;
@@ -0,0 +1,20 @@
1
+ import chalk from 'chalk';
2
+ import spinners from 'cli-spinners';
3
+ import { useState, useEffect } from '../index.js';
4
+ const spinner = spinners.dots;
5
+ export function usePrefix(isLoading = false) {
6
+ const [tick, setTick] = useState(0);
7
+ useEffect(() => {
8
+ if (isLoading) {
9
+ const timeout = setTimeout(() => {
10
+ setTick(tick + 1);
11
+ }, spinner.interval);
12
+ return () => clearTimeout(timeout);
13
+ }
14
+ }, [isLoading, tick]);
15
+ if (isLoading) {
16
+ const frame = tick % spinner.frames.length;
17
+ return chalk.yellow(spinner.frames[frame]);
18
+ }
19
+ return chalk.green('?');
20
+ }
@@ -1,50 +1,31 @@
1
- const ansiEscapes = require('ansi-escapes');
2
-
1
+ import type { InquirerReadline } from '../index.js';
3
2
  /**
4
3
  * Move cursor left by `x`
5
4
  * @param {Readline} rl - Readline instance
6
5
  * @param {Number} x - How far to go left (default to 1)
7
6
  */
8
-
9
- exports.left = function (rl, x) {
10
- rl.output.write(ansiEscapes.cursorBackward(x));
11
- };
12
-
7
+ export declare function left(rl: InquirerReadline, x: number): void;
13
8
  /**
14
9
  * Move cursor right by `x`
15
10
  * @param {Readline} rl - Readline instance
16
11
  * @param {Number} x - How far to go left (default to 1)
17
12
  */
18
-
19
- exports.right = function (rl, x) {
20
- rl.output.write(ansiEscapes.cursorForward(x));
21
- };
22
-
13
+ export declare function right(rl: InquirerReadline, x: number): void;
23
14
  /**
24
15
  * Move cursor up by `x`
25
16
  * @param {Readline} rl - Readline instance
26
17
  * @param {Number} x - How far to go up (default to 1)
27
18
  */
28
-
29
- exports.up = function (rl, x) {
30
- rl.output.write(ansiEscapes.cursorUp(x));
31
- };
32
-
19
+ export declare function up(rl: InquirerReadline, x: number): void;
33
20
  /**
34
21
  * Move cursor down by `x`
35
22
  * @param {Readline} rl - Readline instance
36
23
  * @param {Number} x - How far to go down (default to 1)
37
24
  */
38
-
39
- exports.down = function (rl, x) {
40
- rl.output.write(ansiEscapes.cursorDown(x));
41
- };
42
-
25
+ export declare function down(rl: InquirerReadline, x: number): void;
43
26
  /**
44
27
  * Clear current line
45
28
  * @param {Readline} rl - Readline instance
46
29
  * @param {Number} len - number of line to delete
47
30
  */
48
- exports.clearLine = function (rl, len) {
49
- rl.output.write(ansiEscapes.eraseLines(len));
50
- };
31
+ export declare function clearLine(rl: InquirerReadline, len: number): void;
@@ -0,0 +1,49 @@
1
+ import ansiEscapes from 'ansi-escapes';
2
+ /**
3
+ * Move cursor left by `x`
4
+ * @param {Readline} rl - Readline instance
5
+ * @param {Number} x - How far to go left (default to 1)
6
+ */
7
+ export function left(rl, x) {
8
+ if (x > 0) {
9
+ rl.output.write(ansiEscapes.cursorBackward(x));
10
+ }
11
+ }
12
+ /**
13
+ * Move cursor right by `x`
14
+ * @param {Readline} rl - Readline instance
15
+ * @param {Number} x - How far to go left (default to 1)
16
+ */
17
+ export function right(rl, x) {
18
+ if (x > 0) {
19
+ rl.output.write(ansiEscapes.cursorForward(x));
20
+ }
21
+ }
22
+ /**
23
+ * Move cursor up by `x`
24
+ * @param {Readline} rl - Readline instance
25
+ * @param {Number} x - How far to go up (default to 1)
26
+ */
27
+ export function up(rl, x) {
28
+ if (x > 0) {
29
+ rl.output.write(ansiEscapes.cursorUp(x));
30
+ }
31
+ }
32
+ /**
33
+ * Move cursor down by `x`
34
+ * @param {Readline} rl - Readline instance
35
+ * @param {Number} x - How far to go down (default to 1)
36
+ */
37
+ export function down(rl, x) {
38
+ if (x > 0) {
39
+ rl.output.write(ansiEscapes.cursorDown(x));
40
+ }
41
+ }
42
+ /**
43
+ * Clear current line
44
+ * @param {Readline} rl - Readline instance
45
+ * @param {Number} len - number of line to delete
46
+ */
47
+ export function clearLine(rl, len) {
48
+ rl.output.write(ansiEscapes.eraseLines(len));
49
+ }
@@ -0,0 +1,10 @@
1
+ import { InquirerReadline } from '../index.js';
2
+ export default class ScreenManager {
3
+ private readonly rl;
4
+ private height;
5
+ private extraLinesUnderPrompt;
6
+ constructor(rl: InquirerReadline);
7
+ render(content: string, bottomContent?: string): void;
8
+ clean(extraLines: number): void;
9
+ done(): void;
10
+ }
@@ -0,0 +1,93 @@
1
+ import cliWidth from 'cli-width';
2
+ import stripAnsi from 'strip-ansi';
3
+ import stringWidth from 'string-width';
4
+ import ansiEscapes from 'ansi-escapes';
5
+ import * as util from './readline.js';
6
+ import { breakLines } from './utils.js';
7
+ const height = (content) => content.split('\n').length;
8
+ const lastLine = (content) => content.split('\n').pop() ?? '';
9
+ export default class ScreenManager {
10
+ constructor(rl) {
11
+ Object.defineProperty(this, "rl", {
12
+ enumerable: true,
13
+ configurable: true,
14
+ writable: true,
15
+ value: rl
16
+ });
17
+ // These variables are keeping information to allow correct prompt re-rendering
18
+ Object.defineProperty(this, "height", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: 0
23
+ });
24
+ Object.defineProperty(this, "extraLinesUnderPrompt", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: 0
29
+ });
30
+ this.rl = rl;
31
+ }
32
+ render(content, bottomContent = '') {
33
+ this.rl.output.unmute();
34
+ this.clean(this.extraLinesUnderPrompt);
35
+ /**
36
+ * Write message to screen and setPrompt to control backspace
37
+ */
38
+ const promptLine = lastLine(content);
39
+ const rawPromptLine = stripAnsi(promptLine);
40
+ // Remove the rl.line from our prompt. We can't rely on the content of
41
+ // rl.line (mainly because of the password prompt), so just rely on it's
42
+ // length.
43
+ let prompt = rawPromptLine;
44
+ if (this.rl.line.length) {
45
+ prompt = prompt.slice(0, -this.rl.line.length);
46
+ }
47
+ this.rl.setPrompt(prompt);
48
+ // SetPrompt will change cursor position, now we can get correct value
49
+ const cursorPos = this.rl._getCursorPos();
50
+ const width = cliWidth({ defaultWidth: 80, output: this.rl.output });
51
+ content = breakLines(content, width);
52
+ bottomContent = breakLines(bottomContent, width);
53
+ // Manually insert an extra line if we're at the end of the line.
54
+ // This prevent the cursor from appearing at the beginning of the
55
+ // current line.
56
+ if (rawPromptLine.length % width === 0) {
57
+ content += '\n';
58
+ }
59
+ const fullContent = content + (bottomContent ? '\n' + bottomContent : '');
60
+ this.rl.output.write(fullContent);
61
+ /**
62
+ * Re-adjust the cursor at the correct position.
63
+ */
64
+ // We need to consider parts of the prompt under the cursor as part of the bottom
65
+ // content in order to correctly cleanup and re-render.
66
+ const promptLineUpDiff = Math.floor(rawPromptLine.length / width) - cursorPos.rows;
67
+ const bottomContentHeight = promptLineUpDiff + (bottomContent ? height(bottomContent) : 0);
68
+ // Return cursor to the input position (on top of the bottomContent)
69
+ util.up(this.rl, bottomContentHeight);
70
+ // Move cursor at the start of the line, then return to the initial left offset.
71
+ util.left(this.rl, stringWidth(lastLine(fullContent)));
72
+ util.right(this.rl, cursorPos.cols);
73
+ /**
74
+ * Set up state for next re-rendering
75
+ */
76
+ this.extraLinesUnderPrompt = bottomContentHeight;
77
+ this.height = height(fullContent);
78
+ this.rl.output.mute();
79
+ }
80
+ clean(extraLines) {
81
+ util.down(this.rl, extraLines);
82
+ util.clearLine(this.rl, this.height);
83
+ }
84
+ done() {
85
+ // Reset the cursor at the end of the previously displayed content
86
+ util.down(this.rl, this.extraLinesUnderPrompt);
87
+ this.rl.setPrompt('');
88
+ this.rl.output.unmute();
89
+ this.rl.output.write('\n');
90
+ this.rl.output.write(ansiEscapes.cursorShow);
91
+ this.rl.close();
92
+ }
93
+ }
@@ -0,0 +1,8 @@
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 const breakLines: (content: string, width: number) => string;
@@ -1,5 +1,4 @@
1
- const wrapAnsi = require('wrap-ansi');
2
-
1
+ import wrapAnsi from 'wrap-ansi';
3
2
  /**
4
3
  * Force line returns at specific width. This function is ANSI code friendly and it'll
5
4
  * ignore invisible codes during width calculation.
@@ -7,8 +6,8 @@ const wrapAnsi = require('wrap-ansi');
7
6
  * @param {number} width
8
7
  * @return {string}
9
8
  */
10
- exports.breakLines = (content, width) =>
11
- content
9
+ export const breakLines = (content, width) => content
12
10
  .split('\n')
13
- .map((line) => wrapAnsi(line, width, { trim: false, hard: true }))
11
+ // @ts-expect-error broken type check from library
12
+ .map((line) => wrapAnsi(line, width, { trim: false, hard: true }).split('\n'))
14
13
  .join('\n');
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "0.0.19-alpha.0",
3
+ "type": "module",
4
+ "version": "0.0.22-alpha.0",
4
5
  "description": "Core Inquirer prompt API",
5
- "main": "index.js",
6
+ "main": "dist/index.js",
7
+ "typings": "dist/index.d.ts",
8
+ "files": [
9
+ "dist/"
10
+ ],
6
11
  "repository": "SBoudrias/Inquirer.js",
7
12
  "keywords": [
8
13
  "cli",
@@ -13,19 +18,22 @@
13
18
  "author": "Simon Boudrias",
14
19
  "license": "MIT",
15
20
  "dependencies": {
16
- "ansi-escapes": "^4.2.1",
17
- "chalk": "^4.1.1",
21
+ "ansi-escapes": "^5.0.0",
22
+ "chalk": "^5.0.1",
18
23
  "cli-spinners": "^2.6.1",
19
- "cli-width": "^3.0.0",
24
+ "cli-width": "^4.0.0",
20
25
  "lodash": "^4.17.21",
21
26
  "mute-stream": "^0.0.8",
22
27
  "run-async": "^2.3.0",
23
- "string-width": "^4.1.0",
24
- "strip-ansi": "^6.0.0",
25
- "wrap-ansi": "^7.0.0"
28
+ "string-width": "^5.1.2",
29
+ "strip-ansi": "^7.0.1",
30
+ "wrap-ansi": "^8.0.1"
31
+ },
32
+ "scripts": {
33
+ "tsc": "tsc"
26
34
  },
27
35
  "publishConfig": {
28
36
  "access": "public"
29
37
  },
30
- "gitHead": "9baee326b04b4e8565e815b1fa577c36e0b93727"
38
+ "gitHead": "1d5e7e3d15c86851f2e5df2bb9f55084ba231c54"
31
39
  }
package/hooks.js DELETED
@@ -1,119 +0,0 @@
1
- const readline = require('readline');
2
- const MuteStream = require('mute-stream');
3
- const ScreenManager = require('./lib/screen-manager');
4
- const { getPromptConfig } = require('./lib/options');
5
-
6
- let sessionRl;
7
- let hooks = [];
8
- const hooksCleanup = [];
9
- let index = 0;
10
- let handleChange = () => {};
11
-
12
- const cleanupHook = (index) => {
13
- const cleanFn = hooksCleanup[index];
14
- if (typeof cleanFn === 'function') {
15
- cleanFn();
16
- }
17
- };
18
-
19
- exports.useState = (defaultValue) => {
20
- const _idx = index;
21
- const value = _idx in hooks ? hooks[_idx] : defaultValue;
22
-
23
- index++;
24
-
25
- return [
26
- value,
27
- (newValue) => {
28
- hooks[_idx] = newValue;
29
-
30
- // Trigger re-render
31
- handleChange();
32
- },
33
- ];
34
- };
35
-
36
- exports.useKeypress = (userHandler) => {
37
- const _idx = index;
38
- const prevHandler = hooks[_idx];
39
- const handler = (input, event) => {
40
- userHandler(event, sessionRl);
41
- };
42
-
43
- if (prevHandler !== handler) {
44
- cleanupHook(_idx);
45
-
46
- sessionRl.input.on('keypress', handler);
47
- hooks[_idx] = handler;
48
- hooksCleanup[_idx] = () => {
49
- sessionRl.input.removeListener('keypress', handler);
50
- };
51
- }
52
-
53
- index++;
54
- };
55
-
56
- exports.useEffect = (cb, depArray) => {
57
- const _idx = index;
58
-
59
- const oldDeps = hooks[_idx];
60
- let hasChanged = true;
61
- if (oldDeps) {
62
- hasChanged = depArray.some((dep, i) => !Object.is(dep, oldDeps[i]));
63
- }
64
- if (hasChanged) {
65
- cleanupHook(_idx);
66
- hooksCleanup[_idx] = cb();
67
- }
68
- hooks[_idx] = depArray;
69
-
70
- index++;
71
- };
72
-
73
- exports.useRef = (val) => exports.useState({ current: val })[0];
74
-
75
- exports.createPrompt = (view) => (options) => {
76
- // Default `input` to stdin
77
- const input = process.stdin;
78
-
79
- // Add mute capabilities to the output
80
- const output = new MuteStream();
81
- output.pipe(process.stdout);
82
-
83
- const rl = readline.createInterface({
84
- terminal: true,
85
- input,
86
- output,
87
- });
88
- const screen = new ScreenManager(rl);
89
-
90
- return new Promise((resolve, reject) => {
91
- sessionRl = rl;
92
-
93
- const done = (value) => {
94
- let len = cleanupHook.length;
95
- while (len--) {
96
- cleanupHook(len);
97
- }
98
- screen.done();
99
-
100
- // Reset hooks state
101
- hooks = [];
102
- index = 0;
103
- sessionRl = undefined;
104
-
105
- // Finally we resolve our promise
106
- resolve(value);
107
- };
108
-
109
- hooks = [];
110
- const workLoop = (config) => {
111
- index = 0;
112
- handleChange = () => workLoop(config);
113
- screen.render(...[view(config, done)].flat().filter(Boolean));
114
- };
115
-
116
- // TODO: we should display a loader while we get the default options.
117
- getPromptConfig(options).then(workLoop, reject);
118
- });
119
- };