11/**
2- * @description : inquirer plugin - ComplateCheckbox
2+ * @description : inquirer plugin - Search Checkbox
33 * @author : @Zhengqbbb (zhengqbbb@gmail.com)
44 * @license MIT
55 */
@@ -24,6 +24,7 @@ export class SearchCheckbox extends Base {
2424 private firstRender = true ;
2525 private searching = false ;
2626 private haveSearched = false ;
27+ private themeColorCode ?: string ;
2728 private initialValue : any = - 1 ;
2829 private lastSearchInput ?: string ;
2930 private paginator : Paginator = new Paginator ( this . screen , { isInfinite : true } ) ;
@@ -33,10 +34,12 @@ export class SearchCheckbox extends Base {
3334
3435 constructor ( questions : Question , readline : ReadlineInterface , answers : Answers ) {
3536 super ( questions , readline , answers ) ;
36- const { source, separator, isInitDefault } = this . opt as unknown as CZPromptQuestionOptions ;
37+ const { source, separator, isInitDefault, themeColorCode } = this
38+ . opt as unknown as CZPromptQuestionOptions ;
3739 if ( ! source ) this . throwParamError ( "source" ) ;
3840 if ( typeof separator === "string" ) this . separator = separator ;
3941 if ( isInitDefault ) this . initialValue = this . opt . default ;
42+ if ( themeColorCode ) this . themeColorCode = themeColorCode ;
4043 this . renderChoices = new Choices ( [ ] , { } ) ;
4144 }
4245
@@ -72,12 +75,18 @@ export class SearchCheckbox extends Base {
7275
7376 // Render choices or answer depending on the state
7477 if ( this . status === "answered" ) {
75- content += style . cyan ( this . selection . join ( this . separator ) ) ;
78+ this . themeColorCode
79+ ? ( content += style . rgb ( this . themeColorCode ) ( this . selection . join ( this . separator ) ) )
80+ : ( content += style . cyan ( this . selection . join ( this . separator ) ) ) ;
7681 } else if ( this . searching ) {
7782 content += this . rl . line ;
7883 bottomContent += " " + style . dim ( "Searching..." ) ;
7984 } else if ( this . choicesLen ) {
80- const choicesStr = choicesRender ( this . renderChoices . choices , this . pointer ) ;
85+ const choicesStr = choicesRender (
86+ this . renderChoices . choices ,
87+ this . pointer ,
88+ this . themeColorCode
89+ ) ;
8190 content += this . rl . line ;
8291 const indexPosition = this . pointer ;
8392 let realIndexPosition = 0 ;
@@ -99,11 +108,12 @@ export class SearchCheckbox extends Base {
99108 if ( this . firstRender ) {
100109 content += style . dim ( "Press <space>|<right> to select, <enter> to submit" ) ;
101110 }
111+ this . firstRender = false ;
112+
102113 if ( error ) {
103114 bottomContent = style . red ( ">> " ) + error ;
104115 }
105116
106- this . firstRender = false ;
107117 this . screen . render ( content , bottomContent ) ;
108118 }
109119
@@ -265,7 +275,11 @@ export class SearchCheckbox extends Base {
265275 * @param {Number } pointer Position of the pointer
266276 * @return {String } Rendered content
267277 */
268- const choicesRender = ( choices : ChoicesType [ "choices" ] , pointer : number ) : string => {
278+ const choicesRender = (
279+ choices : ChoicesType [ "choices" ] ,
280+ pointer : number ,
281+ themeColorCode ?: string
282+ ) : string => {
269283 let output = "" ;
270284 let separatorOffset = 0 ;
271285
@@ -286,7 +300,11 @@ const choicesRender = (choices: ChoicesType["choices"], pointer: number): string
286300 ? figures . squareSmallFilled + " " + choice . name
287301 : getCheckbox ( choice . checked || false ) + " " + choice . name ;
288302 if ( i - separatorOffset === pointer ) {
289- output += style . cyan ( " " + figures . pointer + style . cyan ( line ) ) ;
303+ themeColorCode
304+ ? ( output += style . rgb ( themeColorCode ) (
305+ " " + figures . pointer + style . rgb ( themeColorCode ) ( line )
306+ ) )
307+ : ( output += style . cyan ( " " + figures . pointer + line ) ) ;
290308 } else {
291309 output += " " + line ;
292310 }
0 commit comments