48 lines
1.3 KiB
Lua
48 lines
1.3 KiB
Lua
function tty(gA,sA,sI,fg,bg) -- gpuAddress,screenAddress,sessionID,foreground,background
|
|
local gP,cx,cy,bg,fg = component.proxy(gA),1,1,bg or 0x000000, fg or 0xffffff -- basic setup from here
|
|
gP.bind(sA)
|
|
local sx, sy = gP.getResolution()
|
|
gP.setResolution(sx,sy)
|
|
gP.setForeground(fg)
|
|
gP.setBackground(bg)
|
|
gP.fill(1,1,sx,sy," ")
|
|
local function cv() -- check cursor position
|
|
if cx > sx then cx,cy=1,cy+1 end
|
|
if cx < 1 then cx,cy=sx,cy-1 end
|
|
if cy < 1 then cx,cy=1,1 end
|
|
if cy > sy then gP.copy(1,2,sx,sy-1,0,-1) gP.fill(1,sy,sx,1," ") cx,cy=1,sy end
|
|
end
|
|
local function ic(s)
|
|
local cc,fg,bg=gP.get(cx,cy)
|
|
if s then fG,bG = bg,fg else fG,bG = fg,bg end
|
|
gP.setForeground(bG)
|
|
gP.setBackground(fG)
|
|
gP.set(cx,cy,cc)
|
|
gP.setForeground(fG)
|
|
gP.setBackground(bG)
|
|
end
|
|
local function wl(str) -- write line
|
|
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, " ")
|
|
elseif c == "\t" then cx=(cx+4-((cx+4)%4))+1
|
|
elseif c == "\127" or c == "\008" then cx=cx-1 gP.set(cx,cy," ")
|
|
else gP.set(cx,cy,c) cx=cx+1
|
|
end cv()
|
|
end
|
|
end
|
|
spawn("tty",function() log(pcall(function() -- spawns the listener
|
|
local csi = os.getenv("sI")
|
|
log(csi)
|
|
while true do
|
|
_,si,str=event.pull("display")
|
|
if si == csi then
|
|
wl(str)
|
|
ic()
|
|
end
|
|
end
|
|
end)) end)
|
|
end
|
|
|