Advertisement
roger109z

Untitled

Jul 24th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. rlib.read = function(lmt, start, cvr)
  2. local col = term.getBackgroundColor()
  3. local x, y = term.getCursorPos()
  4. if lmt == nil then
  5. local xc = term.getCursorPos()
  6. local x = term.getSize()
  7. lmt = x - xc
  8. end
  9. term.setCursorBlink(true)
  10. local outstr = {}
  11. local function Rupdate()
  12. local x3, y3 = term.getCursorPos()
  13. paintutils.drawLine(x, y, x+lmt, y, col)
  14. term.setCursorPos(x+lmt, y)
  15. for i = 1, lmt do
  16. term.setCursorPos(x+lmt-i, y)
  17. if outstr[i] ~= nil then
  18. if cvr == nil then
  19. write(outstr[#outstr-i+1])
  20. else
  21. write(cvr)
  22. end
  23. end
  24. end
  25. term.setCursorPos(x+lmt, y)
  26. end
  27. if start ~= nil then
  28. for i in string.gmatch(start, ".") do
  29. table.insert(outstr, i)
  30. end
  31. term.setCursorPos(x, y)
  32. if #outstr < lmt then
  33. for i = 1, #outstr do
  34. if cvr == nil then
  35. write(outstr[i])
  36. else
  37. write(cvr)
  38. end
  39. end
  40. else
  41. Rupdate()
  42. end
  43. end
  44. while true do
  45. if lmt == nil then
  46. return false
  47. end
  48. eve, let = os.pullEvent()
  49. if eve == "char" then
  50. outstr[#outstr+1] = let
  51. if #outstr <= lmt then
  52. if cvr == nil then
  53. write(let)
  54. else
  55. write(cvr)
  56. end
  57. else
  58. Rupdate()
  59. end
  60. elseif eve == "key" then
  61. if let == 14 and outstr ~= {} then
  62. outstr[#outstr] = nil
  63. if #outstr <= lmt then
  64. paintutils.drawLine(x, y, x+lmt, y, col)
  65. term.setCursorPos(x, y)
  66. for i = 1, #outstr do
  67. if cvr == nil then
  68. write(outstr[i])
  69. else
  70. write(cvr)
  71. end
  72. end
  73. else
  74. Rupdate()
  75. end
  76. elseif let == 28 then
  77. local restr = ""
  78. for i = 1, #outstr do
  79. restr = restr..outstr[i]
  80. end
  81. return restr
  82. elseif let == 15 then
  83. local restr = ""
  84. for i = 1, #outstr do
  85. restr = restr..outstr[i]
  86. end
  87. return restr, "tab"
  88. end
  89. end
  90. end
  91. term.setCursorBlink(false)
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement