Operating system for OpenComputers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
968B

  1. function vtemu(gpua,scra)
  2. local gpu,scr = component.proxy(gpua),component.proxy(scra)
  3. gpu.bind(scra)
  4. local write = vt100emu(gpu)
  5. local kba = {}
  6. for k,v in ipairs(scr.getKeyboards()) do
  7. kba[v]=true
  8. end
  9. local buf = ""
  10. os.spawn(function()
  11. while true do
  12. local ty,ka,ch = coroutine.yield()
  13. if ty == "key_down" and kba[ka] then
  14. if ch == 13 then ch = 10 end
  15. if ch == 8 then
  16. if buf:len() > 0 then
  17. write("\8 \8")
  18. buf = buf:sub(1,-2)
  19. end
  20. elseif ch > 0 then
  21. write(string.char(ch))
  22. buf = buf .. string.char(ch)
  23. end
  24. end
  25. end
  26. end,"keyboard daemon for "..gpua:sub(1,8)..":"..scra:sub(1,8))
  27. local function read(n)
  28. n = n or "\n"
  29. local rdata = ""
  30. if type(n) == "number" then
  31. rdata = buf:sub(1,n)
  32. return rdata
  33. else
  34. if n == "*a" then
  35. rdata = buf
  36. buf = ""
  37. return rdata
  38. end
  39. local pr,po = buf:match("(.-)"..n.."(.*)")
  40. buf = po or buf
  41. return pr
  42. end
  43. end
  44. return read,write
  45. end