Add writeFilter when in the readline
Switch \n with \r\n for all strings printed out. Necessary for writev patch.
This commit is contained in:
parent
c7b24efd21
commit
d4af8a6b6a
@ -17,6 +17,20 @@ exports.createInterface = function (output, completer) {
|
|||||||
return new Interface(output, completer);
|
return new Interface(output, completer);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function writeFilter (stream) {
|
||||||
|
if (stream._writeFiltered) return;
|
||||||
|
stream._writeFiltered = true;
|
||||||
|
stream._normalWrite = stream.write;
|
||||||
|
stream.write = function (d) {
|
||||||
|
var args = Array.prototype.slice.call(arguments);
|
||||||
|
if (typeof d == 'string') {
|
||||||
|
args[0] = d.replace(/([^\r])\n|^\n/g, '$1\r\n');
|
||||||
|
}
|
||||||
|
// TODO what about buffers?
|
||||||
|
return stream._normalWrite.apply(stream, args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Interface (output, completer) {
|
function Interface (output, completer) {
|
||||||
if (!(this instanceof Interface)) return new Interface(output, completer);
|
if (!(this instanceof Interface)) return new Interface(output, completer);
|
||||||
EventEmitter.call(this);
|
EventEmitter.call(this);
|
||||||
@ -35,6 +49,9 @@ function Interface (output, completer) {
|
|||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
// input refers to stdin
|
// input refers to stdin
|
||||||
|
|
||||||
|
writeFilter(this.output);
|
||||||
|
writeFilter(process.stdout);
|
||||||
|
|
||||||
// Current line
|
// Current line
|
||||||
this.line = "";
|
this.line = "";
|
||||||
|
|
||||||
@ -99,8 +116,6 @@ Interface.prototype._addHistory = function () {
|
|||||||
Interface.prototype._refreshLine = function () {
|
Interface.prototype._refreshLine = function () {
|
||||||
if (this._closed) return;
|
if (this._closed) return;
|
||||||
|
|
||||||
stdio.setRawMode(true);
|
|
||||||
|
|
||||||
// Cursor to left edge.
|
// Cursor to left edge.
|
||||||
this.output.write('\x1b[0G');
|
this.output.write('\x1b[0G');
|
||||||
|
|
||||||
@ -288,8 +303,7 @@ Interface.prototype._ttyWrite = function (b) {
|
|||||||
|
|
||||||
case 13: /* enter */
|
case 13: /* enter */
|
||||||
var line = this._addHistory();
|
var line = this._addHistory();
|
||||||
this.output.write('\n\x1b[0G');
|
this.output.write('\r\n');
|
||||||
stdio.setRawMode(false);
|
|
||||||
this.emit('line', line);
|
this.emit('line', line);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user