Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rlib.read = function(lmt, start, cvr)
- local col = term.getBackgroundColor()
- local x, y = term.getCursorPos()
- if lmt == nil then
- local xc = term.getCursorPos()
- local x = term.getSize()
- lmt = x - xc
- end
- term.setCursorBlink(true)
- local outstr = {}
- local function Rupdate()
- local x3, y3 = term.getCursorPos()
- paintutils.drawLine(x, y, x+lmt, y, col)
- term.setCursorPos(x+lmt, y)
- for i = 1, lmt do
- term.setCursorPos(x+lmt-i, y)
- if outstr[i] ~= nil then
- if cvr == nil then
- write(outstr[#outstr-i+1])
- else
- write(cvr)
- end
- end
- end
- term.setCursorPos(x+lmt, y)
- end
- if start ~= nil then
- for i in string.gmatch(start, ".") do
- table.insert(outstr, i)
- end
- term.setCursorPos(x, y)
- if #outstr < lmt then
- for i = 1, #outstr do
- if cvr == nil then
- write(outstr[i])
- else
- write(cvr)
- end
- end
- else
- Rupdate()
- end
- end
- while true do
- if lmt == nil then
- return false
- end
- eve, let = os.pullEvent()
- if eve == "char" then
- outstr[#outstr+1] = let
- if #outstr <= lmt then
- if cvr == nil then
- write(let)
- else
- write(cvr)
- end
- else
- Rupdate()
- end
- elseif eve == "key" then
- if let == 14 and outstr ~= {} then
- outstr[#outstr] = nil
- if #outstr <= lmt then
- paintutils.drawLine(x, y, x+lmt, y, col)
- term.setCursorPos(x, y)
- for i = 1, #outstr do
- if cvr == nil then
- write(outstr[i])
- else
- write(cvr)
- end
- end
- else
- Rupdate()
- end
- elseif let == 28 then
- local restr = ""
- for i = 1, #outstr do
- restr = restr..outstr[i]
- end
- return restr
- elseif let == 15 then
- local restr = ""
- for i = 1, #outstr do
- restr = restr..outstr[i]
- end
- return restr, "tab"
- end
- end
- end
- term.setCursorBlink(false)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement