there is now a non-standard control code for the terminal to toggle line mode and local echo for the terminal

This commit is contained in:
Izaya 2020-04-11 08:52:18 +10:00
parent 459fd95992
commit a9b3c6adf3
2 changed files with 34 additions and 10 deletions

View File

@ -28,6 +28,7 @@ function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function
local function termwrite(s) local function termwrite(s)
local wb = "" local wb = ""
local lb, ec = nil, nil
local function flushwb() local function flushwb()
while wb:len() > 0 do while wb:len() > 0 do
checkCursor() checkCursor()
@ -103,7 +104,7 @@ function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function
elseif cc == "m" then elseif cc == "m" then
for _,num in ipairs(tA) do for _,num in ipairs(tA) do
if num == 0 then if num == 0 then
fg,bg = 0xFFFFFF,0 fg,bg,ec,lb = 0xFFFFFF,0,true,true
elseif num == 7 then elseif num == 7 then
local nfg,nbg = bg, fg local nfg,nbg = bg, fg
fg, bg = nfg, nbg fg, bg = nfg, nbg
@ -111,6 +112,10 @@ function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function
fg = colours[num-29] fg = colours[num-29]
elseif num > 39 and num < 48 then elseif num > 39 and num < 48 then
bg = colours[num-39] bg = colours[num-39]
elseif num == 100 then -- disable local echo
ec = false
elseif num == 101 then -- disable line mode
lb = false
end end
end end
gpu.setForeground(fg) gpu.setForeground(fg)
@ -129,7 +134,7 @@ function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function
gpu.set(cx,cy,pc) gpu.set(cx,cy,pc)
gpu.setForeground(fg) gpu.setForeground(fg)
gpu.setBackground(bg) gpu.setBackground(bg)
return rs return rs, lb, ec
end end
return termwrite return termwrite

View File

@ -8,7 +8,7 @@ function vtemu(gpua,scra) -- creates a process to handle the GPU and screen addr
for k,v in ipairs(component.invoke(scra,"getKeyboards")) do for k,v in ipairs(component.invoke(scra,"getKeyboards")) do
kba[v]=true kba[v]=true
end end
local buf = "" local buf, lbuf, echo = "", true, true
os.spawn(function() dprint(pcall(function() os.spawn(function() dprint(pcall(function()
while true do while true do
local ty,ka,ch = coroutine.yield() local ty,ka,ch = coroutine.yield()
@ -16,24 +16,43 @@ function vtemu(gpua,scra) -- creates a process to handle the GPU and screen addr
if ch == 13 then ch = 10 end if ch == 13 then ch = 10 end
if ch == 8 then if ch == 8 then
if buf:len() > 0 then if buf:len() > 0 then
write("\8 \8") if echo then write("\8 \8") end
buf = buf:sub(1,-2) buf = buf:sub(1,-2)
end end
elseif ch > 0 then elseif ch > 0 then
write(string.char(ch)) if echo then write(string.char(ch)) end
buf=buf..string.char(ch) buf=buf..string.char(ch)
end end
end end
end end
end)) end,string.format("ttyd[%s:%s]",gpua:sub(1,8),scra:sub(1,8))) end)) end,string.format("ttyd[%s:%s]",gpua:sub(1,8),scra:sub(1,8)))
local function bread() local function bread(n)
while not buf:find("\n") do local r
if lbuf then
while not buf:find("\n") do
coroutine.yield()
end
local n = buf:find("\n")
r, buf = buf:sub(1,n), buf:sub(n+1)
else
r = buf
buf = ""
coroutine.yield() coroutine.yield()
end end
local n = buf:find("\n")
r, buf = buf:sub(1,n), buf:sub(n+1)
return r return r
end end
return bread, function(d) buf=buf..write(d) end, function() io.write("\27[2J\27[H") end local function bwrite(d)
local ba, lb, ec = write(d)
buf = buf .. ba
if lb ~= nil then
dprint("local buffer mode: "..tostring(lb))
lbuf = lb
end
if ec ~= nil then
dprint("echo mode: "..tostring(ec))
echo = ec
end
end
return bread, bwrite, function() io.write("\27[2J\27[H") end
end end
end end