backspace on the tty

This commit is contained in:
Lisa Milne 2023-12-12 21:16:25 +10:00
parent abf9dbad6c
commit 41353aab1a
2 changed files with 28 additions and 0 deletions

View file

@ -471,6 +471,10 @@ bios.input.keyboard = {
k.char = String.fromCharCode(127);
k.lchr = k.char;
k.code = 127;
case "Backspace":
k.char = String.fromCharCode(8);
k.lchr = k.char;
k.code = 8;
break;
default:
k.code = key;

View file

@ -2157,6 +2157,10 @@ clite.tty = {
var updateY = clite.tty.data.ttys[id].y;
switch (cc) {
case 8: //BS
clite.tty.data.ttys[id].x--;
updateLine = true;
break;
case 10: //LF
clite.tty.data.ttys[id].y++;
break;
@ -2169,6 +2173,14 @@ clite.tty = {
clite.tty.data.ttys[id].x++;
}
if (clite.tty.data.ttys[id].x < 0) {
clite.tty.data.ttys[id].y--;
clite.tty.data.ttys[id].x = 79;
}
if (clite.tty.data.ttys[id].y < 0)
clite.tty.data.ttys[id].y = 0;
if (clite.tty.data.ttys[id].x > 79) {
clite.tty.data.ttys[id].y++;
clite.tty.data.ttys[id].x = 0;
@ -2290,6 +2302,15 @@ clite.tty = {
}
return;
}
// Backspace
if (key.code == 8) {
if (t.buff.pop() && t.echo) {
clite.tty.write(t.id,String.fromCharCode(8));
clite.tty.write(t.id,' ');
clite.tty.write(t.id,String.fromCharCode(8));
}
return;
}
t.buff.push(key);
if (typeof t.rcb !== 'function')
return;
@ -2348,6 +2369,9 @@ clite.tty = {
// TODO: escape/control sequences
if (cc < 32 || cc > 126) {
switch (cc) {
case 8:
clite.tty.internal.write(id,String.fromCharCode(8));
break;
case 10: // NL/LF to CR+LF
clite.tty.internal.write(id,String.fromCharCode(13));
clite.tty.internal.write(id,String.fromCharCode(10));