@@ -34,7 +34,6 @@ const {
34
34
const { validateString } = require ( 'internal/validators' ) ;
35
35
const { inspect } = require ( 'util' ) ;
36
36
const { emitExperimentalWarning } = require ( 'internal/util' ) ;
37
- const { Buffer } = require ( 'buffer' ) ;
38
37
const EventEmitter = require ( 'events' ) ;
39
38
const {
40
39
CSI ,
@@ -161,6 +160,10 @@ function Interface(input, output, completer, terminal) {
161
160
162
161
this . terminal = ! ! terminal ;
163
162
163
+ if ( process . env . TERM === 'dumb' ) {
164
+ this . _ttyWrite = _ttyWriteDumb . bind ( this ) ;
165
+ }
166
+
164
167
function ondata ( data ) {
165
168
self . _normalWrite ( data ) ;
166
169
}
@@ -276,7 +279,7 @@ Interface.prototype._setRawMode = function(mode) {
276
279
277
280
Interface . prototype . prompt = function ( preserveCursor ) {
278
281
if ( this . paused ) this . resume ( ) ;
279
- if ( this . terminal ) {
282
+ if ( this . terminal && process . env . TERM !== 'dumb' ) {
280
283
if ( ! preserveCursor ) this . cursor = 0 ;
281
284
this . _refreshLine ( ) ;
282
285
} else {
@@ -417,7 +420,11 @@ Interface.prototype.resume = function() {
417
420
418
421
Interface . prototype . write = function ( d , key ) {
419
422
if ( this . paused ) this . resume ( ) ;
420
- this . terminal ? this . _ttyWrite ( d , key ) : this . _normalWrite ( d ) ;
423
+ if ( this . terminal ) {
424
+ this . _ttyWrite ( d , key ) ;
425
+ } else {
426
+ this . _normalWrite ( d ) ;
427
+ }
421
428
} ;
422
429
423
430
Interface . prototype . _normalWrite = function ( b ) {
@@ -789,6 +796,46 @@ Interface.prototype._moveCursor = function(dx) {
789
796
}
790
797
} ;
791
798
799
+ function _ttyWriteDumb ( s , key ) {
800
+ key = key || { } ;
801
+
802
+ if ( key . name === 'escape' ) return ;
803
+
804
+ if ( this . _sawReturnAt && key . name !== 'enter' )
805
+ this . _sawReturnAt = 0 ;
806
+
807
+ if ( key . ctrl && key . name === 'c' ) {
808
+ if ( this . listenerCount ( 'SIGINT' ) > 0 ) {
809
+ this . emit ( 'SIGINT' ) ;
810
+ } else {
811
+ // This readline instance is finished
812
+ this . close ( ) ;
813
+ }
814
+ }
815
+
816
+ switch ( key . name ) {
817
+ case 'return' : // carriage return, i.e. \r
818
+ this . _sawReturnAt = Date . now ( ) ;
819
+ this . _line ( ) ;
820
+ break ;
821
+
822
+ case 'enter' :
823
+ // When key interval > crlfDelay
824
+ if ( this . _sawReturnAt === 0 ||
825
+ Date . now ( ) - this . _sawReturnAt > this . crlfDelay ) {
826
+ this . _line ( ) ;
827
+ }
828
+ this . _sawReturnAt = 0 ;
829
+ break ;
830
+
831
+ default :
832
+ if ( typeof s === 'string' && s ) {
833
+ this . line += s ;
834
+ this . cursor += s . length ;
835
+ this . _writeToOutput ( s ) ;
836
+ }
837
+ }
838
+ }
792
839
793
840
// handle a write from the tty
794
841
Interface . prototype . _ttyWrite = function ( s , key ) {
@@ -1007,10 +1054,7 @@ Interface.prototype._ttyWrite = function(s, key) {
1007
1054
// falls through
1008
1055
1009
1056
default :
1010
- if ( s instanceof Buffer )
1011
- s = s . toString ( 'utf-8' ) ;
1012
-
1013
- if ( s ) {
1057
+ if ( typeof s === 'string' && s ) {
1014
1058
var lines = s . split ( / \r \n | \n | \r / ) ;
1015
1059
for ( var i = 0 , len = lines . length ; i < len ; i ++ ) {
1016
1060
if ( i > 0 ) {
0 commit comments