2017-08-03 11:44:20 +10:00
|
|
|
function tty(gA,sA,sI,fg,bg)
|
2017-10-07 16:14:30 +11:00
|
|
|
local sI = sI or 1
|
|
|
|
local gP,cx,cy,bg,fg,Sx,Sy = component.proxy(gA),1,1,bg or 0x000000, fg or 0xffffff,1,1
|
2017-08-03 11:44:20 +10:00
|
|
|
gP.bind(sA)
|
|
|
|
local sx, sy = gP.getResolution()
|
|
|
|
gP.setResolution(sx,sy)
|
|
|
|
gP.setForeground(fg)
|
|
|
|
gP.setBackground(bg)
|
|
|
|
gP.fill(1,1,sx,sy," ")
|
|
|
|
gP.setDepth(gP.maxDepth())
|
|
|
|
local function cv()
|
|
|
|
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)
|
2017-10-07 06:10:57 +11:00
|
|
|
if gP.getScreen() ~= sA then
|
2017-09-24 02:19:51 +10:00
|
|
|
gP.bind(sA)
|
|
|
|
end
|
2017-08-03 11:44:20 +10:00
|
|
|
local cm = 0
|
|
|
|
for c in str:gmatch(".") do
|
|
|
|
if cm == 1 then
|
|
|
|
cm = 0
|
|
|
|
if c == "A" then cy=cy-1
|
|
|
|
elseif c == "B" then cy=cy+1
|
|
|
|
elseif c == "C" then cx=cx+1
|
|
|
|
elseif c == "D" then cx=cx-1
|
|
|
|
elseif c == "H" then cx,cy=1,1
|
|
|
|
elseif c == "Y" then cm=2
|
|
|
|
elseif c == "b" then cm=4
|
|
|
|
elseif c == "c" then cm=5
|
2017-10-07 16:14:30 +11:00
|
|
|
elseif c == "j" then Sx,Sy = cx,cy
|
|
|
|
elseif c == "k" then cx,cy = Sx,Sy
|
|
|
|
elseif c == "l" then
|
|
|
|
gP.fill(1,cy,sx,1," ")
|
|
|
|
elseif c == "L" then
|
|
|
|
gP.copy(1,2,sx,cy-1,0,-1)
|
|
|
|
gP.fill(1,cy-1,sx,1," ")
|
|
|
|
elseif c == "p" then
|
|
|
|
gP.setForeground(bG)
|
|
|
|
gP.setBackground(fG)
|
|
|
|
elseif c == "q" then
|
|
|
|
gP.setForeground(fG)
|
|
|
|
gP.setBackground(bG)
|
2017-08-03 11:44:20 +10:00
|
|
|
end
|
|
|
|
elseif cm == 2 then
|
|
|
|
cx,cm=string.byte(c)-31,3
|
|
|
|
elseif cm == 3 then
|
|
|
|
cy,cm=string.byte(c)-31,0
|
|
|
|
elseif cm == 4 then
|
|
|
|
fg,cm = string.byte(c),0
|
|
|
|
gP.setForeground(fg,true)
|
|
|
|
elseif cm == 5 then
|
|
|
|
bg,cm = string.byte(c),0
|
|
|
|
gP.setBackground(bg,true)
|
|
|
|
else
|
|
|
|
if c == "\n" then cx,cy=1,cy+1
|
|
|
|
elseif c == "\27" then cm=1
|
|
|
|
elseif c == "\r" then cx=1
|
|
|
|
elseif c == "\f" then cx=1 cy=1 gP.fill(1, 1, sx, sy, " ")
|
2017-08-03 17:52:10 +10:00
|
|
|
elseif c == "\t" then cx=(cx+8-((cx+8)%8))+1
|
2017-09-13 13:06:17 +10:00
|
|
|
elseif c == "\127" then cx=cx-1 gP.set(cx,cy,(" "):rep(2))
|
2017-08-03 11:44:20 +10:00
|
|
|
else gP.set(cx,cy,c) cx=cx+1
|
|
|
|
end
|
|
|
|
end cv()
|
|
|
|
end
|
|
|
|
end
|
|
|
|
spawn("tty["..tostring(sI).."]: "..gA:sub(1,8)..","..sA:sub(1,8),function() log(pcall(function()
|
2017-10-07 16:14:30 +11:00
|
|
|
if sI then os.setenv("sI",sI) end
|
2017-08-03 11:44:20 +10:00
|
|
|
while true do
|
2017-09-26 13:56:15 +10:00
|
|
|
local csi = os.getenv("sI")
|
|
|
|
log(csi)
|
|
|
|
while true do
|
|
|
|
_,si,str=event.pull("display")
|
|
|
|
if si == csi then
|
|
|
|
wl(str)
|
|
|
|
ic()
|
|
|
|
end
|
2017-08-03 11:44:20 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end)) end)
|
|
|
|
end
|