|
@ -135,7 +135,36 @@ Interface.prototype._normalWrite = function (b) { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Interface.prototype._historyNext = function () { |
|
|
|
|
|
if (this.historyIndex > 0) { |
|
|
|
|
|
this.historyIndex--; |
|
|
|
|
|
this.history[this.historyIndex].copy(this.buf, 0); |
|
|
|
|
|
this.buf.used = this.history[this.historyIndex].length; |
|
|
|
|
|
// set cursor to end of line.
|
|
|
|
|
|
this.cursor = this.buf.used; |
|
|
|
|
|
this._refreshLine(); |
|
|
|
|
|
|
|
|
|
|
|
} else if (this.historyIndex === 0) { |
|
|
|
|
|
this.historyIndex = -1; |
|
|
|
|
|
this.cursor = 0; |
|
|
|
|
|
this.buf.used = 0; |
|
|
|
|
|
this._refreshLine(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
Interface.prototype._historyPrev = function () { |
|
|
|
|
|
if (this.historyIndex + 1 < this.history.length) { |
|
|
|
|
|
this.historyIndex++; |
|
|
|
|
|
this.history[this.historyIndex].copy(this.buf, 0); |
|
|
|
|
|
this.buf.used = this.history[this.historyIndex].length; |
|
|
|
|
|
// set cursor to end of line.
|
|
|
|
|
|
this.cursor = this.buf.used; |
|
|
|
|
|
|
|
|
|
|
|
this._refreshLine(); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// handle a write from the tty
|
|
|
Interface.prototype._ttyWrite = function (b) { |
|
|
Interface.prototype._ttyWrite = function (b) { |
|
|
switch (b[0]) { |
|
|
switch (b[0]) { |
|
|
/* ctrl+c */ |
|
|
/* ctrl+c */ |
|
@ -144,8 +173,16 @@ Interface.prototype._ttyWrite = function (b) { |
|
|
this.close(); |
|
|
this.close(); |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 4: /* ctrl+d */ |
|
|
case 4: // control-d, delete right or EOF
|
|
|
|
|
|
if (this.cursor === 0 && this.buf.used === 0) { |
|
|
this.close(); |
|
|
this.close(); |
|
|
|
|
|
} else if (this.cursor < this.buf.used) { |
|
|
|
|
|
for (var i = this.cursor; i < this.buf.used; i++) { |
|
|
|
|
|
this.buf[i] = this.buf[i+1]; |
|
|
|
|
|
} |
|
|
|
|
|
this.buf.used--; |
|
|
|
|
|
this._refreshLine(); |
|
|
|
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 13: /* enter */ |
|
|
case 13: /* enter */ |
|
@ -187,47 +224,47 @@ Interface.prototype._ttyWrite = function (b) { |
|
|
this._refreshLine(); |
|
|
this._refreshLine(); |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|
case 27: /* escape sequence */ |
|
|
case 2: // control-b, back one character
|
|
|
if (b[1] === 91 && b[2] === 68) { |
|
|
|
|
|
// left arrow
|
|
|
|
|
|
if (this.cursor > 0) { |
|
|
if (this.cursor > 0) { |
|
|
this.cursor--; |
|
|
this.cursor--; |
|
|
this._refreshLine(); |
|
|
this._refreshLine(); |
|
|
} |
|
|
} |
|
|
} else if (b[1] === 91 && b[2] === 67) { |
|
|
break; |
|
|
// right arrow
|
|
|
|
|
|
|
|
|
case 6: // control-f, forward one character
|
|
|
if (this.cursor != this.buf.used) { |
|
|
if (this.cursor != this.buf.used) { |
|
|
this.cursor++; |
|
|
this.cursor++; |
|
|
this._refreshLine(); |
|
|
this._refreshLine(); |
|
|
} |
|
|
} |
|
|
} else if (b[1] === 91 && b[2] === 65) { |
|
|
break; |
|
|
// up arrow
|
|
|
|
|
|
if (this.historyIndex + 1 < this.history.length) { |
|
|
|
|
|
this.historyIndex++; |
|
|
|
|
|
this.history[this.historyIndex].copy(this.buf, 0); |
|
|
|
|
|
this.buf.used = this.history[this.historyIndex].length; |
|
|
|
|
|
// set cursor to end of line.
|
|
|
|
|
|
this.cursor = this.buf.used; |
|
|
|
|
|
|
|
|
|
|
|
this._refreshLine(); |
|
|
case 14: // control-n, next history item
|
|
|
} |
|
|
this._historyNext(); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
} else if (b[1] === 91 && b[2] === 66) { |
|
|
case 16: // control-p, previous history item
|
|
|
// down arrow
|
|
|
this._historyPrev(); |
|
|
if (this.historyIndex > 0) { |
|
|
break; |
|
|
this.historyIndex--; |
|
|
|
|
|
this.history[this.historyIndex].copy(this.buf, 0); |
|
|
|
|
|
this.buf.used = this.history[this.historyIndex].length; |
|
|
|
|
|
// set cursor to end of line.
|
|
|
|
|
|
this.cursor = this.buf.used; |
|
|
|
|
|
this._refreshLine(); |
|
|
|
|
|
|
|
|
|
|
|
} else if (this.historyIndex === 0) { |
|
|
case 27: /* escape sequence */ |
|
|
this.historyIndex = -1; |
|
|
if (b[1] === 98 && this.cursor > 0) { // meta-b - backward word
|
|
|
this.cursor = 0; |
|
|
|
|
|
this.buf.used = 0; |
|
|
} else if (b[1] === 102 && this.cursor < this.buf.used) { // meta-f - forward word
|
|
|
|
|
|
|
|
|
|
|
|
} else if (b[1] === 91 && b[2] === 68) { // left arrow
|
|
|
|
|
|
if (this.cursor > 0) { |
|
|
|
|
|
this.cursor--; |
|
|
|
|
|
this._refreshLine(); |
|
|
|
|
|
} |
|
|
|
|
|
} else if (b[1] === 91 && b[2] === 67) { // right arrow
|
|
|
|
|
|
if (this.cursor != this.buf.used) { |
|
|
|
|
|
this.cursor++; |
|
|
this._refreshLine(); |
|
|
this._refreshLine(); |
|
|
} |
|
|
} |
|
|
|
|
|
} else if (b[1] === 91 && b[2] === 65) { // up arrow
|
|
|
|
|
|
this._historyPrev(); |
|
|
|
|
|
} else if (b[1] === 91 && b[2] === 66) { // down arrow
|
|
|
|
|
|
this._historyNext(); |
|
|
} |
|
|
} |
|
|
break; |
|
|
break; |
|
|
|
|
|
|
|
|