From ecb0ae6b46f095f46744635c8dc2e161d9a3301b Mon Sep 17 00:00:00 2001 From: Izaya Date: Wed, 11 Oct 2017 14:20:50 +1100 Subject: [PATCH] some work on a new tty driver, fastty, still pretty buggy but it works well enough for now --- configs/everything.cfg | 5 ++- configs/minimal.cfg | 2 +- modules/drivers/fastty.lua | 73 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 modules/drivers/fastty.lua diff --git a/configs/everything.cfg b/configs/everything.cfg index 4e4ce77..7f7d9df 100755 --- a/configs/everything.cfg +++ b/configs/everything.cfg @@ -6,10 +6,9 @@ modules/debug/log.lua modules/base/header.lua modules/base/component.lua modules/lib/fs.lua -modules/util/logflush.lua modules/lib/buffer.lua modules/lib/io.lua -modules/drivers/vt52.lua +modules/drivers/fastty.lua modules/lib/print.lua modules/drivers/kbd.lua modules/lib/cdlib.lua @@ -19,7 +18,7 @@ modules/util/motd.lua modules/lib/readline.lua modules/lib/shutil.lua fwrap shutil.cat exec/cat.lua -fwrap shutil.mem exec/free.lua +fwrap shutil.free exec/free.lua fwrap shutil.ls exec/ls.lua fwrap shutil.ps exec/ps.lua alias shutil.cd fs.cd diff --git a/configs/minimal.cfg b/configs/minimal.cfg index 3eaf3f8..056089c 100755 --- a/configs/minimal.cfg +++ b/configs/minimal.cfg @@ -9,7 +9,7 @@ modules/lib/fs.lua modules/util/logflush.lua modules/lib/buffer.lua modules/lib/io.lua -modules/drivers/vt52.lua +modules/drivers/fastty.lua modules/lib/print.lua modules/drivers/kbd.lua modules/lib/cdlib.lua diff --git a/modules/drivers/fastty.lua b/modules/drivers/fastty.lua new file mode 100644 index 0000000..df02caa --- /dev/null +++ b/modules/drivers/fastty.lua @@ -0,0 +1,73 @@ +function tty(gA,sA,sI,mx,my) + spawn("fastty: "..gA:sub(1,8)..","..sA:sub(1,8)..","..sI,function() +-- _G.nlog = "" + local sb,lb = {},{} + local cx, cy = 1, 1 + local sI = sI or os.getenv("sI") + local gpu = component.proxy(gA) + gpu.bind(sA) + local sx, sy = gpu.maxResolution() + sx, sy = mx or sx, my or sy + + local function wl(s) + s=tostring(s) or "" + for c in s:gmatch(".") do + if c == "\f" then + for i = 1, sy do + sb[i] = nil + end + cx,cy=1,1 + elseif c == "\n" then + cx,cy=1,cy+1 + elseif c == "\t" then + repeat + cx=cx+1 + until cx%8 == 0 + elseif c == "\127" then + cx=cx-1 + if cx<1 then cx=1 end + --(" "):rep(2) + sb[cy] = sb[cy]:sub(1,cx-1).." "..sb[cy]:sub(cx+2) + else + sb[cy] = sb[cy] or "" + while cx > sb[cy]:len() do + sb[cy]=sb[cy] .. " " + end + sb[cy] = sb[cy]:sub(1,cx-1)..c..sb[cy]:sub(cx) + if sb[cy]:len() > sx then + sb[cy] = sb[cy]:sub(1,sx) + end + cx=cx+1 + end + end + end + local function rd() + while #sb > sy do + table.remove(sb,1) + cy=cy-1 + end + for i = 1, sy do + if sb[i] and sb[i] ~= lb[i] then + if not sb[i] then + lb[i] = nil + else + --lb[i] = sb[i] + end + local cs = sb[i] + --nlog = nlog .. tostring(i) .. " " .. tostring(cs) .. "\n" + while cs:len() < sx do + cs=cs.." " + end + gpu.set(1,i,cs) + end + end + end + while true do + _,si,str = event.pull("display") + if si == sI then + wl(str) + rd() + end + end + end,{sI=sI}) +end