@@ -157,13 +157,15 @@ const kPreviousCursorCols = Symbol('_previousCursorCols');
157157const kMultilineMove = Symbol ( '_multilineMove' ) ;
158158const kPreviousPrevRows = Symbol ( '_previousPrevRows' ) ;
159159const kAddNewLineOnTTY = Symbol ( '_addNewLineOnTTY' ) ;
160+ const kColorize = Symbol ( '_colorize' ) ;
160161
161162function InterfaceConstructor ( input , output , completer , terminal ) {
162163 this [ kSawReturnAt ] = 0 ;
163164 // TODO(BridgeAR): Document this property. The name is not ideal, so we
164165 // might want to expose an alias and document that instead.
165166 this . isCompletionEnabled = true ;
166167 this [ kSawKeyPress ] = false ;
168+ this [ kColorize ] = undefined ;
167169 this [ kPreviousKey ] = null ;
168170 this . escapeCodeTimeout = ESCAPE_CODE_TIMEOUT ;
169171 this . tabSize = 8 ;
@@ -186,6 +188,7 @@ function InterfaceConstructor(input, output, completer, terminal) {
186188 const historySize = input . historySize ;
187189 const history = input . history ;
188190 const removeHistoryDuplicates = input . removeHistoryDuplicates ;
191+ this [ kColorize ] = input . colorize ;
189192
190193 if ( input . tabSize !== undefined ) {
191194 validateUint32 ( input . tabSize , 'tabSize' , true ) ;
@@ -523,15 +526,18 @@ class Interface extends InterfaceConstructor {
523526 if ( this [ kIsMultiline ] ) {
524527 const lines = StringPrototypeSplit ( this . line , '\n' ) ;
525528 // Write first line with normal prompt
526- this [ kWriteToOutput ] ( this [ kPrompt ] + lines [ 0 ] ) ;
529+ this [ kWriteToOutput ] ( this [ kPrompt ] +
530+ ( this [ kColorize ] ?. ( lines [ 0 ] ) ?? lines [ 0 ] ) ) ;
527531
528532 // For continuation lines, add the "|" prefix
529533 for ( let i = 1 ; i < lines . length ; i ++ ) {
530- this [ kWriteToOutput ] ( `\n${ kMultilinePrompt . description } ` + lines [ i ] ) ;
534+ this [ kWriteToOutput ] ( `\n${ kMultilinePrompt . description } ` +
535+ ( this [ kColorize ] ?. ( lines [ i ] ) ?? lines [ i ] ) ) ;
531536 }
532537 } else {
533538 // Write the prompt and the current buffer content.
534- this [ kWriteToOutput ] ( line ) ;
539+ this [ kWriteToOutput ] ( this [ kPrompt ] +
540+ ( this [ kColorize ] ?. ( this . line ) ?? this . line ) ) ;
535541 }
536542
537543 // Force terminal to allocate a new line
@@ -687,7 +693,11 @@ class Interface extends InterfaceConstructor {
687693 this . line += c ;
688694 }
689695 this . cursor += c . length ;
690- this [ kWriteToOutput ] ( c ) ;
696+ if ( this [ kColorize ] === undefined ) {
697+ this [ kWriteToOutput ] ( c ) ;
698+ } else {
699+ this [ kRefreshLine ] ( ) ;
700+ }
691701 return ;
692702 }
693703 if ( this . cursor < this . line . length ) {
@@ -706,7 +716,7 @@ class Interface extends InterfaceConstructor {
706716 this . cursor += c . length ;
707717 const newPos = this . getCursorPos ( ) ;
708718
709- if ( oldPos . rows < newPos . rows ) {
719+ if ( oldPos . rows < newPos . rows || this [ kColorize ] !== undefined ) {
710720 this [ kRefreshLine ] ( ) ;
711721 } else {
712722 this [ kWriteToOutput ] ( c ) ;
0 commit comments