mirror of
https://github.com/sigmasternchen/Wish
synced 2025-03-15 23:48:55 +00:00
moveable cursor and temporary shell history
This commit is contained in:
parent
be0e09e01b
commit
a4f007cce1
1 changed files with 79 additions and 7 deletions
|
@ -97,6 +97,9 @@ WshClass.prototype.iCommands = {
|
||||||
}
|
}
|
||||||
WshClass.prototype.state = 0;
|
WshClass.prototype.state = 0;
|
||||||
WshClass.prototype.input = new Array();
|
WshClass.prototype.input = new Array();
|
||||||
|
WshClass.prototype.inputIndex = 0;
|
||||||
|
WshClass.prototype.history = new Array();
|
||||||
|
WshClass.prototype.historyIndex = 0;
|
||||||
WshClass.prototype.childList = new Array();
|
WshClass.prototype.childList = new Array();
|
||||||
WshClass.prototype.main = function(args) {
|
WshClass.prototype.main = function(args) {
|
||||||
console.log("wsh " + this.pid + ": adding to scheduler job list");
|
console.log("wsh " + this.pid + ": adding to scheduler job list");
|
||||||
|
@ -171,20 +174,89 @@ WshClass.prototype.tick = function() {
|
||||||
if (!char.length)
|
if (!char.length)
|
||||||
break;
|
break;
|
||||||
var code = char.charCodeAt(0);
|
var code = char.charCodeAt(0);
|
||||||
if (KeyCodes.isBackspace(code)) {
|
if (KeyCodes.isUp(code)) {
|
||||||
if (!this.input.length)
|
if (this.historyIndex == 0)
|
||||||
break;
|
break;
|
||||||
this.input.pop();
|
for (var i = this.inputIndex; i < this.input.length; i++) {
|
||||||
|
stdout.write("\033[1C");
|
||||||
|
}
|
||||||
|
for (var i = 0; i < this.input.length; i++) {
|
||||||
stdout.write("\033[1D \033[1D");
|
stdout.write("\033[1D \033[1D");
|
||||||
|
}
|
||||||
|
this.input = clone(this.history[--this.historyIndex]);
|
||||||
|
this.inputIndex = this.input.length;
|
||||||
|
stdout.write(this.input.join(""));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (KeyCodes.isDown(code)) {
|
||||||
|
if (this.historyIndex == this.history.length)
|
||||||
|
break;
|
||||||
|
for (var i = this.inputIndex; i < this.input.length; i++) {
|
||||||
|
stdout.write("\033[1C");
|
||||||
|
}
|
||||||
|
for (var i = 0; i < this.input.length; i++) {
|
||||||
|
stdout.write("\033[1D \033[1D");
|
||||||
|
}
|
||||||
|
if (this.historyIndex + 1 == this.history.length) {
|
||||||
|
this.input = new Array();
|
||||||
|
this.inputIndex = this.input.length;
|
||||||
|
this.historyIndex = this.history.length;
|
||||||
|
} else {
|
||||||
|
this.input = clone(this.history[++this.historyIndex]);
|
||||||
|
this.inputIndex = this.input.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
stdout.write(this.input.join(""));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (KeyCodes.isLeft(code)) {
|
||||||
|
if (this.inputIndex == 0)
|
||||||
|
break;
|
||||||
|
this.inputIndex--;
|
||||||
|
stdout.write("\033[1D");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (KeyCodes.isRight(code)) {
|
||||||
|
if (this.inputIndex == this.input.length)
|
||||||
|
break;
|
||||||
|
this.inputIndex++;
|
||||||
|
stdout.write("\033[1C");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (KeyCodes.isBackspace(code)) {
|
||||||
|
if (this.inputIndex == 0)
|
||||||
|
break;
|
||||||
|
for (var i = this.inputIndex; i < this.input.length; i++) {
|
||||||
|
stdout.write("\033[1C");
|
||||||
|
}
|
||||||
|
for (var i = 0; i < this.input.length; i++) {
|
||||||
|
stdout.write("\033[1D \033[1D");
|
||||||
|
}
|
||||||
|
this.input.splice(--this.inputIndex, 1);
|
||||||
|
stdout.write(this.input.join(""));
|
||||||
|
for (var i = this.input.length; i > this.inputIndex; i--) {
|
||||||
|
stdout.write("\033[1D");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (KeyCodes.isEnter(code)) {
|
if (KeyCodes.isEnter(code)) {
|
||||||
|
this.history.push(clone(this.input));
|
||||||
|
this.historyIndex = this.history.length;
|
||||||
|
this.inputIndex = 0;
|
||||||
stdout.write("\n");
|
stdout.write("\n");
|
||||||
this.parseLine();
|
this.parseLine();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
this.input.push(char);
|
this.historyIndex = this.history.length;
|
||||||
stdout.write(char);
|
|
||||||
|
for (var i = 0; i < this.inputIndex; i++) {
|
||||||
|
stdout.write("\033[1D \033[1D");
|
||||||
|
}
|
||||||
|
this.input.splice(this.inputIndex++, 0, char);
|
||||||
|
stdout.write(this.input.join(""));
|
||||||
|
for (var i = this.input.length; i > this.inputIndex; i--) {
|
||||||
|
stdout.write("\033[1D");
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue