OC-PsychOS2/module/vt-task.lua

38 lines
902 B
Lua

do
--#include "module/vt100.lua"
function vtemu(gpua,scra)
local gpu = component.proxy(gpua)
gpu.bind(scra)
local write = vt100emu(gpu)
local kba = {}
for k,v in ipairs(component.invoke(scra,"getKeyboards")) do
kba[v]=true
end
local buf = ""
os.spawn(function() dprint(pcall(function()
while true do
local ty,ka,ch = coroutine.yield()
if ty == "key_down" and kba[ka] then
if ch == 13 then ch = 10 end
if ch == 8 then
if buf:len() > 0 then
write("\8 \8")
buf = buf:sub(1,-2)
end
elseif ch > 0 then
write(string.char(ch))
buf=buf..string.char(ch)
end
end
end
end)) end,string.format("ttyd[%s:%s]",gpua:sub(1,8),scra:sub(1,8)))
local function bread()
local n = buf:find("\n")
if not n then return nil end
r, buf = buf:sub(1,n), buf:sub(n+1)
return r
end
return bread, write, function() io.write("\27[2J\27[H") end
end
end