OC-PsychOS/modules/drivers/fastty.lua

74 lines
1.5 KiB
Lua

_G.term_hack = true
function tty(gA,sA,sI,mx,my)
spawn("fastty: "..gA:sub(1,8)..","..sA:sub(1,8)..","..sI,function()
_G.nlog = ""
local sb,lb,slb = {},{},{}
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
lb[i] = sb[i]
local cs = sb[i]
--nlog = nlog .. tostring(i) .. " " .. tostring(cs) .. "\n"
while cs:len() < sx do
cs=cs.." "
end
gpu.set(1,i,cs)
if term_hack then
gpu.set(1,i,cs)
end
end
end
end
while true do
_,si,str = event.pull("display")
if si == sI then
wl(str)
rd()
end
end
end,{sI=sI})
end