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.

44 lines
948B

  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 and buf:len() > 0 then
  16. write("\8 \8")
  17. buf = buf:sub(1,-2)
  18. elseif ch > 0 then
  19. write(string.char(ch))
  20. buf = buf .. string.char(ch)
  21. end
  22. end
  23. end
  24. end,"keyboard daemon for "..gpua:sub(1,8)..":"..scra:sub(1,8))
  25. local function read(n)
  26. n = n or "\n"
  27. local rdata = ""
  28. if type(n) == "number" then
  29. rdata = buf:sub(1,n)
  30. return rdata
  31. else
  32. if n == "*a" then
  33. rdata = buf
  34. buf = ""
  35. return rdata
  36. end
  37. local pr,po = buf:match("(.-)"..n.."(.*)")
  38. buf = po or buf
  39. return pr
  40. end
  41. end
  42. return read,write
  43. end