1
- import * as prompt from "inquirer " ;
1
+ import * as prompt from "prompts " ;
2
2
import * as helpers from "./helpers" ;
3
3
import * as readline from "readline" ;
4
4
import { ReadStream } from "tty" ;
5
- import { IAllowEmpty , IPrompterOptions } from "./declarations" ;
5
+ import {
6
+ IAllowEmpty ,
7
+ IPrompterAnswers ,
8
+ IPrompterOptions ,
9
+ IPrompterQuestion ,
10
+ } from "./declarations" ;
6
11
import { injector } from "./yok" ;
7
12
const MuteStream = require ( "mute-stream" ) ;
8
13
import * as _ from "lodash" ;
9
14
10
15
export class Prompter implements IPrompter {
11
- private descriptionSeparator = "|" ;
12
16
private ctrlcReader : readline . ReadLine ;
13
17
private muteStreamInstance : any = null ;
14
18
@@ -18,12 +22,7 @@ export class Prompter implements IPrompter {
18
22
}
19
23
}
20
24
21
- public async get ( questions : prompt . Question [ ] ) : Promise < any > {
22
- _ . each ( questions , ( q ) => {
23
- q . filter = ( selection : string ) => {
24
- return selection . split ( this . descriptionSeparator ) [ 0 ] . trim ( ) ;
25
- } ;
26
- } ) ;
25
+ public async get ( questions : IPrompterQuestion [ ] ) : Promise < any > {
27
26
try {
28
27
this . muteStdout ( ) ;
29
28
@@ -55,7 +54,7 @@ export class Prompter implements IPrompter {
55
54
message : string ,
56
55
options ?: IAllowEmpty
57
56
) : Promise < string > {
58
- const schema : prompt . Question = {
57
+ const schema : IPrompterQuestion = {
59
58
message,
60
59
type : "password" ,
61
60
name : "password" ,
@@ -73,9 +72,9 @@ export class Prompter implements IPrompter {
73
72
message : string ,
74
73
options ?: IPrompterOptions
75
74
) : Promise < string > {
76
- const schema : prompt . Question = {
75
+ const schema : IPrompterQuestion = {
77
76
message,
78
- type : "input " ,
77
+ type : "text " ,
79
78
name : "inputString" ,
80
79
validate : ( value : any ) => {
81
80
const doesNotAllowEmpty =
@@ -95,9 +94,9 @@ export class Prompter implements IPrompter {
95
94
promptMessage : string ,
96
95
choices : string [ ]
97
96
) : Promise < string > {
98
- const schema : prompt . Answers = {
97
+ const schema : IPrompterAnswers = {
99
98
message : promptMessage ,
100
- type : "list " ,
99
+ type : "select " ,
101
100
name : "userAnswer" ,
102
101
choices,
103
102
} ;
@@ -110,21 +109,17 @@ export class Prompter implements IPrompter {
110
109
promptMessage : string ,
111
110
choices : { key : string ; description : string } [ ]
112
111
) : Promise < string > {
113
- const longestKeyLength = choices . concat ( ) . sort ( function ( a , b ) {
114
- return b . key . length - a . key . length ;
115
- } ) [ 0 ] . key . length ;
116
112
const inquirerChoices = choices . map ( ( choice ) => {
117
113
return {
118
- name : `${ _ . padEnd ( choice . key , longestKeyLength ) } ${
119
- choice . description ? this . descriptionSeparator : ""
120
- } ${ choice . description } `,
121
- short : choice . key ,
114
+ title : choice . key ,
115
+ value : choice . key ,
116
+ description : choice . description ,
122
117
} ;
123
118
} ) ;
124
119
125
120
const schema : any = {
126
121
message : promptMessage ,
127
- type : "list " ,
122
+ type : "select " ,
128
123
name : "userAnswer" ,
129
124
choices : inquirerChoices ,
130
125
} ;
0 commit comments