made tty.lua handle the cursor rather than readline because that's just stupid

This commit is contained in:
Izaya 2017-07-15 02:32:47 +10:00
parent d5f77ef8c9
commit 2c6f92261e
2 changed files with 12 additions and 7 deletions

View File

@ -1,10 +1,10 @@
function tty(gA,sA,sI,fg,bg)
local gP,cx,cy = component.proxy(gA),1,1
local gP,cx,cy,bg,fg = component.proxy(gA),1,1,bg or 0x000000, fg or 0xffffff
gP.bind(sA)
local sx, sy = gP.getResolution()
gP.setResolution(sx,sy)
gP.setForeground(bg or 0xFFFFFF)
gP.setBackground(bg or 0x000000)
gP.setForeground(fg)
gP.setBackground(bg)
gP.fill(1,1,sx,sy," ")
local function cv()
if cx > sx then cx,cy=1,cy+1 end
@ -28,6 +28,12 @@ function tty(gA,sA,sI,fg,bg)
eT = ev
if eT[1] == "display" and eT[3] == sI then
wl(tostring(eT[2]))
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)
end
C.yield()
end

View File

@ -1,6 +1,5 @@
function readln(rC)
local s,si="",E().sI or 1
write("|")
while true do
if ev[1] == "key" and ev[2] == si then
if ev[3] == 13 then
@ -8,9 +7,9 @@ function readln(rC)
C.yield()
return s
elseif ev[3] == 8 then
if s:len()>0 then s=s:sub(1,-2) write("\127\127|") end
if s:len()>0 then s=s:sub(1,-2) write("\127") end
elseif ev[3] > 31 and ev[3] < 127 then
s=s..string.char(ev[3]) write("\127"..(rC or string.char(ev[3])).."|")
s=s..string.char(ev[3]) write((rC or string.char(ev[3])))
end
end
C.yield()