1- import chalk from 'chalk' ;
1+ import chalk from 'chalk' ;
22
33import { AwesomeLogger } from '../../awesome-logger.js' ;
44import { AwesomePromptToggleConfig , AwesomePromptToggleControl } from './config/toggle.js' ;
@@ -7,7 +7,10 @@ import { KEY_ARROW_DOWN, KEY_ARROW_UP } from '../../utils/ansi-utils.js';
77import { TerminalSize } from '../../utils/terminal-size.js' ;
88import { AwesomePromptBase } from '../prompt-base.js' ;
99
10- export class AwesomeTogglePromt extends AwesomePromptBase < string [ ] > implements AwesomePromptToggleControl {
10+ export class AwesomeTogglePromt
11+ extends AwesomePromptBase < string [ ] >
12+ implements AwesomePromptToggleControl
13+ {
1114 private _currentHighlightedRow : number ;
1215 private readonly _text ?: string ;
1316 private readonly _options : string [ ] ;
@@ -24,10 +27,15 @@ export class AwesomeTogglePromt extends AwesomePromptBase<string[]> implements A
2427 this . _currentHighlightedRow = 0 ;
2528 this . _options = config . options ?? [ ] ;
2629 this . _lines = [ ...this . _options ] ;
27- this . _toggles = this . _options . map ( ( ) => false ) ;
30+ this . _toggles = this . _options . map ( o => config . default ?. includes ( o ) ?? false ) ;
2831 }
2932
30- private adjustLine ( lineText : string , index : number , highlighted : boolean , selected : boolean = false ) {
33+ private adjustLine (
34+ lineText : string ,
35+ index : number ,
36+ highlighted : boolean ,
37+ selected : boolean = false
38+ ) {
3139 const newText = `${ selected ? chalk . green ( '[X]' ) : chalk . gray ( '[ ]' ) } ${ ( highlighted ? chalk . blue : chalk . white ) ( lineText ) } ` ;
3240 this . _lines [ index ] = newText ;
3341 }
@@ -58,7 +66,10 @@ export class AwesomeTogglePromt extends AwesomePromptBase<string[]> implements A
5866 if ( this . _currentHighlightedRow < this . _lines . length - 1 ) {
5967 const prevHighlightedLine = this . _currentHighlightedRow ;
6068 this . _currentHighlightedRow ++ ;
61- if ( this . _currentHighlightedRow - this . scrollAmount > TerminalSize . terminalHeight - 2 - this . fixedLineCount ) {
69+ if (
70+ this . _currentHighlightedRow - this . scrollAmount >
71+ TerminalSize . terminalHeight - 2 - this . fixedLineCount
72+ ) {
6273 this . scrollAmount ++ ;
6374 }
6475 this . renderLines ( prevHighlightedLine , this . _currentHighlightedRow ) ;
@@ -104,7 +115,9 @@ export class AwesomeTogglePromt extends AwesomePromptBase<string[]> implements A
104115 result . push ( option ) ;
105116 }
106117 }
107- const resultLog = chalk . gray ( ` - Selected option${ result . length > 1 ? 's' : '' } : ${ chalk . green ( result . join ( ', ' ) ) } ` ) ;
118+ const resultLog = chalk . gray (
119+ ` - Selected option${ result . length > 1 ? 's' : '' } : ${ chalk . green ( result . join ( ', ' ) ) } `
120+ ) ;
108121 this . setLogger ( AwesomeLogger . create ( 'text' , { text : resultLog } ) ) ;
109122 }
110123
0 commit comments