@@ -31,12 +31,21 @@ const { debug, inherits } = require('util');
31
31
const Buffer = require ( 'buffer' ) . Buffer ;
32
32
const EventEmitter = require ( 'events' ) ;
33
33
const {
34
+ CSI ,
34
35
emitKeys,
35
36
getStringWidth,
36
37
isFullWidthCodePoint,
37
38
stripVTControlCharacters
38
39
} = require ( 'internal/readline' ) ;
39
40
41
+ const {
42
+ kEscape,
43
+ kClearToBeginning,
44
+ kClearToEnd,
45
+ kClearLine,
46
+ kClearScreenDown
47
+ } = CSI ;
48
+
40
49
const kHistorySize = 30 ;
41
50
const kMincrlfDelay = 100 ;
42
51
const kMaxcrlfDelay = 2000 ;
@@ -995,7 +1004,7 @@ function emitKeypressEvents(stream, iface) {
995
1004
try {
996
1005
stream [ ESCAPE_DECODER ] . next ( r [ i ] ) ;
997
1006
// Escape letter at the tail position
998
- if ( r [ i ] === '\x1b' && i + 1 === r . length ) {
1007
+ if ( r [ i ] === kEscape && i + 1 === r . length ) {
999
1008
timeoutId = setTimeout ( escapeCodeTimeout , ESCAPE_CODE_TIMEOUT ) ;
1000
1009
}
1001
1010
} catch ( err ) {
@@ -1047,9 +1056,9 @@ function cursorTo(stream, x, y) {
1047
1056
throw new Error ( 'Can\'t set cursor row without also setting it\'s column' ) ;
1048
1057
1049
1058
if ( typeof y !== 'number' ) {
1050
- stream . write ( '\x1b[' + ( x + 1 ) + 'G' ) ;
1059
+ stream . write ( CSI ` ${ x + 1 } G` ) ;
1051
1060
} else {
1052
- stream . write ( '\x1b[' + ( y + 1 ) + ';' + ( x + 1 ) + 'H' ) ;
1061
+ stream . write ( CSI ` ${ y + 1 } ; ${ x + 1 } H` ) ;
1053
1062
}
1054
1063
}
1055
1064
@@ -1062,15 +1071,15 @@ function moveCursor(stream, dx, dy) {
1062
1071
return ;
1063
1072
1064
1073
if ( dx < 0 ) {
1065
- stream . write ( '\x1b[' + ( - dx ) + 'D' ) ;
1074
+ stream . write ( CSI ` ${ - dx } D` ) ;
1066
1075
} else if ( dx > 0 ) {
1067
- stream . write ( '\x1b[' + dx + 'C' ) ;
1076
+ stream . write ( CSI ` ${ dx } C` ) ;
1068
1077
}
1069
1078
1070
1079
if ( dy < 0 ) {
1071
- stream . write ( '\x1b[' + ( - dy ) + 'A' ) ;
1080
+ stream . write ( CSI ` ${ - dy } A` ) ;
1072
1081
} else if ( dy > 0 ) {
1073
- stream . write ( '\x1b[' + dy + 'B' ) ;
1082
+ stream . write ( CSI ` ${ dy } B` ) ;
1074
1083
}
1075
1084
}
1076
1085
@@ -1087,13 +1096,13 @@ function clearLine(stream, dir) {
1087
1096
1088
1097
if ( dir < 0 ) {
1089
1098
// to the beginning
1090
- stream . write ( '\x1b[1K' ) ;
1099
+ stream . write ( kClearToBeginning ) ;
1091
1100
} else if ( dir > 0 ) {
1092
1101
// to the end
1093
- stream . write ( '\x1b[0K' ) ;
1102
+ stream . write ( kClearToEnd ) ;
1094
1103
} else {
1095
1104
// entire line
1096
- stream . write ( '\x1b[2K' ) ;
1105
+ stream . write ( kClearLine ) ;
1097
1106
}
1098
1107
}
1099
1108
@@ -1105,7 +1114,7 @@ function clearScreenDown(stream) {
1105
1114
if ( stream === null || stream === undefined )
1106
1115
return ;
1107
1116
1108
- stream . write ( '\x1b[0J' ) ;
1117
+ stream . write ( kClearScreenDown ) ;
1109
1118
}
1110
1119
1111
1120
module . exports = {
0 commit comments