mirror of
https://github.com/samsonjs/repl-edit.git
synced 2026-03-25 09:25:49 +00:00
Clean up temp file on exit, updated readme
This commit is contained in:
parent
6b5cb82723
commit
ff812e2265
2 changed files with 22 additions and 5 deletions
|
|
@ -13,8 +13,10 @@ npm install repl-edit
|
|||
Usage
|
||||
=====
|
||||
|
||||
You can fire up a repl with editing capabilities by running `node-repl-edit`
|
||||
or extend an existing repl session by typing `require('repl-edit').extend(global)`.
|
||||
You can fire up a repl with editing capabilities by running `node-repl-edit`.
|
||||
|
||||
(It would be nice to extend an existing repl session but that's not possible with
|
||||
Node's repl module right now.)
|
||||
|
||||
|
||||
Commands
|
||||
|
|
@ -63,6 +65,9 @@ capability to provide commands like `.edit` and `.stash <filename>`.
|
|||
The first time edit() is run in a repl instead of an empty file the command should be seeded
|
||||
with the last command that was executed.
|
||||
|
||||
If the native repl module exports the currently running repl object it will be possible to attach
|
||||
to an existing repl instead of having to run a separate binary that loads a repl.
|
||||
|
||||
|
||||
License
|
||||
=======
|
||||
|
|
|
|||
18
lib/index.js
18
lib/index.js
|
|
@ -5,9 +5,10 @@
|
|||
// github.com/samsonjs/repl-edit
|
||||
//
|
||||
|
||||
// TODO proper error handling
|
||||
// TODO proper error handling, better intregration with node/lib/repl.js
|
||||
|
||||
var fs = require('fs')
|
||||
, repl = require('repl')
|
||||
, _repl
|
||||
|
||||
exports.startRepl = function() {
|
||||
|
|
@ -15,7 +16,8 @@ exports.startRepl = function() {
|
|||
// TODO extend the repl context instead, problem is that repl.js:resetContext() isn't exported
|
||||
// so simple assignments to _repl.context can't survive .clear yet
|
||||
exports.extend(global)
|
||||
_repl = require('repl').start()
|
||||
_repl = repl.start()
|
||||
return exports
|
||||
}
|
||||
|
||||
exports.extend = function(obj) {
|
||||
|
|
@ -91,6 +93,16 @@ exports.extend = function(obj) {
|
|||
sys.pump(read, fs.createWriteStream(_tmpfile))
|
||||
})
|
||||
}
|
||||
|
||||
process.on('exit', function() {
|
||||
try {
|
||||
fs.unlinkSync(_tmpfile)
|
||||
} catch (e) {
|
||||
// might not exist
|
||||
}
|
||||
})
|
||||
|
||||
return exports
|
||||
}
|
||||
|
||||
function pausingRepl(fn) {
|
||||
|
|
@ -105,7 +117,7 @@ function pausingRepl(fn) {
|
|||
_repl.displayPrompt()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function runFile(filename, callback) {
|
||||
var Script = process.binding('evals').Script
|
||||
, evalcx = Script.runInContext
|
||||
|
|
|
|||
Loading…
Reference in a new issue