@@ -286,8 +286,8 @@ export class Massarg<Options extends OptionsBase = OptionsBase> {
286286 if ( example . description ) {
287287 lines . push (
288288 ...wrap ( this . color ( titleColors , example . description ) , {
289- colorCount : this . _help . useColors ? colorCount ( titleColors ) : 0 ,
290- firstLineIndent : 2 ,
289+ colorCount : this . colorCount ( titleColors ) ,
290+ indent : 2 ,
291291 printWidth : this . _help . printWidth ,
292292 } )
293293 )
@@ -300,22 +300,30 @@ export class Massarg<Options extends OptionsBase = OptionsBase> {
300300 " "
301301 ),
302302 {
303- colorCount : this . _help . useColors ? colorCount ( highlightColors ) : 0 ,
303+ colorCount : this . colorCount ( highlightColors ) ,
304304 firstLineIndent : 2 ,
305+ indent : 3 + this . _help . exampleInputPrefix . length ,
306+ // indent: this.colorCount(normalColors) + 4,
305307 printWidth : this . _help . printWidth ,
306308 }
307309 )
308310 )
309- lines.push(
310- ...wrap(
311- [this.color(normalColors, this._help.exampleOutputPrefix), this.color(bodyColors, example.output)].join(" "),
312- {
313- colorCount : this . _help . useColors ? colorCount ( bodyColors ) : 0 ,
314- firstLineIndent : 2 ,
315- printWidth : this . _help . printWidth ,
316- }
311+ if (example.output) {
312+ lines . push (
313+ ...wrap (
314+ [ this . color ( normalColors , this . _help . exampleOutputPrefix ) , this . color ( bodyColors , example . output ) ] . join (
315+ " "
316+ ) ,
317+ {
318+ colorCount : this . colorCount ( bodyColors ) ,
319+ firstLineIndent : 2 ,
320+ indent : 3 + this . _help . exampleOutputPrefix . length ,
321+ // indent: this.colorCount(normalColors) + 4,
322+ printWidth : this . _help . printWidth ,
323+ }
324+ )
317325 )
318- )
326+ }
319327 lines.push("")
320328 }
321329 return lines
@@ -405,20 +413,18 @@ export class Massarg<Options extends OptionsBase = OptionsBase> {
405413
406414 for (const item of list) {
407415 const cmdName = this . color ( highlightColors , `${ item . name } ` ) . padEnd (
408- nameFullSize + ( this . _help . useColors ? colorCount ( highlightColors ) : 0 ) * COLOR_CODE_LEN ,
416+ nameFullSize + this . colorCount ( highlightColors ) * COLOR_CODE_LEN ,
409417 " "
410418 )
411419 const cmdDescr = this . color ( normalColors , item . description ?? "" )
412420
413421 for ( const line of wrap ( cmdName + cmdDescr , {
414422 indent : nameFullSize + INDENT_LEN ,
415- colorCount : this . _help . useColors
416- ? colorCount (
417- normalColors ,
418- highlightColors ,
419- item . additionalColorCount ? new Array ( { length : item . additionalColorCount } ) : [ ]
420- )
421- : 0 ,
423+ colorCount : this . colorCount (
424+ normalColors ,
425+ highlightColors ,
426+ item . additionalColorCount ? new Array ( { length : item . additionalColorCount } ) : [ ]
427+ ) ,
422428 firstLineIndent : INDENT_LEN ,
423429 printWidth : this . _help . printWidth ,
424430 } ) ) {
@@ -532,6 +538,13 @@ export class Massarg<Options extends OptionsBase = OptionsBase> {
532538 }
533539 return chalk.reset(output)
534540 }
541+
542+ private colorCount ( ...colors : any [ ] ) : number {
543+ if ( ! this . _help . useColors ) {
544+ return 0
545+ }
546+ return colorCount(...colors)
547+ }
535548}
536549
537550export function massarg < T extends OptionsBase = OptionsBase > () {
0 commit comments