SHARE
TWEET

uOS

a guest Mar 19th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Variables
  2. allColors = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  3. select_color = 12
  4. background_color = 1
  5. outline_color = 8
  6. text_color = 16
  7. text_color_selected = 1
  8. page = 0
  9. setScreen = 1
  10. --Functions
  11. function cls()
  12.   term.setBackgroundColor(allColors[background_color])
  13.   term.setTextColor(allColors[text_color])
  14.   term.clear()
  15.   term.setCursorPos(1,1)
  16. end
  17. function folder()
  18.   screen = 3
  19.   page = 0
  20.   selection = 1
  21.   title = "Folder - "..itemsDir[selection_line_true]
  22.   items = fs.list("/"..items[selection_line_true].."/")
  23.   table.insert(items, ">Back")
  24.   itemsDir = items
  25.   for i=1,#items do
  26.     if fs.isDir(items[i]) == true then
  27.       info = ">>"..items[i]
  28.       simpleVar = i
  29.       table.remove(items, i)
  30.       table.insert(items, i, info)
  31.     end
  32.   end
  33. end
  34. function getItems()
  35.   title = "Page 1"
  36.   page = 0
  37.   --items = {"Hello World!","Votesim","Hello World 3!"}
  38.   items = fs.list("")
  39.   table.insert(items, ">Settings")
  40.   table.insert(items, ">Exit")
  41.   itemsDir = {}
  42.   for i=1,#items do
  43.    table.insert(itemsDir,items[i])
  44.   end
  45.   for i=1,#items do
  46.     if fs.isDir(items[i]) == true then
  47.       info = ">>"..items[i]
  48.       simpleVar = i
  49.       table.remove(items, i)
  50.       table.insert(items, i, info)
  51.     end
  52.   end
  53.   --table.insert(items, 1, "< Page >")
  54.   selection = 1
  55.   screen = 1
  56. end
  57. function settingsInitialize()
  58.   settingsEnterFix = 0
  59.   screen = 2
  60.   title = "Settings"
  61.   items = {"Selection Color","Background Color","Outline Color","Text Color","Text Color(Selected)","Enable Time","Back"}
  62. end
  63. function settingsUse()
  64.   if selection == 1 then
  65.     if select_color == 16 then
  66.       select_color = 1
  67.     else
  68.       select_color = select_color + 1
  69.     end
  70.   end
  71.   if selection == 2 then
  72.     if background_color == 16 then
  73.       background_color = 1
  74.     else
  75.       background_color = background_color + 1
  76.     end
  77.   end
  78.   if selection == 3 then
  79.     if outline_color == 16 then
  80.       outline_color = 1
  81.     else
  82.       outline_color = outline_color + 1
  83.     end
  84.   end
  85.   if selection == 4 then
  86.     if text_color == 16 then
  87.       text_color = 1
  88.     else
  89.       text_color = text_color + 1
  90.     end
  91.   end
  92.   if selection == 5 then
  93.     if text_color_selected == 16 then
  94.       text_color_selected = 1
  95.     else
  96.       text_color_selected = text_color_selected + 1
  97.     end
  98.   end
  99. end
  100. function draw()
  101.   pages = math.floor((#items + 1) / 16)
  102.   display_page = page + 1
  103.   term.setBackgroundColor( allColors[background_color] )
  104.   term.clear()
  105.   paintutils.drawBox(2, 2, 50, 18, allColors[outline_color])
  106.   term.setCursorPos(2,1)
  107.   term.setTextColor( allColors[text_color_selected] )
  108.   if screen ~= 1 then
  109.     print(title)
  110.   else
  111.     print("Page "..display_page)
  112.   end
  113.   term.setTextColor( allColors[text_color] )
  114.   term.setBackgroundColor( allColors[background_color] )
  115.   min_amount = page * 16
  116.   max_amount = (page + 1) * 15
  117.   for i=min_amount,max_amount do
  118.     line=i - min_amount + display_page + 1
  119.     selection_line = i - (page * 15)
  120.     if selection_line == selection then
  121.       term.setBackgroundColor( allColors[background_color] )
  122.       term.setTextColor( allColors[text_color_selected] )
  123.       paintutils.drawLine(3, line, 49, line, allColors[select_color])
  124.       term.setCursorPos(3,line)
  125.       print(items[i])
  126.     else
  127.       term.setBackgroundColor( allColors[background_color] )
  128.       term.setTextColor( allColors[text_color] )
  129.       term.setCursorPos(3,line)
  130.       print(items[i])
  131.     end
  132.   end
  133.   --term.setCursorPos(1,1)
  134.   --print(screen)
  135. end
  136. --Main
  137. getItems()
  138. while true do
  139.   draw()
  140.   selection_line_true = selection + (page * 15)
  141.   local event, key, isHeld = os.pullEvent("key")
  142.   if key == keys.down then
  143.     if selection_line_true ~= #items then
  144.       if selection ~= 15 then
  145.         selection = selection + 1
  146.       end
  147.     end
  148.   end
  149.   if key == keys.up then
  150.     if selection ~= 1 then
  151.       selection = selection - 1
  152.     end
  153.   end
  154.   if key == keys.right then
  155.     if screen == 1 then
  156.       if page ~= pages then
  157.         page = page + 1
  158.         selection = 1
  159.       end
  160.     end
  161.   end
  162.   if key == keys.left then
  163.     if screen == 1 then
  164.       if page ~= 0 then
  165.         page = page - 1
  166.         selection = 1
  167.       end
  168.     end
  169.   end
  170.   if key == keys.enter then
  171.     if screen == 1 then
  172.       if selection_line_true == #items then
  173.         os.reboot()
  174.       else
  175.         settingsCheck = #items - 1
  176.         if selection_line_true == settingsCheck then
  177.           prev_settings_page = page
  178.           page = 0
  179.           settingsInitialize()
  180.         else
  181.           checkDir ="/"..tostring(itemsDir[selection_line_true])
  182.           if fs.isDir(itemsDir[selection_line_true]) ~= true then
  183.             cls()
  184.             shell.run(items[selection_line_true])
  185.           end
  186.  
  187.           if fs.isDir(itemsDir[selection_line_true]) == true then
  188.             folder()
  189.           end
  190.         end
  191.       end
  192.     end
  193.     if screen == 2 then
  194.       if selection == #items then
  195.         screen = 1
  196.         selection = 1
  197.         page = prev_settings_page + 1
  198.         getItems()
  199.       else
  200.         settingsEnterFix = settingsEnterFix + 1
  201.         if settingsEnterFix > 1 then
  202.           settingsUse()
  203.         end
  204.       end
  205.     end
  206.     if screen == 3 then
  207.       if selection_line_true == #items then
  208.         screen = 1
  209.         getItems()
  210.       end
  211.     end
  212.   end
  213.   if key == keys.space then
  214.     if (items[selection_line_true] ~= ">Settings") and (items[selection_line_true] ~= ">Exit") then
  215.       if fs.isDir(itemsDir[selection_line_true].."/") ~= true then
  216.         term.setBackgroundColor( allColors[outline_color])
  217.         paintutils.drawLine(3,9,49,9)
  218.         term.setCursorPos(2,1)
  219.         term.setTextColor(allColors[text_color_selected])
  220.         print("Enter Parameters")
  221.         term.setTextColor(allColors[text_color])
  222.         term.setBackgroundColor( allColors[background_color])
  223.         paintutils.drawFilledBox(3,3,49,8)
  224.         term.setCursorPos(3,3)
  225.         print("Start '"..items[selection_line_true].."' with below parameters.")
  226.         term.setCursorPos(3,5)
  227.         os.sleep(0.15)
  228.         parameters = read()
  229.         if parameters ~= "" then
  230.           cls()
  231.           shell.run(items[selection_line_true],parameters)
  232.         end
  233.       end
  234.     end
  235.   end
  236. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top