Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: revert stdin handling #1393

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions lib/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,56 +95,50 @@ function nodemon(settings) {
utils.log.detail('reading config ' + file);
});

// echo out notices about running state
if (config.options.stdin) {
if (config.options.stdin && config.options.restartable) {
// allow nodemon to restart when the use types 'rs\n'
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', data => {
const str = data.toString().trim().toLowerCase();

// if the keys entered match the restartable value, then restart!
if (str === config.options.restartable) {
bus.emit('restart');
} else if (data.charCodeAt(0) === 12) { // ctrl+l
console.clear();
}
});
} else if (config.options.stdin) {
// so let's make sure we don't eat the key presses
// but also, since we're wrapping, watch out for
// special keys, like ctrl+c x 2 or '.exit' or ctrl+d or ctrl+l
var ctrlC = false;
var buffer = '';
const rs = config.options.restartable;

process.stdin.setEncoding('utf8');
process.stdin.on('data', function (data) {
data = data.toString();
buffer += data;
const chr = data.charCodeAt(0);

// if restartable, echo back
if (rs) {
if (chr === 13) {
process.stdout.write('\n');
}
// this intentionally prevents cursor keys from working.
process.stdout.write(String.fromCharCode(chr));
}

if (chr === 3) {
if (ctrlC) {
process.exit(0);
}

// if restartable, assume ctrl+c will break immediately
if (rs) {
bus.emit('quit', 130);
}
ctrlC = true;
return;
} else if (!rs && (buffer === '.exit' || chr === 4)) { // ctrl+d
} else if (buffer === '.exit' || chr === 4) { // ctrl+d
process.exit();
} else if (chr === 13 || chr === 10) { // enter / carriage return
const input = buffer.toString().trim().toLowerCase();
if (input === rs) {
bus.emit('restart');
}
buffer = '';
} else if (chr === 12) { // ctrl+l
console.clear();
buffer = '';
}
ctrlC = false;
});
process.stdin.resume();
if (process.stdin.setRawMode) {
process.stdin.setRawMode(true);
}
Expand Down