diff --git a/clite/bios.js b/clite/bios.js index 346a612..62f2832 100644 --- a/clite/bios.js +++ b/clite/bios.js @@ -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; diff --git a/clite/core.js b/clite/core.js index a0cd64f..d116417 100644 --- a/clite/core.js +++ b/clite/core.js @@ -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));