Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pversion = "0.1"
- function sortedList()
- term.clear()
- p = peripheral.getNames() -- load a list of peripherals into a table
- table.sort(p)
- term.clear()
- term.setCursorPos(1,1)
- for i=1, #p do
- term.write(i .. ". " .. p[i])
- x,y = term.getCursorPos()
- term.setCursorPos(1, (y+1))
- sleep(0.2)
- end
- print("Number of peripherals: " .. #p)
- term.write("(M)ain Menu or (Q)uit: ")
- sorted_input = read()
- sorted_input = string.upper(sorted_input)
- if sorted_input == "M" then
- mainMenu()
- elseif sorted_input == "Q" then
- error("Exited")
- else
- mainMenu()
- end
- end
- function pSearch()
- print("Search criteria / (M)ain menu: ")
- search_input = string.upper(read())
- if search_input == "M" then
- mainMenu()
- else
- p = peripheral.getNames()
- for i=1, #p do
- if string.find(p[i], search_input) then
- print(p[i])
- end
- end
- end
- print("(M)ain Menu or (Q)uit: ")
- next_input = string.upper(read())
- if next_input == "M" then
- mainMenu()
- elseif next_input == "Q" then
- error("Exited")
- else
- mainMenu()
- end
- end
- function mainMenu ()
- term.clear()
- term.setCursorPos(1,1)
- print("Peripheral Helper Program v" .. pversion)
- print("Make a selection :")
- print("Sorted [l]ist of connected peripherals")
- print("[S]earch for a specific peripheral")
- print("[Q]uit")
- term.write(": ")
- user_input = read()
- user_input = string.upper(user_input)
- if user_input == "L" then
- sortedList()
- elseif user_input == "S" then
- pSearch()
- elseif user_input == "Q" then
- error("Exited")
- else
- mainMenu()
- end
- end
- while true do
- mainMenu()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement