mirror of
https://github.com/samsonjs/repl-edit.git
synced 2026-03-25 09:25:49 +00:00
Use VISUAL, and run reset after the editor exits (fixes display bugs)
This commit is contained in:
parent
da81c0808c
commit
b9469be9b7
1 changed files with 10 additions and 8 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')
|
||||
|
||||
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
|
||||
pausingRepl(function(unpause) {
|
||||
var fds = [process.openStdin(), process.stdout, process.stdout]
|
||||
, args = [_tmpfile]
|
||||
// handle things like 'mate -w' and 'emacsclient --server-file <filename>'
|
||||
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)
|
||||
editor = words[0]
|
||||
}
|
||||
spawn(editor, args, {customFds: fds}).on('exit', function(code) {
|
||||
// FIXME figure out why obj.run doesn't work properly here (output is skewed)
|
||||
if (code === 0) {
|
||||
runFile(_tmpfile, function() { unpause() })
|
||||
} else {
|
||||
unpause()
|
||||
}
|
||||
// some editors change the terminal resulting in skewed output, clean up
|
||||
spawn('reset').on('exit', function(_) {
|
||||
if (code === 0) {
|
||||
runFile(_tmpfile, function() { unpause() })
|
||||
} else {
|
||||
unpause()
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue