Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function go()
- local tw,th = term.getSize()
- local selected = 0
- local inp = {}
- local lbl_locs = {{16,3,"Name:"},{16,6,"Author:"},{16,9,"Install Dir:"},{16,12,"Files:"}}
- local inp_locs = {{16,4,8},{16,7,8},{16,10,10}}
- local btn_locs = {{tw-6,th,"accept"}}
- function getInput(type,key)
- if selected == 0 then return end
- inp[selected] = inp[selected] or ""
- if type == "char" then
- inp[selected] = inp[selected]..key
- elseif type == "key" then
- if key == keys.enter then
- selected = 0
- elseif key == keys.backspace then
- inp[selected] = inp[selected]:sub(1,-2)
- end
- end
- end
- function getMouseClick(x,y)
- for i,v in pairs(inp_locs) do
- if x >= v[1] and x <= v[1]+v[3]-1 and y == v[2] then
- selected = i
- return
- end
- end
- for i,v in pairs(btn_locs) do
- if x >= v[1] and x <= v[1]+#(v[3])-1 and y == v[2] then
- return "end"
- end
- end
- end
- function disp()
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.lightGray)
- for i,v in pairs(inp_locs) do
- term.setCursorPos(v[1], v[2])
- term.write(string.rep(" ",v[3]))
- term.setCursorPos(v[1], v[2])
- term.write(string.sub((inp[i] or ""),-v[3]))
- end
- term.setTextColor(colors.white)
- for i,v in pairs(btn_locs) do
- term.setCursorPos(v[1], v[2])
- term.write(v[3])
- end
- term.setBackgroundColor(colors.black)
- for i,v in pairs(lbl_locs) do
- term.setCursorPos(v[1], v[2])
- term.write(v[3])
- end
- end
- while true do
- disp()
- local ev,a1,a2,a3 = os.pullEvent()
- if ev == "char" or ev == "key" then
- getInput(ev,a1)
- elseif ev == "mouse_click" then
- if getMouseClick(a2,a3) == "end" then
- return inp
- end
- end
- end
- end
- go()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement