Skip to content

Commit

Permalink
readline: use module.exports = {}
Browse files Browse the repository at this point in the history
PR-URL: #12755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
jasnell authored and addaleax committed May 7, 2017
1 parent a398516 commit 9318f82
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions lib/readline.js
Expand Up @@ -43,7 +43,7 @@ const isFullWidthCodePoint = internalReadline.isFullWidthCodePoint;
const stripVTControlCharacters = internalReadline.stripVTControlCharacters;


exports.createInterface = function(input, output, completer, terminal) {
function createInterface(input, output, completer, terminal) {
return new Interface(input, output, completer, terminal);
};

Expand Down Expand Up @@ -311,13 +311,13 @@ Interface.prototype._refreshLine = function() {
// first move to the bottom of the current line, based on cursor pos
var prevRows = this.prevRows || 0;
if (prevRows > 0) {
exports.moveCursor(this.output, 0, -prevRows);
moveCursor(this.output, 0, -prevRows);
}

// Cursor to left edge.
exports.cursorTo(this.output, 0);
cursorTo(this.output, 0);
// erase data
exports.clearScreenDown(this.output);
clearScreenDown(this.output);

// Write the prompt and the current buffer content.
this._writeToOutput(line);
Expand All @@ -328,11 +328,11 @@ Interface.prototype._refreshLine = function() {
}

// Move cursor to original position.
exports.cursorTo(this.output, cursorPos.cols);
cursorTo(this.output, cursorPos.cols);

var diff = lineRows - cursorPos.rows;
if (diff > 0) {
exports.moveCursor(this.output, 0, -diff);
moveCursor(this.output, 0, -diff);
}

this.prevRows = cursorPos.rows;
Expand Down Expand Up @@ -716,7 +716,7 @@ Interface.prototype._moveCursor = function(dx) {
this.line.substring(this.cursor, oldcursor)
);
}
exports.moveCursor(this.output, diffWidth, 0);
moveCursor(this.output, diffWidth, 0);
this.prevRows = newPos.rows;
} else {
this._refreshLine();
Expand Down Expand Up @@ -798,8 +798,8 @@ Interface.prototype._ttyWrite = function(s, key) {
break;

case 'l': // clear the whole screen
exports.cursorTo(this.output, 0, 0);
exports.clearScreenDown(this.output);
cursorTo(this.output, 0, 0);
clearScreenDown(this.output);
this._refreshLine();
break;

Expand Down Expand Up @@ -957,10 +957,6 @@ Interface.prototype._ttyWrite = function(s, key) {
}
};


exports.Interface = Interface;


/**
* accepts a readable Stream instance and makes it emit "keypress" events
*/
Expand Down Expand Up @@ -1036,8 +1032,6 @@ function emitKeypressEvents(stream, iface) {
stream.on('newListener', onNewListener);
}
}
exports.emitKeypressEvents = emitKeypressEvents;


/**
* moves the cursor to the x and y coordinate on the given stream
Expand All @@ -1059,8 +1053,6 @@ function cursorTo(stream, x, y) {
stream.write('\x1b[' + (y + 1) + ';' + (x + 1) + 'H');
}
}
exports.cursorTo = cursorTo;


/**
* moves the cursor relative to its current location
Expand All @@ -1082,8 +1074,6 @@ function moveCursor(stream, dx, dy) {
stream.write('\x1b[' + dy + 'B');
}
}
exports.moveCursor = moveCursor;


/**
* clears the current line the cursor is on:
Expand All @@ -1107,8 +1097,6 @@ function clearLine(stream, dir) {
stream.write('\x1b[2K');
}
}
exports.clearLine = clearLine;


/**
* clears the screen from the current position of the cursor down
Expand All @@ -1120,4 +1108,13 @@ function clearScreenDown(stream) {

stream.write('\x1b[0J');
}
exports.clearScreenDown = clearScreenDown;

module.exports = {
Interface,
clearLine,
clearScreenDown,
createInterface,
cursorTo,
emitKeypressEvents,
moveCursor
};

0 comments on commit 9318f82

Please sign in to comment.