@@ -34,8 +34,9 @@ export const run: (
3434 const commandPath = options ?. commandPath ?? [ command . name ]
3535 const selected = getCommandAtPath ( command , commandPath )
3636 const commandLine = ( options ?. prefix ?? commandPath ) . map ( ( value ) => commandLineArg ( value ) )
37- yield * logCurrentCommand ( commandLine )
38- yield * promptCommand ( selected , commandLine , selected === command ? "ROOT" : selected . name )
37+ const { colors } = yield * Prompt . Theme
38+ yield * logCurrentCommand ( commandLine , colors )
39+ yield * promptCommand ( selected , commandLine , selected === command ? "ROOT" : selected . name , colors )
3940 return {
4041 args : commandLine . map ( ( arg ) => arg . value ) ,
4142 displayArgs : commandLine . map ( ( arg ) => arg . displayValue )
@@ -63,30 +64,31 @@ const getCommandAtPath = (
6364const promptCommand : (
6465 command : Command . Command . Any ,
6566 commandLine : Array < CommandLineArg > ,
66- sectionName : string
67+ sectionName : string ,
68+ colors : boolean
6769) => Effect . Effect < void , CliError . CliError | Terminal . QuitError , Command . Environment > = Effect . fnUntraced (
68- function * ( command , commandLine , sectionName ) {
70+ function * ( command , commandLine , sectionName , colors ) {
6971 const impl = toImpl ( command )
7072 const visibleSubcommands = command . subcommands . flatMap ( ( group ) => group . commands . filter ( ( child ) => ! child . unlisted ) )
7173 const config = visibleSubcommands . length === 0 ? impl . config : impl . contextConfig
7274
7375 if ( config . flags . length > 0 ) {
74- yield * Console . log ( renderSection ( sectionName , "FLAGS" ) )
76+ yield * Console . log ( renderSection ( sectionName , "FLAGS" , colors ) )
7577 for ( const param of config . flags ) {
7678 commandLine . push ( ...yield * promptParam ( param ) )
7779 }
7880 if ( config . arguments . length > 0 || visibleSubcommands . length > 0 ) {
79- yield * logCurrentCommand ( commandLine )
81+ yield * logCurrentCommand ( commandLine , colors )
8082 }
8183 }
8284
8385 if ( config . arguments . length > 0 ) {
84- yield * Console . log ( renderSection ( sectionName , "ARGUMENTS" ) )
86+ yield * Console . log ( renderSection ( sectionName , "ARGUMENTS" , colors ) )
8587 for ( const param of config . arguments ) {
8688 commandLine . push ( ...yield * promptParam ( param ) )
8789 }
8890 if ( visibleSubcommands . length > 0 ) {
89- yield * logCurrentCommand ( commandLine )
91+ yield * logCurrentCommand ( commandLine , colors )
9092 }
9193 }
9294
@@ -109,9 +111,9 @@ const promptCommand: (
109111 yield * Console . log ( )
110112 commandLine . push ( commandLineArg ( child . name ) )
111113 if ( hasWizardSteps ( child ) ) {
112- yield * logCurrentCommand ( commandLine )
114+ yield * logCurrentCommand ( commandLine , colors )
113115 }
114- yield * promptCommand ( child , commandLine , child . name )
116+ yield * promptCommand ( child , commandLine , child . name , colors )
115117 }
116118)
117119
@@ -244,41 +246,47 @@ const humanize = (name: string): string => {
244246 return [ words [ 0 ] [ 0 ] . toUpperCase ( ) + words [ 0 ] . slice ( 1 ) , ...words . slice ( 1 ) ] . join ( " " )
245247}
246248
247- const logCurrentCommand = ( commandLine : ReadonlyArray < CommandLineArg > ) : Effect . Effect < void > =>
248- Console . log ( renderCommandBlock ( "Current command" , commandLine . map ( ( arg ) => arg . displayValue ) , Ansi . magenta ) )
249+ const logCurrentCommand = ( commandLine : ReadonlyArray < CommandLineArg > , colors : boolean ) : Effect . Effect < void > =>
250+ Console . log ( renderCommandBlock ( "Current command" , commandLine . map ( ( arg ) => arg . displayValue ) , colors , Ansi . magenta ) )
249251
250- const renderSection = ( commandName : string , section : string ) : string =>
251- `${ Ansi . annotate ( commandName . toUpperCase ( ) , Ansi . bold , Ansi . cyanBright ) } ${ Ansi . annotate ( "·" , Ansi . blackBright ) } ${
252- Ansi . annotate ( section , Ansi . bold , Ansi . white )
253- } `
252+ const renderSection = ( commandName : string , section : string , colors : boolean ) : string =>
253+ `${ Ansi . annotate ( colors , commandName . toUpperCase ( ) , Ansi . bold , Ansi . cyanBright ) } ${
254+ Ansi . annotate ( colors , "·" , Ansi . blackBright )
255+ } ${ Ansi . annotate ( colors , section , Ansi . bold , Ansi . white ) } `
254256
255- export const renderIntroduction = ( name : string , version : string , summary : string | undefined ) : string => {
256- const title = `${ Ansi . annotate ( name , Ansi . bold , Ansi . cyanBright ) } ${ Ansi . annotate ( `v${ version } ` , Ansi . white ) } ${
257- Ansi . annotate ( "· Command wizard" , Ansi . bold , Ansi . white )
258- } `
257+ export const renderIntroduction = (
258+ name : string ,
259+ version : string ,
260+ summary : string | undefined ,
261+ colors : boolean
262+ ) : string => {
263+ const title = `${ Ansi . annotate ( colors , name , Ansi . bold , Ansi . cyanBright ) } ${
264+ Ansi . annotate ( colors , `v${ version } ` , Ansi . white )
265+ } ${ Ansi . annotate ( colors , "· Command wizard" , Ansi . bold , Ansi . white ) } `
259266 return [
260267 title ,
261268 ...( summary === undefined || summary . length === 0 ? [ ] : [ summary ] ) ,
262- Ansi . annotate ( "Build a command interactively. Press Ctrl+C to cancel." , Ansi . blackBright ) ,
269+ Ansi . annotate ( colors , "Build a command interactively. Press Ctrl+C to cancel." , Ansi . blackBright ) ,
263270 ""
264271 ] . join ( "\n" )
265272}
266273
267- export const renderCompletion = ( commandLine : ReadonlyArray < string > ) : string =>
268- renderCommandBlock ( "Command ready" , commandLine , Ansi . cyanBright , Ansi . green )
274+ export const renderCompletion = ( commandLine : ReadonlyArray < string > , colors : boolean ) : string =>
275+ renderCommandBlock ( "Command ready" , commandLine , colors , Ansi . cyanBright , Ansi . green )
269276
270- export const renderQuit = ( ) : string => `\n${ Ansi . annotate ( "Wizard cancelled." , Ansi . red ) } `
277+ export const renderQuit = ( colors : boolean ) : string => `\n${ Ansi . annotate ( colors , "Wizard cancelled." , Ansi . red ) } `
271278
272279const renderCommandBlock = (
273280 label : string ,
274281 commandLine : ReadonlyArray < string > ,
282+ colors : boolean ,
275283 commandColor : string ,
276284 labelColor : string = Ansi . white
277285) : string => {
278286 const lines = wrapCommand ( commandLine )
279287 return [
280- Ansi . annotate ( label , Ansi . bold , labelColor ) ,
281- ...lines . map ( ( line ) => Ansi . annotate ( line , commandColor ) ) ,
288+ Ansi . annotate ( colors , label , Ansi . bold , labelColor ) ,
289+ ...lines . map ( ( line ) => Ansi . annotate ( colors , line , commandColor ) ) ,
282290 ""
283291 ] . join ( "\n" )
284292}
0 commit comments