@@ -140,47 +140,70 @@ function REPLServer(prompt,
140
140
replMode ) ;
141
141
}
142
142
143
- var options , input , output , dom , breakEvalOnSigint ;
143
+ let options ;
144
144
if ( prompt !== null && typeof prompt === 'object' ) {
145
- // an options object was given
146
- options = prompt ;
145
+ // An options object was given.
146
+ options = { ... prompt } ;
147
147
stream = options . stream || options . socket ;
148
- input = options . input ;
149
- output = options . output ;
150
148
eval_ = options . eval ;
151
149
useGlobal = options . useGlobal ;
152
150
ignoreUndefined = options . ignoreUndefined ;
153
151
prompt = options . prompt ;
154
- dom = options . domain ;
155
152
replMode = options . replMode ;
156
- breakEvalOnSigint = options . breakEvalOnSigint ;
157
153
} else {
158
154
options = { } ;
159
155
}
160
156
161
- if ( breakEvalOnSigint && eval_ ) {
157
+ if ( ! options . input && ! options . output ) {
158
+ // Legacy API, passing a 'stream'/'socket' option.
159
+ if ( ! stream ) {
160
+ // Use stdin and stdout as the default streams if none were given.
161
+ stream = process ;
162
+ }
163
+ // We're given a duplex readable/writable Stream, like a `net.Socket`
164
+ // or a custom object with 2 streams, or the `process` object.
165
+ options . input = stream . stdin || stream ;
166
+ options . output = stream . stdout || stream ;
167
+ }
168
+
169
+ if ( options . terminal === undefined ) {
170
+ options . terminal = options . output . isTTY ;
171
+ }
172
+ options . terminal = ! ! options . terminal ;
173
+
174
+ if ( options . terminal && options . useColors === undefined ) {
175
+ // If possible, check if stdout supports colors or not.
176
+ if ( options . output . hasColors ) {
177
+ options . useColors = options . output . hasColors ( ) ;
178
+ } else if ( process . env . NODE_DISABLE_COLORS === undefined ) {
179
+ options . useColors = true ;
180
+ }
181
+ }
182
+
183
+ this . inputStream = options . input ;
184
+ this . outputStream = options . output ;
185
+ this . useColors = ! ! options . useColors ;
186
+ this . _domain = options . domain || domain . create ( ) ;
187
+ this . useGlobal = ! ! useGlobal ;
188
+ this . ignoreUndefined = ! ! ignoreUndefined ;
189
+ this . replMode = replMode || exports . REPL_MODE_SLOPPY ;
190
+ this . underscoreAssigned = false ;
191
+ this . last = undefined ;
192
+ this . underscoreErrAssigned = false ;
193
+ this . lastError = undefined ;
194
+ this . breakEvalOnSigint = ! ! options . breakEvalOnSigint ;
195
+ this . editorMode = false ;
196
+ // Context id for use with the inspector protocol.
197
+ this [ kContextId ] = undefined ;
198
+
199
+ if ( this . breakEvalOnSigint && eval_ ) {
162
200
// Allowing this would not reflect user expectations.
163
201
// breakEvalOnSigint affects only the behavior of the default eval().
164
202
throw new ERR_INVALID_REPL_EVAL_CONFIG ( ) ;
165
203
}
166
204
167
- var self = this ;
168
-
169
- self . _domain = dom || domain . create ( ) ;
170
- self . useGlobal = ! ! useGlobal ;
171
- self . ignoreUndefined = ! ! ignoreUndefined ;
172
- self . replMode = replMode || exports . REPL_MODE_SLOPPY ;
173
- self . underscoreAssigned = false ;
174
- self . last = undefined ;
175
- self . underscoreErrAssigned = false ;
176
- self . lastError = undefined ;
177
- self . breakEvalOnSigint = ! ! breakEvalOnSigint ;
178
- self . editorMode = false ;
179
- // Context id for use with the inspector protocol.
180
- self [ kContextId ] = undefined ;
181
-
182
- let rli = self ;
183
- Object . defineProperty ( self , 'rli' , {
205
+ let rli = this ;
206
+ Object . defineProperty ( this , 'rli' , {
184
207
get : util . deprecate ( ( ) => rli ,
185
208
'REPLServer.rli is deprecated' , 'DEP0124' ) ,
186
209
set : util . deprecate ( ( val ) => rli = val ,
@@ -197,6 +220,8 @@ function REPLServer(prompt,
197
220
198
221
eval_ = eval_ || defaultEval ;
199
222
223
+ const self = this ;
224
+
200
225
// Pause taking in new input, and store the keys in a buffer.
201
226
const pausedBuffer = [ ] ;
202
227
let paused = false ;
@@ -452,21 +477,6 @@ function REPLServer(prompt,
452
477
top . displayPrompt ( ) ;
453
478
} ) ;
454
479
455
- if ( ! input && ! output ) {
456
- // legacy API, passing a 'stream'/'socket' option
457
- if ( ! stream ) {
458
- // Use stdin and stdout as the default streams if none were given
459
- stream = process ;
460
- }
461
- // We're given a duplex readable/writable Stream, like a `net.Socket`
462
- // or a custom object with 2 streams, or the `process` object
463
- input = stream . stdin || stream ;
464
- output = stream . stdout || stream ;
465
- }
466
-
467
- self . inputStream = input ;
468
- self . outputStream = output ;
469
-
470
480
self . resetContext ( ) ;
471
481
self . lines . level = [ ] ;
472
482
@@ -503,13 +513,6 @@ function REPLServer(prompt,
503
513
// Figure out which "writer" function to use
504
514
self . writer = options . writer || exports . writer ;
505
515
506
- if ( options . useColors === undefined ) {
507
- options . useColors = self . terminal && (
508
- typeof self . outputStream . getColorDepth === 'function' ?
509
- self . outputStream . getColorDepth ( ) > 1 : true ) ;
510
- }
511
- self . useColors = ! ! options . useColors ;
512
-
513
516
if ( self . writer === writer ) {
514
517
// Conditionally turn on ANSI coloring.
515
518
writer . options . colors = self . useColors ;
0 commit comments