Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[Settings]]--
- --true for blacklist mode, programs table is the blacklist
- --false for whitelist mode, programs table is whitelist
- local blacklistMode = true
- local programs = {}
- local selector = {"[", "]"}
- --[[Variables & peripherals]]--
- local width, height = term.getSize()
- local list = {}
- if blacklistMode then
- for i, name in pairs(fs.list("/")) do
- if not fs.isDir(name) then
- allowed = true
- for j, black in pairs(programs) do
- if black == name then
- allowed = false
- end
- end
- if allowed then
- table.insert(list, name)
- end
- end
- end
- else
- list = programs
- end
- --[[Functions]]--
- local function round(number)
- return math.floor(number + .5)
- end
- local function spaces(number)
- for i = 1, number do
- write(" ")
- end
- end
- local function menu(list, selector)
- local selector = selector or {"[", "]"}
- local longestItem = 0
- local width, height = term.getSize()
- for i, item in pairs(list) do
- if #item > longestItem then
- longestItem = #item
- end
- end
- local selected = 1
- local startX = round((width / 2) - (longestItem / 2)) - 2
- local startY = round((height / 2) - (#list / 2))
- for i, j in pairs(list) do
- if #j > longestItem then
- longestItem = #j
- end
- end
- local running = true
- while running do
- curX = startX
- curY = startY
- for i, item in pairs(list) do
- term.setCursorPos(curX, curY)
- if i == selected then
- write(selector[1].." "..item)
- spaces(longestItem - #item + 1)
- write(selector[2])
- else
- spaces(2)
- write(item)
- spaces(longestItem - #item + 2)
- end
- curY = curY + 1
- end
- event, key = os.pullEvent("key")
- if key == keys.up and selected > 1 then
- selected = selected - 1
- elseif key == keys.down and selected < #list then
- selected = selected + 1
- elseif key == keys.enter then
- return list[selected]
- elseif key == keys.q then
- return "quit"
- end
- end
- end
- local function centerPrint(text, y)
- local width, height = term.getSize()
- term.setCursorPos(round(( width / 2 ) - ( #text / 2 )), y)
- print(text)
- end
- --[[Main program]]--
- shell.run("clear")
- centerPrint("Which program do you want to run?", 2)
- local option = menu(list, selector)
- shell.run("clear")
- shell.run(option)
Advertisement
Add Comment
Please, Sign In to add comment