2017-10-12 10:39:19 +11:00
|
|
|
_G.term_hack = true
|
2017-10-11 14:20:50 +11:00
|
|
|
function tty(gA,sA,sI,mx,my)
|
|
|
|
spawn("fastty: "..gA:sub(1,8)..","..sA:sub(1,8)..","..sI,function()
|
2017-10-12 10:39:19 +11:00
|
|
|
_G.nlog = ""
|
|
|
|
local sb,lb,slb = {},{},{}
|
2017-10-11 14:20:50 +11:00
|
|
|
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 ""
|
2017-10-12 16:13:51 +11:00
|
|
|
for i = 1,unicode.len(s) do
|
|
|
|
local c = ""
|
|
|
|
c=unicode.sub(s,i,i)
|
2017-10-11 14:20:50 +11:00
|
|
|
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
|
2017-10-12 16:13:51 +11:00
|
|
|
cx=cx+unicode.charWidth(c)
|
2017-10-11 14:20:50 +11:00
|
|
|
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
|
2017-10-12 10:39:19 +11:00
|
|
|
lb[i] = sb[i]
|
2017-10-11 14:20:50 +11:00
|
|
|
local cs = sb[i]
|
|
|
|
--nlog = nlog .. tostring(i) .. " " .. tostring(cs) .. "\n"
|
|
|
|
while cs:len() < sx do
|
|
|
|
cs=cs.." "
|
|
|
|
end
|
|
|
|
gpu.set(1,i,cs)
|
2017-10-12 10:39:19 +11:00
|
|
|
if term_hack then
|
|
|
|
gpu.set(1,i,cs)
|
|
|
|
end
|
2017-10-11 14:20:50 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
while true do
|
|
|
|
_,si,str = event.pull("display")
|
|
|
|
if si == sI then
|
|
|
|
wl(str)
|
|
|
|
rd()
|
2017-10-12 16:13:51 +11:00
|
|
|
gpu.set(cx,cy,"█")
|
2017-10-11 14:20:50 +11:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end,{sI=sI})
|
|
|
|
end
|