Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Readline bugfix, and proposal. #2737

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/readline.js
Expand Up @@ -126,6 +126,7 @@ Interface.prototype.setPrompt = function(prompt, length) {


Interface.prototype.prompt = function(preserveCursor) {
if (this._closed) this.resume();
if (this.enabled) {
if (!preserveCursor) this.cursor = 0;
this._refreshLine();
Expand All @@ -136,7 +137,7 @@ Interface.prototype.prompt = function(preserveCursor) {


Interface.prototype.question = function(query, cb) {
if (cb) {
if (typeof cb === 'function') {
this.resume();
if (this._questionCallback) {
this.output.write('\n');
Expand All @@ -153,6 +154,7 @@ Interface.prototype.question = function(query, cb) {


Interface.prototype._onLine = function(line) {
if (this._closed) return;
if (this._questionCallback) {
var cb = this._questionCallback;
this._questionCallback = null;
Expand All @@ -165,6 +167,7 @@ Interface.prototype._onLine = function(line) {


Interface.prototype._addHistory = function() {
if (this._closed) return;
if (this.line.length === 0) return '';

this.history.unshift(this.line);
Expand Down Expand Up @@ -204,8 +207,8 @@ Interface.prototype.close = function(d) {
if (this.enabled) {
tty.setRawMode(false);
}
this.emit('close');
this._closed = true;
this.emit('close');
};


Expand All @@ -220,6 +223,8 @@ Interface.prototype.resume = function() {
if (this.enabled) {
tty.setRawMode(true);
}
this._closing = false;
this._closed = false;
};


Expand Down Expand Up @@ -466,6 +471,8 @@ Interface.prototype._attemptClose = function() {

// handle a write from the tty
Interface.prototype._ttyWrite = function(s, key) {
if (this._closed) return;

var next_word, next_non_word, previous_word, previous_non_word;
key = key || {};

Expand Down