21
21
22
22
'use strict' ;
23
23
24
- const util = require ( 'util' ) ;
24
+ const { inherits , _errnoException , _extend } = require ( 'util' ) ;
25
25
const net = require ( 'net' ) ;
26
26
const { TTY , isTTY } = process . binding ( 'tty_wrap' ) ;
27
- const { inherits } = util ;
28
- const errnoException = util . _errnoException ;
29
27
const errors = require ( 'internal/errors' ) ;
30
28
const readline = require ( 'readline' ) ;
31
29
const { release } = require ( 'os' ) ;
@@ -41,7 +39,6 @@ function isatty(fd) {
41
39
return Number . isInteger ( fd ) && fd >= 0 && isTTY ( fd ) ;
42
40
}
43
41
44
-
45
42
function ReadStream ( fd , options ) {
46
43
if ( ! ( this instanceof ReadStream ) )
47
44
return new ReadStream ( fd , options ) ;
@@ -54,7 +51,7 @@ function ReadStream(fd, options) {
54
51
throw new errors . SystemError ( ctx ) ;
55
52
}
56
53
57
- options = util . _extend ( {
54
+ options = _extend ( {
58
55
highWaterMark : 0 ,
59
56
readable : true ,
60
57
writable : false ,
@@ -74,7 +71,6 @@ ReadStream.prototype.setRawMode = function(flag) {
74
71
this . isRaw = flag ;
75
72
} ;
76
73
77
-
78
74
function WriteStream ( fd ) {
79
75
if ( ! ( this instanceof WriteStream ) )
80
76
return new WriteStream ( fd ) ;
@@ -100,16 +96,15 @@ function WriteStream(fd) {
100
96
// Ref: https://github.com/nodejs/node/pull/1771#issuecomment-119351671
101
97
this . _handle . setBlocking ( true ) ;
102
98
103
- var winSize = new Array ( 2 ) ;
104
- var err = this . _handle . getWindowSize ( winSize ) ;
99
+ const winSize = new Array ( 2 ) ;
100
+ const err = this . _handle . getWindowSize ( winSize ) ;
105
101
if ( ! err ) {
106
102
this . columns = winSize [ 0 ] ;
107
103
this . rows = winSize [ 1 ] ;
108
104
}
109
105
}
110
106
inherits ( WriteStream , net . Socket ) ;
111
107
112
-
113
108
WriteStream . prototype . isTTY = true ;
114
109
115
110
WriteStream . prototype . getColorDepth = function ( env = process . env ) {
@@ -178,25 +173,23 @@ WriteStream.prototype.getColorDepth = function(env = process.env) {
178
173
} ;
179
174
180
175
WriteStream . prototype . _refreshSize = function ( ) {
181
- var oldCols = this . columns ;
182
- var oldRows = this . rows ;
183
- var winSize = new Array ( 2 ) ;
184
- var err = this . _handle . getWindowSize ( winSize ) ;
176
+ const oldCols = this . columns ;
177
+ const oldRows = this . rows ;
178
+ const winSize = new Array ( 2 ) ;
179
+ const err = this . _handle . getWindowSize ( winSize ) ;
185
180
if ( err ) {
186
- this . emit ( 'error' , errnoException ( err , 'getWindowSize' ) ) ;
181
+ this . emit ( 'error' , _errnoException ( err , 'getWindowSize' ) ) ;
187
182
return ;
188
183
}
189
- var newCols = winSize [ 0 ] ;
190
- var newRows = winSize [ 1 ] ;
184
+ const [ newCols , newRows ] = winSize ;
191
185
if ( oldCols !== newCols || oldRows !== newRows ) {
192
186
this . columns = newCols ;
193
187
this . rows = newRows ;
194
188
this . emit ( 'resize' ) ;
195
189
}
196
190
} ;
197
191
198
-
199
- // backwards-compat
192
+ // Backwards-compat
200
193
WriteStream . prototype . cursorTo = function ( x , y ) {
201
194
readline . cursorTo ( this , x , y ) ;
202
195
} ;
@@ -213,5 +206,4 @@ WriteStream.prototype.getWindowSize = function() {
213
206
return [ this . columns , this . rows ] ;
214
207
} ;
215
208
216
-
217
209
module . exports = { isatty, ReadStream, WriteStream } ;
0 commit comments