some work on a new tty driver, fastty, still pretty buggy but it works well enough for now

This commit is contained in:
Izaya 2017-10-11 14:20:50 +11:00
parent 8192e62ebd
commit ecb0ae6b46
3 changed files with 76 additions and 4 deletions

View File

@ -6,10 +6,9 @@ modules/debug/log.lua
modules/base/header.lua modules/base/header.lua
modules/base/component.lua modules/base/component.lua
modules/lib/fs.lua modules/lib/fs.lua
modules/util/logflush.lua
modules/lib/buffer.lua modules/lib/buffer.lua
modules/lib/io.lua modules/lib/io.lua
modules/drivers/vt52.lua modules/drivers/fastty.lua
modules/lib/print.lua modules/lib/print.lua
modules/drivers/kbd.lua modules/drivers/kbd.lua
modules/lib/cdlib.lua modules/lib/cdlib.lua
@ -19,7 +18,7 @@ modules/util/motd.lua
modules/lib/readline.lua modules/lib/readline.lua
modules/lib/shutil.lua modules/lib/shutil.lua
fwrap shutil.cat exec/cat.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.ls exec/ls.lua
fwrap shutil.ps exec/ps.lua fwrap shutil.ps exec/ps.lua
alias shutil.cd fs.cd alias shutil.cd fs.cd

View File

@ -9,7 +9,7 @@ modules/lib/fs.lua
modules/util/logflush.lua modules/util/logflush.lua
modules/lib/buffer.lua modules/lib/buffer.lua
modules/lib/io.lua modules/lib/io.lua
modules/drivers/vt52.lua modules/drivers/fastty.lua
modules/lib/print.lua modules/lib/print.lua
modules/drivers/kbd.lua modules/drivers/kbd.lua
modules/lib/cdlib.lua modules/lib/cdlib.lua

View File

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