mirror of
https://github.com/samsonjs/repl-edit.git
synced 2026-03-27 09:45:51 +00:00
Compare commits
2 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
332bef8c07 | ||
|
|
b9469be9b7 |
2 changed files with 11 additions and 9 deletions
18
lib/index.js
18
lib/index.js
|
|
@ -39,24 +39,26 @@ exports.extend = function(obj) {
|
||||||
, _tmpfile = path.join(_tmpdir, 'node-repl-' + process.pid + '.js')
|
, _tmpfile = path.join(_tmpdir, 'node-repl-' + process.pid + '.js')
|
||||||
|
|
||||||
obj.edit = function(editor) {
|
obj.edit = function(editor) {
|
||||||
editor = editor || process.ENV['EDITOR']
|
editor = editor || process.ENV['VISUAL'] || process.ENV['EDITOR']
|
||||||
// TODO seed the file with _repl.context._ if the file doesn't exist yet
|
// TODO seed the file with _repl.context._ if the file doesn't exist yet
|
||||||
pausingRepl(function(unpause) {
|
pausingRepl(function(unpause) {
|
||||||
var fds = [process.openStdin(), process.stdout, process.stdout]
|
var fds = [process.openStdin(), process.stdout, process.stdout]
|
||||||
, args = [_tmpfile]
|
, args = [_tmpfile]
|
||||||
// handle things like 'mate -w' and 'emacsclient --server-file <filename>'
|
// handle things like 'mate -w' and 'emacsclient --server-file <filename>'
|
||||||
if (editor.match(/\s/)) {
|
if (editor.match(/\s/)) {
|
||||||
var words = editor.split(/\s+/)
|
var words = editor.split(/\s+/) // FIXME this should do proper word splitting ...
|
||||||
args = words.slice(1).concat(args)
|
args = words.slice(1).concat(args)
|
||||||
editor = words[0]
|
editor = words[0]
|
||||||
}
|
}
|
||||||
spawn(editor, args, {customFds: fds}).on('exit', function(code) {
|
spawn(editor, args, {customFds: fds}).on('exit', function(code) {
|
||||||
// FIXME figure out why obj.run doesn't work properly here (output is skewed)
|
// some editors change the terminal resulting in skewed output, clean up
|
||||||
if (code === 0) {
|
spawn('reset').on('exit', function(_) {
|
||||||
runFile(_tmpfile, function() { unpause() })
|
if (code === 0) {
|
||||||
} else {
|
runFile(_tmpfile, function() { unpause() })
|
||||||
unpause()
|
} else {
|
||||||
}
|
unpause()
|
||||||
|
}
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{ "name" : "repl-edit"
|
{ "name" : "repl-edit"
|
||||||
, "description" : "Edit code in the repl using a real text editor"
|
, "description" : "Edit code in the repl using a real text editor"
|
||||||
, "version" : "0.0.2"
|
, "version" : "0.0.3"
|
||||||
, "homepage" : "http://samhuri.net/node/repl-edit"
|
, "homepage" : "http://samhuri.net/node/repl-edit"
|
||||||
, "author" : "Sami Samhuri <sami@samhuri.net>"
|
, "author" : "Sami Samhuri <sami@samhuri.net>"
|
||||||
, "repository" :
|
, "repository" :
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue