@@ -140,30 +140,33 @@ async function askToUserCharaId(
140
140
. filter ( ( el ) => el [ 1 ] )
141
141
. map ( ( el ) => el [ 0 ] ) ;
142
142
const selectedCharaArray : number [ ] = [ ] ;
143
- const questionBuilder = async ( position : string ) => {
143
+ const questionBuilder = async ( position : string , canBack : boolean = false ) => {
144
144
return (
145
145
await prompts ( {
146
146
type : 'select' ,
147
147
name : 'value' ,
148
148
message : `Select singing chara for '${ position } ' position` ,
149
- choices : liveCanUseCharaArray
150
- // .filter((entry) => selectedCharaArray.includes(entry) === false) // to eliminate duplicates
151
- . map ( ( entry ) => ( {
152
- title :
153
- entry +
154
- ': ' +
155
- db . masterDb . text_data . find (
156
- ( texEntry : any ) => texEntry . id === 6 && texEntry . category === 6 && texEntry . index === entry ,
157
- ) . text ,
158
- description :
159
- 'CV: ' +
160
- db . masterDb . text_data . find (
161
- ( texEntry : any ) => texEntry . id === 7 && texEntry . category === 7 && texEntry . index === entry ,
162
- ) . text ,
163
- value : entry ,
164
- disabled : false ,
165
- selected : false ,
166
- } ) ) ,
149
+ choices : [
150
+ ...liveCanUseCharaArray
151
+ // .filter((entry) => selectedCharaArray.includes(entry) === false) // to eliminate duplicates
152
+ . map ( ( entry ) => ( {
153
+ title :
154
+ entry +
155
+ ': ' +
156
+ db . masterDb . text_data . find (
157
+ ( texEntry : any ) => texEntry . id === 6 && texEntry . category === 6 && texEntry . index === entry ,
158
+ ) . text ,
159
+ description :
160
+ 'CV: ' +
161
+ db . masterDb . text_data . find (
162
+ ( texEntry : any ) => texEntry . id === 7 && texEntry . category === 7 && texEntry . index === entry ,
163
+ ) . text ,
164
+ value : entry ,
165
+ disabled : false ,
166
+ selected : false ,
167
+ } ) ) ,
168
+ { title : '=== Go Back ===' , value : - 1 , disabled : ! canBack , selected : false } ,
169
+ ] ,
167
170
} )
168
171
) . value ;
169
172
} ;
@@ -198,7 +201,6 @@ async function askToUserCharaId(
198
201
retObj [ position ] = argParsed [ i ] ! ;
199
202
selectedCharaArray . push ( argParsed [ i ] ! ) ;
200
203
}
201
-
202
204
return retObj ;
203
205
} else {
204
206
console . log ( `Available positions: ${ availablePositionArray . map ( ( el ) => chalk . bold . green ( el ) ) . join ( ', ' ) } ` ) ;
@@ -212,9 +214,14 @@ async function askToUserCharaId(
212
214
right3 : null ,
213
215
} ;
214
216
for ( let i = 0 ; i < availablePositionArray . length ; i ++ ) {
215
- const rsp = await questionBuilder ( availablePositionArray [ i ] ! ) ;
216
- selectedCharaArray . push ( rsp ) ;
217
- retObj [ availablePositionArray [ i ] ! ] = rsp ;
217
+ const rsp = await questionBuilder ( availablePositionArray [ i ] ! , i > 0 ) ;
218
+ if ( rsp !== - 1 ) {
219
+ selectedCharaArray . push ( rsp ) ;
220
+ retObj [ availablePositionArray [ i ] ! ] = rsp ;
221
+ } else {
222
+ i -= 2 ;
223
+ process . stdout . write ( '\x1b[1A\x1b[2K\x1b[1A\x1b[2K' ) ;
224
+ }
218
225
}
219
226
return retObj ;
220
227
}
0 commit comments