@@ -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 ) {
162163this [ 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.
165166this . isCompletionEnabled = true ;
166167this [ kSawKeyPress ] = false ;
168+ this [ kColorize ] = undefined ;
167169this [ kPreviousKey ] = null ;
168170this . escapeCodeTimeout = ESCAPE_CODE_TIMEOUT ;
169171this . tabSize = 8 ;
@@ -186,6 +188,7 @@ function InterfaceConstructor(input, output, completer, terminal) {
186188const historySize = input . historySize ;
187189const history = input . history ;
188190const removeHistoryDuplicates = input . removeHistoryDuplicates ;
191+ this [ kColorize ] = input . colorize ;
189192
190193if ( input . tabSize !== undefined ) {
191194validateUint32 ( input . tabSize , 'tabSize' , true ) ;
@@ -523,15 +526,18 @@ class Interface extends InterfaceConstructor {
523526if ( this [ kIsMultiline ] ) {
524527const 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
529533for ( 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 {
687693this . line += c ;
688694}
689695this . cursor += c . length ;
690- this [ kWriteToOutput ] ( c ) ;
696+ if ( this [ kColorize ] === undefined ) {
697+ this [ kWriteToOutput ] ( c ) ;
698+ } else {
699+ this [ kRefreshLine ] ( ) ;
700+ }
691701return ;
692702}
693703if ( this . cursor < this . line . length ) {
@@ -706,7 +716,7 @@ class Interface extends InterfaceConstructor {
706716this . cursor += c . length ;
707717const newPos = this . getCursorPos ( ) ;
708718
709- if ( oldPos . rows < newPos . rows ) {
719+ if ( oldPos . rows < newPos . rows || this [ kColorize ] !== undefined ) {
710720this [ kRefreshLine ] ( ) ;
711721} else {
712722this [ kWriteToOutput ] ( c ) ;
0 commit comments