2019-10-27 23:34:02 +11:00
do
2020-04-09 15:44:23 +10:00
--#include "module/nvt100.lua"
2019-11-06 14:08:42 +11:00
function vtemu ( gpua , scra ) -- creates a process to handle the GPU and screen address combination *gpua*/*scra*. Returns read, write and "close" functions.
2019-10-27 23:34:02 +11:00
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
2020-04-11 08:52:18 +10:00
local buf , lbuf , echo = " " , true , true
2019-10-27 23:34:02 +11:00
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
2020-04-11 08:52:18 +10:00
if echo then write ( " \8 \8 " ) end
2019-10-27 23:34:02 +11:00
buf = buf : sub ( 1 , - 2 )
end
elseif ch > 0 then
2020-04-11 08:52:18 +10:00
if echo then write ( string.char ( ch ) ) end
2019-10-27 23:34:02 +11:00
buf = buf .. string.char ( ch )
end
end
end
end ) ) end , string.format ( " ttyd[%s:%s] " , gpua : sub ( 1 , 8 ) , scra : sub ( 1 , 8 ) ) )
2020-04-11 08:52:18 +10:00
local function bread ( n )
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 = " "
2019-11-04 08:54:30 +11:00
coroutine.yield ( )
end
2019-10-27 23:34:02 +11:00
return r
end
2020-04-11 08:52:18 +10:00
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
2019-10-27 23:34:02 +11:00
end
end