From 2b9967fbcc560c2b2185fee19f82ea8b9902c644 Mon Sep 17 00:00:00 2001 From: Nathan Rajlich Date: Mon, 21 May 2012 19:41:56 -0300 Subject: [PATCH] readline: move the "setRawMode" logic into a private function --- lib/readline.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/readline.js b/lib/readline.js index 9bca13a727f..2de74397be6 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -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;