Advertisement
Marikc0

Peripheral Helper Program

Nov 20th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. pversion = "0.1"
  2.  
  3. function sortedList()
  4.    
  5.     term.clear()
  6.     p = peripheral.getNames() -- load a list of peripherals into a table
  7.     table.sort(p)
  8.  
  9.     term.clear()
  10.     term.setCursorPos(1,1)
  11.  
  12.     for i=1, #p do
  13.         term.write(i .. ". " .. p[i])
  14.         x,y = term.getCursorPos()
  15.         term.setCursorPos(1, (y+1))
  16.         sleep(0.2)
  17.     end
  18.  
  19.     print("Number of peripherals: " .. #p)
  20.     term.write("(M)ain Menu or (Q)uit: ")
  21.  
  22.     sorted_input = read()
  23.     sorted_input = string.upper(sorted_input)
  24.  
  25.     if sorted_input == "M" then
  26.         mainMenu()
  27.     elseif sorted_input == "Q" then
  28.         error("Exited")
  29.     else
  30.         mainMenu()
  31.     end
  32.    
  33. end
  34.  
  35. function pSearch()
  36.  
  37.     print("Search criteria / (M)ain menu: ")
  38.    
  39.     search_input = string.upper(read())
  40.    
  41.     if search_input == "M" then
  42.         mainMenu()
  43.     else
  44.         p = peripheral.getNames()
  45.         for i=1, #p do
  46.             if string.find(p[i], search_input) then
  47.                 print(p[i])
  48.             end
  49.         end
  50.     end
  51.  
  52.     print("(M)ain Menu or (Q)uit: ")
  53.     next_input = string.upper(read())
  54.  
  55.     if next_input == "M" then
  56.         mainMenu()
  57.     elseif next_input == "Q" then
  58.         error("Exited")
  59.     else
  60.         mainMenu()
  61.     end
  62. end
  63.  
  64. function mainMenu ()
  65.     term.clear()
  66.     term.setCursorPos(1,1)
  67.     print("Peripheral Helper Program v" .. pversion)
  68.     print("Make a selection :")
  69.     print("Sorted [l]ist of connected peripherals")
  70.     print("[S]earch for a specific peripheral")
  71.     print("[Q]uit")
  72.     term.write(": ")
  73.  
  74.     user_input = read()
  75.     user_input = string.upper(user_input)
  76.  
  77.     if user_input == "L" then
  78.         sortedList()
  79.     elseif user_input == "S" then
  80.         pSearch()
  81.     elseif user_input == "Q" then
  82.         error("Exited")
  83.     else
  84.         mainMenu()
  85.     end
  86. end
  87.  
  88. while true do
  89.  
  90.     mainMenu()
  91.  
  92. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement