Operating system for OpenComputers
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

59 lines
1.4KB

  1. do
  2. --#include "module/nvt100.lua"
  3. function vtemu(gpua,scra) -- creates a process to handle the GPU and screen address combination *gpua*/*scra*. Returns read, write and "close" functions.
  4. local gpu = component.proxy(gpua)
  5. gpu.bind(scra)
  6. local write = vt100emu(gpu)
  7. local kba = {}
  8. for k,v in ipairs(component.invoke(scra,"getKeyboards")) do
  9. kba[v]=true
  10. end
  11. local buf, lbuf, echo = "", true, true
  12. os.spawn(function() dprint(pcall(function()
  13. while true do
  14. local ty,ka,ch = coroutine.yield()
  15. if ty == "key_down" and kba[ka] then
  16. if ch == 13 then ch = 10 end
  17. if ch == 8 then
  18. if buf:len() > 0 then
  19. if echo then write("\8 \8") end
  20. buf = buf:sub(1,-2)
  21. end
  22. elseif ch > 0 then
  23. if echo then write(string.char(ch)) end
  24. buf=buf..string.char(ch)
  25. end
  26. end
  27. end
  28. end)) end,string.format("ttyd[%s:%s]",gpua:sub(1,8),scra:sub(1,8)))
  29. local function bread(n)
  30. local r
  31. if lbuf then
  32. while not buf:find("\n") do
  33. coroutine.yield()
  34. end
  35. local n = buf:find("\n")
  36. r, buf = buf:sub(1,n), buf:sub(n+1)
  37. else
  38. r = buf
  39. buf = ""
  40. coroutine.yield()
  41. end
  42. return r
  43. end
  44. local function bwrite(d)
  45. local ba, lb, ec = write(d)
  46. buf = buf .. ba
  47. if lb ~= nil then
  48. dprint("local buffer mode: "..tostring(lb))
  49. lbuf = lb
  50. end
  51. if ec ~= nil then
  52. dprint("echo mode: "..tostring(ec))
  53. echo = ec
  54. end
  55. end
  56. return bread, bwrite, function() io.write("\27[2J\27[H") end
  57. end
  58. end