Compare commits
No commits in common. "f95124996c2cb90274e2c29dfe39ece293cea8f4" and "4e64a5516939b67683d3192aca0c585df1130d4e" have entirely different histories.
f95124996c
...
4e64a55169
@ -1,13 +1,4 @@
|
||||
local vtansi = {}
|
||||
vtansi.sequences = {
|
||||
[28] = "\n", -- newline
|
||||
[200] = "\27[A", -- up
|
||||
[201] = "\27[5~", -- page up
|
||||
[203] = "\27[D", -- left
|
||||
[205] = "\27[C", -- right
|
||||
[208] = "\27[B", -- down
|
||||
[209] = "\27[6~" -- page down
|
||||
}
|
||||
function vtansi.vtemu(gpu) -- table -- function -- 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()
|
||||
@ -115,7 +106,7 @@ function vtansi.vtemu(gpu) -- table -- function -- takes GPU component proxy *gp
|
||||
elseif cc == "m" then
|
||||
for _,num in ipairs(tA) do
|
||||
if num == 0 then
|
||||
fg,bg,ec,lb = 0xFFFFFF,0,false,true
|
||||
fg,bg,ec,lb = 0xFFFFFF,0,true,true
|
||||
elseif num == 7 then
|
||||
local nfg,nbg = bg, fg
|
||||
fg, bg = nfg, nbg
|
||||
@ -159,27 +150,37 @@ function vtansi.vtsession(gpua,scra) -- string string -- table -- creates a proc
|
||||
for k,v in ipairs(component.invoke(scra,"getKeyboards")) do
|
||||
kba[v]=true
|
||||
end
|
||||
local buf, lbuf, echo = "", false, false
|
||||
os.spawn(function()
|
||||
local buf, lbuf, echo = "", true, true
|
||||
os.spawn(function() dprint(pcall(function()
|
||||
while true do
|
||||
local ty,ka,ch,kc = coroutine.yield()
|
||||
local ty,ka,ch = coroutine.yield()
|
||||
if ty == "key_down" and kba[ka] then
|
||||
local outs
|
||||
if ch > 0 then
|
||||
outs = string.char(ch)
|
||||
if ch == 13 then ch = 10 end
|
||||
if ch == 8 and lbuf then
|
||||
if buf:len() > 0 then
|
||||
if echo then write("\8 \8") end
|
||||
buf = buf:sub(1,-2)
|
||||
end
|
||||
outs = vtansi.sequences[kc] or outs
|
||||
if outs then
|
||||
if echo then write(outs) end
|
||||
buf=buf..outs
|
||||
elseif ch > 0 then
|
||||
if echo then write(string.char(ch)) end
|
||||
buf=buf..string.char(ch)
|
||||
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(n)
|
||||
local r
|
||||
if lbuf then
|
||||
while not buf:find("\n") do
|
||||
coroutine.yield()
|
||||
local r = buf
|
||||
end
|
||||
local n = buf:find("\n")
|
||||
r, buf = buf:sub(1,n), buf:sub(n+1)
|
||||
else
|
||||
r = buf
|
||||
buf = ""
|
||||
coroutine.yield()
|
||||
end
|
||||
return r
|
||||
end
|
||||
local function bwrite(d)
|
||||
|
@ -234,7 +234,6 @@ function buffer:read(...)
|
||||
end
|
||||
|
||||
local function readLine(chop)
|
||||
if not self.mode.t then
|
||||
local start = 1
|
||||
while true do
|
||||
local l = self.bufferRead:find("\n", start, true)
|
||||
@ -256,61 +255,6 @@ function buffer:read(...)
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
-- ?????
|
||||
io.write("\27[s\27[8m")
|
||||
local pos, buffer = 1, ""
|
||||
local function redraw()
|
||||
io.write("\27[u")
|
||||
io.write(buffer.." ")
|
||||
io.write("\27[u")
|
||||
io.write(buffer:sub(1,(#buffer-pos)+1))
|
||||
end
|
||||
while true do
|
||||
syslog("top of readline loop")
|
||||
char = readBytesOrChars(1)
|
||||
if char == "\27" then
|
||||
if readBytesOrChars(1) == "[" then
|
||||
syslog("escape code")
|
||||
local args = {""}
|
||||
repeat
|
||||
char = readBytesOrChars(1)
|
||||
--[[
|
||||
if char:match("%d") then
|
||||
args[#args] = args[#args]..char
|
||||
else
|
||||
args[#args] = tonumber(args[#args])
|
||||
args[#args+1] = ""
|
||||
end
|
||||
]]
|
||||
until not char:match("[%d;]")
|
||||
if char == "C" then -- right
|
||||
if pos > 1 then
|
||||
syslog("moving right")
|
||||
pos = pos - 1
|
||||
end
|
||||
elseif char == "D" then -- left
|
||||
if pos <= #buffer then
|
||||
syslog("moving left")
|
||||
pos = pos + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif char == "\8" then
|
||||
if #buffer > 0 and pos <= #buffer then
|
||||
buffer = buffer:sub(1, (#buffer - pos)) .. buffer:sub((#buffer - pos) + 2)
|
||||
end
|
||||
elseif char == "\13" or char == "\10" or char == "\n" then
|
||||
io.write("\n")
|
||||
if chop then buffer = buffer .. "\n" end
|
||||
return buffer
|
||||
else
|
||||
syslog("char: "..tostring(string.byte(char)))
|
||||
buffer = buffer:sub(1, (#buffer - pos) + 1) .. char .. buffer:sub((#buffer - pos) + 2)
|
||||
end
|
||||
redraw()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function readAll()
|
||||
|
@ -8,7 +8,7 @@ end
|
||||
|
||||
function io.input(fd) -- table -- table -- Sets the default input stream to *fd* if provided, either as a buffer as a path. Returns the default input stream.
|
||||
if type(fd) == "string" then
|
||||
fd=io.open(fd,"rbt")
|
||||
fd=io.open(fd,"rb")
|
||||
end
|
||||
if fd then
|
||||
os.setenv("STDIN",fd)
|
||||
|
@ -58,9 +58,6 @@ function os.getenv(k) -- gets a process' *k* environment variable
|
||||
return tTasks[cPid].e[k]
|
||||
end
|
||||
end
|
||||
function os.getTimeout()
|
||||
return nTimeout
|
||||
end
|
||||
function os.setTimeout(n)
|
||||
if type(n) == "number" and n >= 0 then
|
||||
nTimeout = n
|
||||
|
Loading…
Reference in New Issue
Block a user