get tty device files working properly

This commit is contained in:
Lisa Milne 2023-12-12 21:37:08 +10:00
parent 41353aab1a
commit 015af5b3ba

View file

@ -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;