Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function read(m,length,input)
- local pos = {}
- local sPos = 0
- local periphs = {}
- local erase_queue = false
- if input == nil then input = "" end
- if type(m[1]) ~= "table" then local _temp = m periphs[1] = _temp else periphs = m end
- for i,v in pairs(periphs) do
- pos[i] = {v.getCursorPos()}
- v.setCursorBlink(true)
- end
- repeat
- for i,v in pairs(periphs) do
- v.setCursorPos(pos[i][1], pos[i][2])
- v.write(input)
- if erase_queue then
- x1,y1 = v.getCursorPos()
- v.setCursorPos(xl-1,pos[i][2])
- v.write(" ")
- end
- v.setCursorPos(pos[i][1]-sPos,pos[i][2])
- erase_queue = false
- end
- local ev, p1 = os.pullEvent()
- if ev == 'char' then
- if #input < length then
- input = input .. p1
- end
- elseif ev == 'key' then
- if p1 == keys.backspace then
- if #input ~= 0 then
- erase_queue = true
- end
- input = input:sub(1, #input - 1)
- elseif p1 == keys.left then
- if #input ~= 0 then
- sPos = sPos + 1
- end
- elseif p1 == keys.right then
- if #input ~= length-1 then
- sPos = sPos - 1
- end
- end
- end
- until ev == 'key' and p1 == keys.enter or ev == 'mouse_click' or ev == 'monitor_touch'
- for i,v in pairs(periphs) do
- v.setCursorBlink(false)
- v.setCursorPos(pos[i][1],pos[i][2])
- end
- return input, ev, p1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement