2019-10-27 08:34:02 -04:00
do
2020-04-09 01:44:23 -04:00
--#include "module/nvt100.lua"
2019-11-05 22:08:42 -05: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 08:34:02 -04: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-10 18:52:18 -04:00
local buf , lbuf , echo = " " , true , true
2019-10-27 08:34:02 -04: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-10 18:52:18 -04:00
if echo then write ( " \8 \8 " ) end
2019-10-27 08:34:02 -04:00
buf = buf : sub ( 1 , - 2 )
end
elseif ch > 0 then
2020-04-10 18:52:18 -04:00
if echo then write ( string.char ( ch ) ) end
2019-10-27 08:34:02 -04: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-10 18:52:18 -04: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-03 16:54:30 -05:00
coroutine.yield ( )
end
2019-10-27 08:34:02 -04:00
return r
end
2020-04-10 18:52:18 -04: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 08:34:02 -04:00
end
end