@@ -6,36 +6,12 @@ import ScreenManager from './screen-manager.mjs';
6
6
import type { InquirerReadline } from './read-line.type.mjs' ;
7
7
import { withHooks , effectScheduler } from './hook-engine.mjs' ;
8
8
9
- // @deprecated Prefer using `PromptConfig<{ ... }>` instead
10
- export type AsyncPromptConfig = {
11
- message : string | Promise < string > | ( ( ) => Promise < string > ) ;
12
- } ;
13
-
14
- export type PromptConfig < Config > = Prettify < AsyncPromptConfig & Config > ;
15
-
16
- type ResolvedPromptConfig = { message : string } ;
17
-
18
9
type ViewFunction < Value , Config > = (
19
- config : Prettify < Config & ResolvedPromptConfig > ,
10
+ config : Prettify < Config > ,
20
11
done : ( value : Value ) => void ,
21
12
) => string | [ string , string | undefined ] ;
22
13
23
- // Take an AsyncPromptConfig and resolves all it's values.
24
- async function getPromptConfig < Config extends AsyncPromptConfig > (
25
- config : Config ,
26
- ) : Promise < Config & ResolvedPromptConfig > {
27
- const message =
28
- typeof config . message === 'function' ? config . message ( ) : config . message ;
29
-
30
- return {
31
- ...config ,
32
- message : await message ,
33
- } ;
34
- }
35
-
36
- export function createPrompt < Value , Config extends AsyncPromptConfig > (
37
- view : ViewFunction < Value , Config > ,
38
- ) {
14
+ export function createPrompt < Value , Config > ( view : ViewFunction < Value , Config > ) {
39
15
const prompt : Prompt < Value , Config > = ( config , context ) => {
40
16
// Default `input` to stdin
41
17
const input = context ?. input ?? process . stdin ;
@@ -98,12 +74,12 @@ export function createPrompt<Value, Config extends AsyncPromptConfig>(
98
74
} ) ;
99
75
}
100
76
101
- function workLoop ( resolvedConfig : Config & ResolvedPromptConfig ) {
77
+ function workLoop ( resolvedConfig : Config ) {
102
78
store . index = 0 ;
103
79
store . handleChange = ( ) => workLoop ( resolvedConfig ) ;
104
80
105
81
try {
106
- const nextView = view ( resolvedConfig , done ) ;
82
+ const nextView = view ( config , done ) ;
107
83
108
84
const [ content , bottomContent ] =
109
85
typeof nextView === 'string' ? [ nextView ] : nextView ;
@@ -116,16 +92,13 @@ export function createPrompt<Value, Config extends AsyncPromptConfig>(
116
92
}
117
93
}
118
94
119
- // TODO: we should display a loader while we get the default options.
120
- getPromptConfig ( config ) . then ( ( resolvedConfig ) => {
121
- workLoop ( resolvedConfig ) ;
95
+ workLoop ( config ) ;
122
96
123
- // Re-renders only happen when the state change; but the readline cursor could change position
124
- // and that also requires a re-render (and a manual one because we mute the streams).
125
- // We set the listener after the initial workLoop to avoid a double render if render triggered
126
- // by a state change sets the cursor to the right position.
127
- store . rl . input . on ( 'keypress' , checkCursorPos ) ;
128
- } , reject ) ;
97
+ // Re-renders only happen when the state change; but the readline cursor could change position
98
+ // and that also requires a re-render (and a manual one because we mute the streams).
99
+ // We set the listener after the initial workLoop to avoid a double render if render triggered
100
+ // by a state change sets the cursor to the right position.
101
+ store . rl . input . on ( 'keypress' , checkCursorPos ) ;
129
102
} ) ;
130
103
} ) ;
131
104
0 commit comments