Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local stx, sty = term.getSize()
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function drawlist(title, listr, num)
- clear()
- term.setTextColor(colors.lime)
- local list = {}
- print(title.."\n")
- for i,v in pairs(listr) do
- list[i] = v
- end
- local start = 1
- local last = #list
- if num > sty - 4 then
- start = num - (sty - 4)
- end
- local cnt = 0
- for i = start, #list do
- if cnt > sty - 4 then
- last = last - 1
- cnt = cnt - 1
- end
- cnt = cnt + 1
- end
- for m = start, last do
- local tor = true
- if tor == true then
- if m == num then
- term.setTextColor(colors.white)
- write("[")
- term.setTextColor(colors.lime)
- write("-")
- term.setTextColor(colors.white)
- write("]")
- term.setTextColor(colors.lime)
- print(" "..list[m])
- else
- term.setTextColor(colors.white)
- print("[ ] "..list[m])
- end
- end
- end
- end
- function getKey()
- local rt = nil
- function lop()
- local e, a1 = os.pullEvent("key")
- if a1 == 200 then
- rt = "up"
- elseif a1 == 208 then
- rt = "down"
- elseif a1 == 28 then
- rt = "enter"
- else
- lop()
- end
- end
- lop()
- repeat sleep(0) until rt ~= nil
- return rt
- end
- function ch(title, list)
- clear()
- local ind = 1
- local lcopy = list
- drawlist(title, lcopy, ind)
- local rt = nil
- cycle = function()
- local ke = getKey()
- if ke == "up" then
- if ind > 1 then
- ind = ind - 1
- else
- ind = #list
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "down" then
- if ind < #list then
- ind = ind + 1
- else
- ind = 1
- end
- drawlist(title, lcopy, ind)
- cycle()
- elseif ke == "enter" then
- rt = ind
- end
- end
- cycle()
- repeat sleep(0) until rt ~= nil
- return ind
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement