readline: use module.exports = {}

PR-URL: https://github.com/nodejs/node/pull/12755
Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
James M Snell 2017-04-29 13:33:35 -07:00 committed by Anna Henningsen
parent a398516b4f
commit 9318f82937
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF

View File

@ -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);
};
@ -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);
@ -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;
@ -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();
@ -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;
@ -957,10 +957,6 @@ Interface.prototype._ttyWrite = function(s, key) {
}
};
exports.Interface = Interface;
/**
* accepts a readable Stream instance and makes it emit "keypress" events
*/
@ -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
@ -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
@ -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:
@ -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
@ -1120,4 +1108,13 @@ function clearScreenDown(stream) {
stream.write('\x1b[0J');
}
exports.clearScreenDown = clearScreenDown;
module.exports = {
Interface,
clearLine,
clearScreenDown,
createInterface,
cursorTo,
emitKeypressEvents,
moveCursor
};