@ -1,4 +1,13 @@
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 ( )
@ -106,7 +115,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 , tru e, true
fg , bg , ec , lb = 0xFFFFFF , 0 , fals e, true
elseif num == 7 then
local nfg , nbg = bg , fg
fg , bg = nfg , nbg
@ -150,37 +159,27 @@ 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 = " " , true , tru e
os.spawn ( function ( ) dprint ( pcall ( function ( )
local buf , lbuf , echo = " " , false , fals e
os.spawn ( function ( )
while true do
local ty , ka , ch = coroutine.yield ( )
local ty , ka , ch , kc = coroutine.yield ( )
if ty == " key_down " and kba [ ka ] then
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
elseif ch > 0 then
if echo then write ( string.char ( ch ) ) end
buf = buf .. string.char ( ch )
local outs
if ch > 0 then
outs = string.char ( ch )
end
outs = vtansi.sequences [ kc ] or outs
if outs then
if echo then write ( outs ) end
buf = buf .. outs
end
end
end
end ) ) end , string.format ( " ttyd[%s:%s] " , gpua : sub ( 1 , 8 ) , scra : sub ( 1 , 8 ) ) )
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 ( )
end
local n = buf : find ( " \n " )
r , buf = buf : sub ( 1 , n ) , buf : sub ( n + 1 )
else
r = buf
buf = " "
coroutine.yield ( )
end
coroutine.yield ( )
local r = buf
buf = " "
return r
end
local function bwrite ( d )