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:
parent
a398516b4f
commit
9318f82937
@ -43,7 +43,7 @@ const isFullWidthCodePoint = internalReadline.isFullWidthCodePoint;
|
|||||||
const stripVTControlCharacters = internalReadline.stripVTControlCharacters;
|
const stripVTControlCharacters = internalReadline.stripVTControlCharacters;
|
||||||
|
|
||||||
|
|
||||||
exports.createInterface = function(input, output, completer, terminal) {
|
function createInterface(input, output, completer, terminal) {
|
||||||
return new Interface(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
|
// first move to the bottom of the current line, based on cursor pos
|
||||||
var prevRows = this.prevRows || 0;
|
var prevRows = this.prevRows || 0;
|
||||||
if (prevRows > 0) {
|
if (prevRows > 0) {
|
||||||
exports.moveCursor(this.output, 0, -prevRows);
|
moveCursor(this.output, 0, -prevRows);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Cursor to left edge.
|
// Cursor to left edge.
|
||||||
exports.cursorTo(this.output, 0);
|
cursorTo(this.output, 0);
|
||||||
// erase data
|
// erase data
|
||||||
exports.clearScreenDown(this.output);
|
clearScreenDown(this.output);
|
||||||
|
|
||||||
// Write the prompt and the current buffer content.
|
// Write the prompt and the current buffer content.
|
||||||
this._writeToOutput(line);
|
this._writeToOutput(line);
|
||||||
@ -328,11 +328,11 @@ Interface.prototype._refreshLine = function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Move cursor to original position.
|
// Move cursor to original position.
|
||||||
exports.cursorTo(this.output, cursorPos.cols);
|
cursorTo(this.output, cursorPos.cols);
|
||||||
|
|
||||||
var diff = lineRows - cursorPos.rows;
|
var diff = lineRows - cursorPos.rows;
|
||||||
if (diff > 0) {
|
if (diff > 0) {
|
||||||
exports.moveCursor(this.output, 0, -diff);
|
moveCursor(this.output, 0, -diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.prevRows = cursorPos.rows;
|
this.prevRows = cursorPos.rows;
|
||||||
@ -716,7 +716,7 @@ Interface.prototype._moveCursor = function(dx) {
|
|||||||
this.line.substring(this.cursor, oldcursor)
|
this.line.substring(this.cursor, oldcursor)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
exports.moveCursor(this.output, diffWidth, 0);
|
moveCursor(this.output, diffWidth, 0);
|
||||||
this.prevRows = newPos.rows;
|
this.prevRows = newPos.rows;
|
||||||
} else {
|
} else {
|
||||||
this._refreshLine();
|
this._refreshLine();
|
||||||
@ -798,8 +798,8 @@ Interface.prototype._ttyWrite = function(s, key) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'l': // clear the whole screen
|
case 'l': // clear the whole screen
|
||||||
exports.cursorTo(this.output, 0, 0);
|
cursorTo(this.output, 0, 0);
|
||||||
exports.clearScreenDown(this.output);
|
clearScreenDown(this.output);
|
||||||
this._refreshLine();
|
this._refreshLine();
|
||||||
break;
|
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
|
* accepts a readable Stream instance and makes it emit "keypress" events
|
||||||
*/
|
*/
|
||||||
@ -1036,8 +1032,6 @@ function emitKeypressEvents(stream, iface) {
|
|||||||
stream.on('newListener', onNewListener);
|
stream.on('newListener', onNewListener);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.emitKeypressEvents = emitKeypressEvents;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* moves the cursor to the x and y coordinate on the given stream
|
* 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');
|
stream.write('\x1b[' + (y + 1) + ';' + (x + 1) + 'H');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.cursorTo = cursorTo;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* moves the cursor relative to its current location
|
* moves the cursor relative to its current location
|
||||||
@ -1082,8 +1074,6 @@ function moveCursor(stream, dx, dy) {
|
|||||||
stream.write('\x1b[' + dy + 'B');
|
stream.write('\x1b[' + dy + 'B');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.moveCursor = moveCursor;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clears the current line the cursor is on:
|
* clears the current line the cursor is on:
|
||||||
@ -1107,8 +1097,6 @@ function clearLine(stream, dir) {
|
|||||||
stream.write('\x1b[2K');
|
stream.write('\x1b[2K');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.clearLine = clearLine;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* clears the screen from the current position of the cursor down
|
* clears the screen from the current position of the cursor down
|
||||||
@ -1120,4 +1108,13 @@ function clearScreenDown(stream) {
|
|||||||
|
|
||||||
stream.write('\x1b[0J');
|
stream.write('\x1b[0J');
|
||||||
}
|
}
|
||||||
exports.clearScreenDown = clearScreenDown;
|
|
||||||
|
module.exports = {
|
||||||
|
Interface,
|
||||||
|
clearLine,
|
||||||
|
clearScreenDown,
|
||||||
|
createInterface,
|
||||||
|
cursorTo,
|
||||||
|
emitKeypressEvents,
|
||||||
|
moveCursor
|
||||||
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user