readline: move the "setRawMode" logic into a private function

This commit is contained in:
Nathan Rajlich 2012-05-21 19:41:56 -03:00
parent 45de259b43
commit 2b9967fbcc

View File

@ -108,9 +108,7 @@ function Interface(input, output, completer, terminal) {
// Current line
this.line = '';
if (typeof input.setRawMode === 'function') {
input.setRawMode(true);
}
this._setRawMode(true);
this.terminal = true;
// Cursor position on the line.
@ -143,6 +141,13 @@ Interface.prototype.setPrompt = function(prompt, length) {
};
Interface.prototype._setRawMode = function(mode) {
if (typeof this.input.setRawMode === 'function') {
return this.input.setRawMode(mode);
}
}
Interface.prototype.prompt = function(preserveCursor) {
if (this.paused) this.resume();
if (this.terminal) {
@ -239,9 +244,7 @@ Interface.prototype._refreshLine = function() {
Interface.prototype.close = function() {
if (this.closed) return;
if (this.terminal) {
if (typeof this.input.setRawMode === 'function') {
this.input.setRawMode(false);
}
this._setRawMode(false);
}
this.pause();
this.closed = true;