mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
740 B
26 lines
740 B
var spawn = require('child_process').spawn;
|
|
|
|
module.exports = function (file, opts, cb) {
|
|
if (typeof opts === 'function') {
|
|
cb = opts;
|
|
opts = {};
|
|
}
|
|
if (!opts) opts = {};
|
|
|
|
var ed = /^win/.test(process.platform) ? 'notepad' : 'vim';
|
|
var editor = opts.editor || process.env.VISUAL || process.env.EDITOR || ed;
|
|
|
|
setRaw(true);
|
|
var ps = spawn(editor, [ file ], { customFds : [ 0, 1, 2 ] });
|
|
|
|
ps.on('exit', function (code, sig) {
|
|
setRaw(false);
|
|
process.stdin.pause();
|
|
if (typeof cb === 'function') cb(code, sig)
|
|
});
|
|
};
|
|
|
|
var tty = require('tty');
|
|
function setRaw (mode) {
|
|
process.stdin.setRawMode ? process.stdin.setRawMode(mode) : tty.setRawMode(mode);
|
|
}
|
|
|