Operating system for OpenComputers
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

41 lignes
948B

  1. do
  2. --#include "module/vt100.lua"
  3. function vtemu(gpua,scra)
  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 = ""
  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. write("\8 \8")
  20. buf = buf:sub(1,-2)
  21. end
  22. elseif ch > 0 then
  23. write(string.char(ch))
  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()
  30. while not buf:find("\n") do
  31. coroutine.yield()
  32. end
  33. local n = buf:find("\n")
  34. r, buf = buf:sub(1,n), buf:sub(n+1)
  35. dprint("bread",r)
  36. return r
  37. end
  38. return bread, write, function() io.write("\27[2J\27[H") end
  39. end
  40. end