@@ -48,7 +48,6 @@ var path = require('path');
48
48
var fs = require ( 'fs' ) ;
49
49
var rl = require ( 'readline' ) ;
50
50
var Console = require ( 'console' ) . Console ;
51
- var EventEmitter = require ( 'events' ) . EventEmitter ;
52
51
var domain = require ( 'domain' ) ;
53
52
var debug = util . debuglog ( 'repl' ) ;
54
53
@@ -82,8 +81,6 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
82
81
return new REPLServer ( prompt , stream , eval_ , useGlobal , ignoreUndefined ) ;
83
82
}
84
83
85
- EventEmitter . call ( this ) ;
86
-
87
84
var options , input , output , dom ;
88
85
if ( util . isObject ( prompt ) ) {
89
86
// an options object was given
@@ -109,6 +106,9 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
109
106
self . useGlobal = ! ! useGlobal ;
110
107
self . ignoreUndefined = ! ! ignoreUndefined ;
111
108
109
+ // just for backwards compat, see github.com/joyent/node/pull/7127
110
+ self . rli = this ;
111
+
112
112
eval_ = eval_ || defaultEval ;
113
113
114
114
function defaultEval ( code , context , file , cb ) {
@@ -179,19 +179,18 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
179
179
self . bufferedCommand = '' ;
180
180
self . lines . level = [ ] ;
181
181
182
- self . prompt = ! util . isUndefined ( prompt ) ? prompt : '> ' ;
183
-
184
182
function complete ( text , callback ) {
185
183
self . complete ( text , callback ) ;
186
184
}
187
185
188
- var rli = rl . createInterface ( {
189
- input : self . inputStream ,
190
- output : self . outputStream ,
191
- completer : complete ,
192
- terminal : options . terminal
193
- } ) ;
194
- self . rli = rli ;
186
+ rl . Interface . apply ( this , [
187
+ self . inputStream ,
188
+ self . outputStream ,
189
+ complete ,
190
+ options . terminal
191
+ ] )
192
+
193
+ self . setPrompt ( ! util . isUndefined ( prompt ) ? prompt : '> ' ) ;
195
194
196
195
this . commands = { } ;
197
196
defineDefaultCommands ( this ) ;
@@ -200,7 +199,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
200
199
self . writer = options . writer || exports . writer ;
201
200
202
201
if ( util . isUndefined ( options . useColors ) ) {
203
- options . useColors = rli . terminal ;
202
+ options . useColors = self . terminal ;
204
203
}
205
204
self . useColors = ! ! options . useColors ;
206
205
@@ -211,24 +210,24 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
211
210
} ;
212
211
}
213
212
214
- rli . setPrompt ( self . prompt ) ;
213
+ self . setPrompt ( self . _prompt ) ;
215
214
216
- rli . on ( 'close' , function ( ) {
215
+ self . on ( 'close' , function ( ) {
217
216
self . emit ( 'exit' ) ;
218
217
} ) ;
219
218
220
219
var sawSIGINT = false ;
221
- rli . on ( 'SIGINT' , function ( ) {
222
- var empty = rli . line . length === 0 ;
223
- rli . clearLine ( ) ;
220
+ self . on ( 'SIGINT' , function ( ) {
221
+ var empty = self . line . length === 0 ;
222
+ self . clearLine ( ) ;
224
223
225
224
if ( ! ( self . bufferedCommand && self . bufferedCommand . length > 0 ) && empty ) {
226
225
if ( sawSIGINT ) {
227
- rli . close ( ) ;
226
+ self . close ( ) ;
228
227
sawSIGINT = false ;
229
228
return ;
230
229
}
231
- rli . output . write ( '(^C again to quit)\n' ) ;
230
+ self . output . write ( '(^C again to quit)\n' ) ;
232
231
sawSIGINT = true ;
233
232
} else {
234
233
sawSIGINT = false ;
@@ -239,7 +238,7 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
239
238
self . displayPrompt ( ) ;
240
239
} ) ;
241
240
242
- rli . on ( 'line' , function ( cmd ) {
241
+ self . on ( 'line' , function ( cmd ) {
243
242
debug ( 'line %j' , cmd ) ;
244
243
sawSIGINT = false ;
245
244
var skipCatchall = false ;
@@ -322,13 +321,13 @@ function REPLServer(prompt, stream, eval_, useGlobal, ignoreUndefined) {
322
321
} ;
323
322
} ) ;
324
323
325
- rli . on ( 'SIGCONT' , function ( ) {
324
+ self . on ( 'SIGCONT' , function ( ) {
326
325
self . displayPrompt ( true ) ;
327
326
} ) ;
328
327
329
328
self . displayPrompt ( ) ;
330
329
}
331
- inherits ( REPLServer , EventEmitter ) ;
330
+ inherits ( REPLServer , rl . Interface ) ;
332
331
exports . REPLServer = REPLServer ;
333
332
334
333
@@ -340,7 +339,6 @@ exports.start = function(prompt, source, eval_, useGlobal, ignoreUndefined) {
340
339
return repl ;
341
340
} ;
342
341
343
-
344
342
REPLServer . prototype . createContext = function ( ) {
345
343
var context ;
346
344
if ( this . useGlobal ) {
@@ -388,17 +386,17 @@ REPLServer.prototype.resetContext = function() {
388
386
} ;
389
387
390
388
REPLServer . prototype . displayPrompt = function ( preserveCursor ) {
391
- var prompt = this . prompt ;
389
+ var prompt = this . _prompt ;
392
390
if ( this . bufferedCommand . length ) {
393
391
prompt = '...' ;
394
392
var levelInd = new Array ( this . lines . level . length ) . join ( '..' ) ;
395
393
prompt += levelInd + ' ' ;
394
+ } else {
395
+ this . setPrompt ( prompt ) ;
396
396
}
397
- this . rli . setPrompt ( prompt ) ;
398
- this . rli . prompt ( preserveCursor ) ;
397
+ this . prompt ( preserveCursor ) ;
399
398
} ;
400
399
401
-
402
400
// A stream to push an array into a REPL
403
401
// used in REPLServer.complete
404
402
function ArrayStream ( ) {
@@ -838,7 +836,7 @@ function defineDefaultCommands(repl) {
838
836
repl . defineCommand ( 'exit' , {
839
837
help : 'Exit the repl' ,
840
838
action : function ( ) {
841
- this . rli . close ( ) ;
839
+ this . close ( ) ;
842
840
}
843
841
} ) ;
844
842
@@ -879,7 +877,7 @@ function defineDefaultCommands(repl) {
879
877
this . displayPrompt ( ) ;
880
878
lines . forEach ( function ( line ) {
881
879
if ( line ) {
882
- self . rli . write ( line + '\n' ) ;
880
+ self . write ( line + '\n' ) ;
883
881
}
884
882
} ) ;
885
883
}
0 commit comments