From ff812e22651ec2b7584484d441e4897cbf88f317 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Fri, 24 Sep 2010 09:53:18 -0700 Subject: [PATCH] Clean up temp file on exit, updated readme --- Readme.md | 9 +++++++-- lib/index.js | 18 +++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/Readme.md b/Readme.md index f3251ca..3d72e59 100644 --- a/Readme.md +++ b/Readme.md @@ -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 `. 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 ======= diff --git a/lib/index.js b/lib/index.js index 58bfbbc..6b62414 100644 --- a/lib/index.js +++ b/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