@@ -156,13 +156,15 @@ const kPreviousCursorCols = Symbol('_previousCursorCols');
156156const kMultilineMove = Symbol ( '_multilineMove' ) ;
157157const kPreviousPrevRows = Symbol ( '_previousPrevRows' ) ;
158158const kAddNewLineOnTTY = Symbol ( '_addNewLineOnTTY' ) ;
159+ const kColorize = Symbol ( '_colorize' ) ;
159160
160161function InterfaceConstructor ( input , output , completer , terminal ) {
161162 this [ kSawReturnAt ] = 0 ;
162163 // TODO(BridgeAR): Document this property. The name is not ideal, so we
163164 // might want to expose an alias and document that instead.
164165 this . isCompletionEnabled = true ;
165166 this [ kSawKeyPress ] = false ;
167+ this [ kColorize ] = undefined ;
166168 this [ kPreviousKey ] = null ;
167169 this . escapeCodeTimeout = ESCAPE_CODE_TIMEOUT ;
168170 this . tabSize = 8 ;
@@ -184,6 +186,7 @@ function InterfaceConstructor(input, output, completer, terminal) {
184186 const historySize = input . historySize ;
185187 const history = input . history ;
186188 const removeHistoryDuplicates = input . removeHistoryDuplicates ;
189+ this [ kColorize ] = input . colorize ;
187190
188191 if ( input . tabSize !== undefined ) {
189192 validateUint32 ( input . tabSize , 'tabSize' , true ) ;
@@ -514,15 +517,18 @@ class Interface extends InterfaceConstructor {
514517 if ( this [ kIsMultiline ] ) {
515518 const lines = StringPrototypeSplit ( this . line , '\n' ) ;
516519 // Write first line with normal prompt
517- this [ kWriteToOutput ] ( this [ kPrompt ] + lines [ 0 ] ) ;
520+ this [ kWriteToOutput ] ( this [ kPrompt ] +
521+ ( this [ kColorize ] ?. ( lines [ 0 ] ) ?? lines [ 0 ] ) ) ;
518522
519523 // For continuation lines, add the "|" prefix
520524 for ( let i = 1 ; i < lines . length ; i ++ ) {
521- this [ kWriteToOutput ] ( `\n${ kMultilinePrompt . description } ` + lines [ i ] ) ;
525+ this [ kWriteToOutput ] ( `\n${ kMultilinePrompt . description } ` +
526+ ( this [ kColorize ] ?. ( lines [ i ] ) ?? lines [ i ] ) ) ;
522527 }
523528 } else {
524529 // Write the prompt and the current buffer content.
525- this [ kWriteToOutput ] ( line ) ;
530+ this [ kWriteToOutput ] ( this [ kPrompt ] +
531+ ( this [ kColorize ] ?. ( this . line ) ?? this . line ) ) ;
526532 }
527533
528534 // Force terminal to allocate a new line
@@ -671,7 +677,11 @@ class Interface extends InterfaceConstructor {
671677 this . line += c ;
672678 }
673679 this . cursor += c . length ;
674- this [ kWriteToOutput ] ( c ) ;
680+ if ( this [ kColorize ] === undefined ) {
681+ this [ kWriteToOutput ] ( c ) ;
682+ } else {
683+ this [ kRefreshLine ] ( ) ;
684+ }
675685 return ;
676686 }
677687 if ( this . cursor < this . line . length ) {
@@ -690,7 +700,7 @@ class Interface extends InterfaceConstructor {
690700 this . cursor += c . length ;
691701 const newPos = this . getCursorPos ( ) ;
692702
693- if ( oldPos . rows < newPos . rows ) {
703+ if ( oldPos . rows < newPos . rows || this [ kColorize ] !== undefined ) {
694704 this [ kRefreshLine ] ( ) ;
695705 } else {
696706 this [ kWriteToOutput ] ( c ) ;
0 commit comments