2022-11-01 17:28:14 +02:00
import { _ } from '@joplin/lib/locale' ;
2024-04-05 13:16:49 +02:00
// eslint-disable-next-line @typescript-eslint/ban-types, @typescript-eslint/no-explicit-any -- Old code before rule was applied, Old code before rule was applied
2022-11-01 17:28:14 +02:00
export default ( cmd : any , stdout : Function , store : Function , gui : Function ) = > {
cmd . setStdout ( ( text : string ) = > {
return stdout ( text ) ;
} ) ;
2024-04-05 13:16:49 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
2022-11-01 17:28:14 +02:00
cmd . setDispatcher ( ( action : any ) = > {
if ( store ( ) ) {
return store ( ) . dispatch ( action ) ;
} else {
return ( ) = > { } ;
}
} ) ;
2024-04-05 13:16:49 +02:00
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
2022-11-01 17:28:14 +02:00
cmd . setPrompt ( async ( message : string , options : any ) = > {
if ( ! options ) options = { } ;
if ( ! options . type ) options . type = 'boolean' ;
if ( ! options . booleanAnswerDefault ) options . booleanAnswerDefault = 'y' ;
if ( ! options . answers ) options . answers = options . booleanAnswerDefault === 'y' ? [ _ ( 'Y' ) , _ ( 'n' ) ] : [ _ ( 'N' ) , _ ( 'y' ) ] ;
if ( options . type === 'boolean' ) {
message += ` ( ${ options . answers . join ( '/' ) } ) ` ;
}
let answer = await gui ( ) . prompt ( '' , ` ${ message } ` , options ) ;
if ( options . type === 'boolean' ) {
if ( answer === null ) return false ; // Pressed ESCAPE
if ( ! answer ) answer = options . answers [ 0 ] ;
const positiveIndex = options . booleanAnswerDefault === 'y' ? 0 : 1 ;
return answer . toLowerCase ( ) === options . answers [ positiveIndex ] . toLowerCase ( ) ;
} else {
return answer ;
}
} ) ;
return cmd ;
} ;