2017-05-16 02:26:28 +10:00
|
|
|
function tty(gA,sA,sI,fg,bg)
|
2017-07-15 02:32:47 +10:00
|
|
|
local gP,cx,cy,bg,fg = component.proxy(gA),1,1,bg or 0x000000, fg or 0xffffff
|
2017-05-16 02:26:28 +10:00
|
|
|
gP.bind(sA)
|
|
|
|
local sx, sy = gP.getResolution()
|
|
|
|
gP.setResolution(sx,sy)
|
2017-07-15 02:32:47 +10:00
|
|
|
gP.setForeground(fg)
|
|
|
|
gP.setBackground(bg)
|
2017-05-16 02:26:28 +10:00
|
|
|
gP.fill(1,1,sx,sy," ")
|
|
|
|
local function cv()
|
|
|
|
if cx > sx then cx,cy=1,cy+1 end
|
|
|
|
if cx < 1 then cx,cy=1,cy-1 end
|
|
|
|
if cy < 1 then cx,cy=1,1 end
|
2017-05-16 02:36:16 +10:00
|
|
|
if cy > sy then gP.copy(1,2,sx,sy-1,0,-1) gP.fill(1,sy,sx,1," ") cx,cy=1,sy end
|
2017-05-16 02:26:28 +10:00
|
|
|
end
|
|
|
|
local function wl(str)
|
|
|
|
for c in str:gmatch(".") do
|
|
|
|
if c == "\n" then cx,cy=1,cy+1
|
|
|
|
elseif c == "\r" then cx=1
|
|
|
|
elseif c == "\f" then cx=1 cy=1 gP.fill(1, 1, sx, sy, " ")
|
2017-05-28 03:44:27 +10:00
|
|
|
elseif c == "\t" then cx=(cx+4-((cx+4)%4))+1
|
2017-07-15 02:32:47 +10:00
|
|
|
elseif c == "\127" then cx=cx-1 gP.set(cx,cy," ")
|
2017-05-16 02:26:28 +10:00
|
|
|
else gP.set(cx,cy,c) cx=cx+1
|
|
|
|
end cv()
|
|
|
|
end
|
|
|
|
end
|
2017-06-20 04:33:29 +10:00
|
|
|
s("tty["..TS(sI).."]: "..gA:sub(1,8)..","..sA:sub(1,8),function()
|
2017-05-16 02:26:28 +10:00
|
|
|
while true do
|
|
|
|
eT = ev
|
|
|
|
if eT[1] == "display" and eT[3] == sI then
|
|
|
|
wl(tostring(eT[2]))
|
2017-07-15 02:32:47 +10:00
|
|
|
local cc,fg,bg=gP.get(cx,cy)
|
|
|
|
gP.setForeground(bg)
|
|
|
|
gP.setBackground(fg)
|
|
|
|
gP.set(cx,cy,cc)
|
|
|
|
gP.setForeground(fg)
|
|
|
|
gP.setBackground(bg)
|
2017-05-16 02:26:28 +10:00
|
|
|
end
|
|
|
|
C.yield()
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
end
|