From 015af5b3ba0c5952ab68ef28f01e06d8df986432 Mon Sep 17 00:00:00 2001 From: Lisa Milne Date: Tue, 12 Dec 2023 21:37:08 +1000 Subject: [PATCH] get tty device files working properly --- clite/core.js | 62 ++++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/clite/core.js b/clite/core.js index d116417..0ba98af 100644 --- a/clite/core.js +++ b/clite/core.js @@ -220,7 +220,7 @@ var clite = { n.perms = 'crw-rw-rw-'; n.data.isdev = true; } - // /dev/tty - the main tty device, writing to it prints to the terminal, reading from it reads keyboard input + // /dev/tty - virtual device that always acts like the controlling terminal { vfsapi.mkFile(0,'/dev/tty'); let n = vfsapi.getNode(0,'/dev/tty'); @@ -517,9 +517,9 @@ license.txt:/etc/license:0:0:-rw-r--r--`; var env = clite.user.getEnv(1); var io = { pid:0, - stdin:clite.io.open(1,'/dev/tty',clite.io.flags.O_RDONLY), - stdout:clite.io.open(1,'/dev/tty',clite.io.flags.O_WRONLY), - stderr:clite.io.open(1,'/dev/tty',clite.io.flags.O_WRONLY), + stdin:clite.io.open(1,'/dev/tty0',clite.io.flags.O_RDONLY), + stdout:clite.io.open(1,'/dev/tty0',clite.io.flags.O_WRONLY), + stderr:clite.io.open(1,'/dev/tty0',clite.io.flags.O_WRONLY), exit:null, // filled in by fork() include:null, // filled in by fork() }; @@ -2153,48 +2153,49 @@ clite.tty = { var cc = ch.charCodeAt(0); var updateLine = false; var updateAll = false; - var updateX = clite.tty.data.ttys[id].x; - var updateY = clite.tty.data.ttys[id].y; + var t = clite.tty.data.ttys[id]; + var updateX = t.x; + var updateY = t.y; switch (cc) { case 8: //BS - clite.tty.data.ttys[id].x--; + t.x--; updateLine = true; break; case 10: //LF - clite.tty.data.ttys[id].y++; + t.y++; break; case 13: //CR - clite.tty.data.ttys[id].x = 0; + t.x = 0; updateLine = true; break; default: - clite.tty.data.ttys[id].data[updateY][updateX].ch = ch; - clite.tty.data.ttys[id].x++; + t.data[updateY][updateX].ch = ch; + t.x++; } - if (clite.tty.data.ttys[id].x < 0) { - clite.tty.data.ttys[id].y--; - clite.tty.data.ttys[id].x = 79; + if (t.x < 0) { + t.y--; + t.x = 79; } - if (clite.tty.data.ttys[id].y < 0) - clite.tty.data.ttys[id].y = 0; + if (t.y < 0) + t.y = 0; - if (clite.tty.data.ttys[id].x > 79) { - clite.tty.data.ttys[id].y++; - clite.tty.data.ttys[id].x = 0; + if (t.x > 79) { + t.y++; + t.x = 0; } // theoretically this should be fine, in practice it may not - if (clite.tty.data.ttys[id].y > 24) { - var l = clite.tty.data.ttys[id].data.shift() + if (t.y > 24) { + var l = t.data.shift() for (var i=0; i<80; i++) { l[i].ch = ' '; - l[i].fg = clite.tty.data.ttys[id].fg; - l[i].bg = clite.tty.data.ttys[id].bg; + l[i].fg = t.fg; + l[i].bg = t.bg; } - clite.tty.data.ttys[id].y = 24; - clite.tty.data.ttys[id].data.push(l); + t.y = 24; + t.data.push(l); updateAll = true; } @@ -2202,11 +2203,11 @@ clite.tty = { return; if (updateAll) { - clite.console.drawBuff(clite.tty.data.ttys[id].data); + clite.console.drawBuff(t.data); }else if (updateLine) { - clite.console.drawLine(updateY,clite.tty.data.ttys[id].data[updateY]); + clite.console.drawLine(updateY,t.data[updateY]); }else{ - clite.console.drawAt(updateX,updateY,clite.tty.data.ttys[id].data[updateY][updateX]); + clite.console.drawAt(updateX,updateY,t.data[updateY][updateX]); } }, popLine:function(t) { @@ -2263,8 +2264,9 @@ clite.tty = { return null; } n.data.content = { - read:null, - write:null + ttyid:id, + read:function(cb) {return clite.tty.read(n.data.content.ttyid,cb);}, + write:function(data) {return clite.tty.write(n.data.content.ttyid,data);} }; n.perms = 'crw-rw-rw-'; n.data.isdev = true;