greatly improved the terminal emulator, with colours (<ESC>[...m) and status support
This commit is contained in:
parent
0993182839
commit
fab605ff21
@ -34,6 +34,6 @@ function vtemu(gpua,scra) -- creates a process to handle the GPU and screen addr
|
||||
r, buf = buf:sub(1,n), buf:sub(n+1)
|
||||
return r
|
||||
end
|
||||
return bread, write, function() io.write("\27[2J\27[H") end
|
||||
return bread, function(d) buf=buf..write(d) end, function() io.write("\27[2J\27[H") end
|
||||
end
|
||||
end
|
||||
|
@ -1,4 +1,5 @@
|
||||
function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function to write to it in a manner like an ANSI terminal
|
||||
local colours = {0x0,0xFF0000,0x00FF00,0xFFFF00,0x0000FF,0xFF00FF,0x00B6FF,0xFFFFFF}
|
||||
local mx, my = gpu.maxResolution()
|
||||
local cx, cy = 1, 1
|
||||
local pc = " "
|
||||
@ -7,16 +8,18 @@ function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function
|
||||
local lw = true
|
||||
local sx, sy = 1,1
|
||||
local cs = ""
|
||||
local bg, fg = 0, 0xFFFFFF
|
||||
|
||||
-- setup
|
||||
gpu.setResolution(mx,my)
|
||||
gpu.fill(1,1,mx,my," ")
|
||||
|
||||
function termwrite(s)
|
||||
local rs = ""
|
||||
s=s:gsub("\8","\27[D")
|
||||
pc = gpu.get(cx,cy)
|
||||
gpu.setForeground(0xFFFFFF)
|
||||
gpu.setBackground(0)
|
||||
gpu.setForeground(fg)
|
||||
gpu.setBackground(bg)
|
||||
gpu.set(cx,cy,pc)
|
||||
for i = 1, s:len() do
|
||||
local cc = s:sub(i,i)
|
||||
@ -46,38 +49,58 @@ function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function
|
||||
gpu.copy(1,1,mx,my-1,0,1)
|
||||
gpu.fill(1,1,mx,1," ")
|
||||
mode = "n"
|
||||
else
|
||||
mode = "n"
|
||||
end
|
||||
|
||||
elseif mode == "v" then
|
||||
mode = "n"
|
||||
if cc == "s" then -- save cursor
|
||||
sx, sy = cx, cy
|
||||
mode = "n"
|
||||
elseif cc == "u" then -- restore cursor
|
||||
cx, cy = sx, sy
|
||||
mode = "n"
|
||||
elseif cc == "H" then -- cursor home or to
|
||||
local tx, ty = cs:match("(.-);(.-)")
|
||||
local tx, ty = cs:match("(%d+);(%d+)")
|
||||
tx, ty = tx or "1", ty or "1"
|
||||
cx, cy = tonumber(tx), tonumber(ty)
|
||||
mode = "n"
|
||||
elseif cc == "A" then -- cursor up
|
||||
cy = cy - (tonumber(cs) or 1)
|
||||
mode = "n"
|
||||
elseif cc == "B" then -- cursor down
|
||||
cy = cy + (tonumber(cs) or 1)
|
||||
mode = "n"
|
||||
elseif cc == "C" then -- cursor right
|
||||
cx = cx + (tonumber(cs) or 1)
|
||||
mode = "n"
|
||||
elseif cc == "D" then -- cursor left
|
||||
cx = cx - (tonumber(cs) or 1)
|
||||
mode = "n"
|
||||
elseif cc == "h" and lc == "7" then -- enable line wrap
|
||||
lw = true
|
||||
elseif cc == "l" and lc == "7" then -- disable line wrap
|
||||
lw = false
|
||||
elseif cc == "c" then
|
||||
rs = string.format("%s\27[%d;%d0c",rs,mx,my)
|
||||
elseif cc == "n" and lc == "6" then
|
||||
rs = string.format("%s\27[%d;%dR",rs,cx,cy)
|
||||
elseif cc == "m" then
|
||||
for num in cs:gmatch("%d+") do
|
||||
num=tonumber(num)
|
||||
if num == 0 then
|
||||
fg,bg = 0xFFFFFF,0
|
||||
elseif num == 7 then
|
||||
local nfg,nbg = bg, fg
|
||||
fg, bg = nfg, nbg
|
||||
elseif num > 29 and num < 38 then
|
||||
fg = colours[num-29]
|
||||
elseif num > 39 and num < 48 then
|
||||
bg = colours[num-39]
|
||||
end
|
||||
end
|
||||
gpu.setForeground(fg)
|
||||
gpu.setBackground(bg)
|
||||
else
|
||||
cs = cs .. cc
|
||||
if cc:match("[%d;]") then
|
||||
mode = "v"
|
||||
end
|
||||
end
|
||||
cs = cs .. cc
|
||||
end
|
||||
|
||||
if cx > mx and lw then
|
||||
@ -94,11 +117,12 @@ function vt100emu(gpu) -- takes GPU component proxy *gpu* and returns a function
|
||||
lc = cc
|
||||
end
|
||||
pc = gpu.get(cx,cy)
|
||||
gpu.setForeground(0)
|
||||
gpu.setBackground(0xFFFFFF)
|
||||
gpu.setForeground(bg)
|
||||
gpu.setBackground(fg)
|
||||
gpu.set(cx,cy,pc)
|
||||
gpu.setForeground(0xFFFFFF)
|
||||
gpu.setBackground(0)
|
||||
gpu.setForeground(fg)
|
||||
gpu.setBackground(bg)
|
||||
return rs
|
||||
end
|
||||
|
||||
return termwrite
|
||||
|
Loading…
Reference in New Issue
Block a user