Advertisement
Guest User

os

a guest
Nov 8th, 2019
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.26 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. --Variables
  3. local w,h = term.getSize()
  4. local nOpt = 1
  5. local scr = 1 --Screen ID (1 = smenu 2 = App 3 = opt 4 = Util
  6. term.setTextColor( colors.green )
  7. --
  8. --PrintCen
  9. function printCentered (y,s)
  10.   local x = math.floor((w - string.len(s)) / 2)
  11.   term.setCursorPos(x,y)
  12.   term.clearLine()
  13.   term.write(s)  
  14. end
  15. --Draw menu
  16.  
  17.  
  18.  
  19. local function drawMenu()
  20.   term.clear()
  21.   term.setCursorPos(1,2)
  22.   term.write("BasOS Ver. V1.0 Dev build")
  23.     term.setCursorPos(1,3)
  24.     term.write("")
  25.   term.setCursorPos(1,18)
  26.   shell.run("time")
  27.   term.setCursorPos(w-11,1)
  28.  
  29.      if nOpt == 1 and scr == 1 then
  30.     term.write("Applications")
  31.   elseif nOpt == 2 and scr == 1 then
  32.     term.write("Options")
  33.  
  34.   elseif nOpt == 3 and scr == 1  then
  35.     term.write("Shutdown")
  36.   elseif nOpt == 1 and scr == 2 then
  37.     term.write("Games")
  38.   elseif nOpt == 2  and scr == 2 then
  39.     term.write("Utility")
  40.   elseif nOpt == 3 and scr == 2   then
  41.     term.write("Adventure")
  42.   elseif nOpt == 4 and scr == 2  then
  43.     term.write("Shell")
  44.       elseif nOpt == 5 and scr == 2  then
  45.  
  46.      elseif nOpt == 1 and scr == 3 then
  47.     term.write("Password")
  48.   elseif nOpt == 2 and scr == 3 then
  49.  
  50.     else
  51.     end
  52.  
  53. end
  54. --GUI
  55. term.clear()
  56.  
  57. local function dA()
  58.     scr = 1
  59.   printCentered(math.floor(h/2) - 3, "")
  60.   printCentered(math.floor(h/2) - 2, "Start Menu")
  61.   printCentered(math.floor(h/2) - 1, "")
  62.   printCentered(math.floor(h/2) + 0, ((nOpt == 1) and "[-> Applications <-]") or "Applications")
  63.   printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Options <-]") or "Options" )
  64.   printCentered(math.floor(h/2) + 2, ((nOpt == 3) and "[-> Shut-down <-]") or "Shut-down" )
  65.   printCentered(math.floor(h/2) + 3, ((nOpt == 4) and "[-> Reboot <-]") or "Reboot" )
  66. end  
  67. local function dBA()
  68. scr = 21
  69.  
  70.   printCentered(math.floor(h/2) - 5, "")
  71.   printCentered(math.floor(h/2) - 4, "")
  72.   printCentered(math.floor(h/2) - 2, "Game Menu")
  73.   printCentered(math.floor(h/2) - 1, "")
  74.  
  75.   printCentered(math.floor(h/2) + 0, ((nOpt == 1) and "[-> Worm <-]") or "Worm" )
  76.   printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Minesweeper <-]") or "Minesweeper" )
  77.    printCentered(math.floor(h/2) + 2, ((nOpt == 3) and "[-> Adventure <-]") or "Adventure" )
  78.   printCentered(math.floor(h/2) + 3, ((nOpt == 4) and "[-> Back <-]") or "Back" )
  79.  
  80.  
  81.   end
  82.   local function dB()--Applications
  83.   scr = 2
  84.  
  85.   printCentered(math.floor(h/2) - 5, "")
  86.   printCentered(math.floor(h/2) - 4, "")
  87.   printCentered(math.floor(h/2) - 2, "Applications Menu")
  88.   printCentered(math.floor(h/2) - 1, "")
  89.  
  90.   printCentered(math.floor(h/2) + 0, ((nOpt == 2) and "[-> Games <-]") or "Games" )
  91.   printCentered(math.floor(h/2) + 1, ((nOpt == 3) and "[-> Utility <-]") or "Utility" )
  92.    
  93.   printCentered(math.floor(h/2) + 2, ((nOpt == 4) and "[-> Shell <-]") or "Shell" )
  94.   printCentered(math.floor(h/2) + 3, ((nOpt == 5) and "[-> Back <-]") or "Back" )
  95.   end
  96.     local function dBB()--Utility Menu
  97.   scr = 22
  98.  
  99.   printCentered(math.floor(h/2) - 5, "")
  100.   printCentered(math.floor(h/2) - 4, "")
  101.   printCentered(math.floor(h/2) - 2, "Utility Menu")
  102.   printCentered(math.floor(h/2) - 1, "")
  103.  
  104.   printCentered(math.floor(h/2) + 0, ((nOpt == 2) and "[-> Ink <-]") or "Ink" )
  105.   printCentered(math.floor(h/2) + 1, ((nOpt == 3) and "[-> Disk <-]") or "Disk" )
  106.   printCentered(math.floor(h/2) + 2, ((nOpt == 4) and "[-> LuaIDE <-]") or "LuaIDE" )
  107.   printCentered(math.floor(h/2) + 3, ((nOpt == 5) and "[-> Back <-]") or "Back" )
  108.   end
  109.   local function dC()
  110. scr = 3
  111.     local d = fs.open("des", "r")
  112.   printCentered(math.floor(h/2) - 3, "")
  113.   printCentered(math.floor(h/2) - 2, "Options Menu")
  114.   printCentered(math.floor(h/2) - 1, "")
  115.   printCentered(math.floor(h/2) + 0, ((nOpt == 1) and "[-> Password <-]") or "Password" )
  116.   if d.readAll() == "t" then
  117.   local g = 1
  118.     printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Disable password <-]") or "Disable password" )
  119.     else
  120.     g = 0
  121.      printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Enable password <-]") or "Enable password" )
  122.     end
  123.   printCentered(math.floor(h/2) + 2, ((nOpt == 3) and "[-> Back <-]") or "Back" )
  124.     printCentered(math.floor(h/2) + 3, ((nOpt == 4) and "         ") or "          " )
  125.       printCentered(math.floor(h/2) + 4, ((nOpt == 5) and "          ") or "          " )
  126.   end
  127.  local function Pw()
  128. scr = 25
  129. term.clear()
  130. local title = disk.getAudioTitle("Bottom")
  131. printCentered(math.floor(h/2) - 3, "Music Disc Menu")
  132. printCentered(math.floor(h/2) - 2, ""..disk.getAudioTitle("bottom"))
  133.   printCentered(math.floor(h/2) + 0, ((nOpt == 1) and "[-> Play <-]") or "Play")
  134.   printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Stop <-]") or "Stop")
  135.   printCentered(math.floor(h/2) + 2, ((nOpt == 3) and "[-> Back <-]") or "Back")
  136.  
  137. end
  138. local function PwB()
  139. scr = 251
  140. term.clear()
  141.  
  142. printCentered(math.floor(h/2) - 3, "Floppy Disk Menu")
  143.  
  144.   printCentered(math.floor(h/2) + 0, ((nOpt == 1) and "[-> Data <-]") or "Data")
  145.   printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Name <-]") or "Name")
  146.   printCentered(math.floor(h/2) + 2, ((nOpt == 3) and "[-> Back <-]") or "Back")
  147.  
  148. end
  149. local function PwC()
  150. scr = 252
  151. term.clear()
  152. printCentered(math.floor(h/2) - 3, "Name Disk")
  153.  
  154.   printCentered(math.floor(h/2) - 3, "Input Name:")
  155. printCentered(math.floor(h/2) + 0, "")
  156. local input = read()
  157. disk.setLabel("bottom", input)
  158. PwB()
  159. end
  160. local function pset()
  161. while true do
  162. scr = 252
  163. term.clear()
  164. if fs.exists("pass") == true then
  165. shell.run("delete pass")
  166. end
  167.  
  168.  
  169. printCentered(math.floor(h/2) - 3, "Input new password")
  170.  
  171.   printCentered(math.floor(h/2) - 3, "        ")
  172. printCentered(math.floor(h/2) + 0, "")
  173. local input = read()
  174.  
  175. print("Invalid password!")
  176.  
  177.  
  178. local h = fs.open("pass", "w")
  179. h.write(input)
  180. scr = 3
  181.  
  182. dC()
  183. break
  184.  
  185. end
  186. end
  187.  
  188. function data()
  189. term.clear()
  190. shell.run("cd disk")
  191. end
  192.   function Wtd ()
  193.   while true do
  194.  
  195.   local e,p = os.pullEvent()
  196.     if e == "key" then
  197.         local key = p
  198.         if key == 17 or key == 200 then
  199.           term.setCursorPos(1,18)
  200.   shell.run("time")
  201.             if nOpt > 1 and scr == 1 then
  202.             nOpt = nOpt - 1
  203.             drawMenu()
  204.             dA()
  205.             elseif nOpt > 1 and scr == 25 then
  206.             nOpt = nOpt - 1
  207.             drawMenu()
  208.             Pw()
  209.             elseif nOpt > 1 and scr == 251 then
  210.             nOpt = nOpt - 1
  211.             drawMenu()
  212.             PwB()
  213.             elseif nOpt > 2 and scr == 2 then
  214.             nOpt = nOpt - 1
  215.             drawMenu()
  216.             dB()
  217.             elseif nOpt > 1 and scr == 3 then
  218.             nOpt = nOpt - 1
  219.             drawMenu()
  220.             dC()
  221.             elseif nOpt > 2 and scr == 22 then
  222.             nOpt = nOpt - 1
  223.             drawMenu()
  224.             dBB()
  225.             elseif nOpt > 1 and scr == 21 then
  226.             nOpt = nOpt - 1
  227.             drawMenu()
  228.             dBA()
  229.             else
  230.             end
  231.             elseif key == 31 or key == 208 then
  232.             if nOpt < 4 and scr == 1 then
  233.             nOpt = nOpt + 1
  234.             drawMenu()
  235.             dA()
  236.             elseif nOpt < 5 and scr == 2 then
  237.             nOpt = nOpt + 1
  238.             drawMenu()
  239.             dB()
  240.             elseif nOpt < 5 and scr == 2 then
  241.             nOpt = nOpt + 1
  242.             drawMenu()
  243.             dB()
  244.             elseif nOpt < 2 and scr == 3 then
  245.             nOpt = nOpt + 1
  246.             drawMenu()
  247.             dC()
  248.             elseif nOpt < 3 and scr == 3 then
  249.             nOpt = nOpt + 1
  250.             drawMenu()
  251.             dC()
  252.             elseif nOpt < 5 and scr == 22 then
  253.             nOpt = nOpt + 1
  254.             drawMenu()
  255.             dBB()
  256.         elseif nOpt < 4 and scr == 21 then
  257.             nOpt = nOpt + 1
  258.             drawMenu()
  259.             dBA()
  260.             elseif nOpt < 3 and scr == 251 then
  261.             nOpt = nOpt + 1
  262.             drawMenu()
  263.             PwB()
  264.             elseif nOpt < 3 and scr == 25 then
  265.             nOpt = nOpt + 1
  266.             drawMenu()
  267.             Pw()
  268.             else
  269.             end
  270.            
  271.             elseif key == 28 then
  272.             if nOpt == 3 and scr == 1 then
  273.                 printCentered(math.floor(h/2) - 2, "Shutting Down...")
  274.                 sleep(1)
  275.                 printCentered(math.floor(h/2) - 2, "                ")
  276.                 printCentered(math.floor(h/2) - 2, "")
  277.                 shell.run("shutdown")
  278.                 term.clear()
  279.             end
  280.             if nOpt == 4 and scr == 1 then
  281.                 printCentered(math.floor(h/2) - 2, "Rebooting...")
  282.                 sleep(1)
  283.                 printCentered(math.floor(h/2) - 2, "                ")
  284.                 printCentered(math.floor(h/2) - 2, "")
  285.                 shell.run("reboot")
  286.                 term.clear()
  287.             end
  288.         if nOpt == 3 and scr == 1 then
  289.         printCentered(math.floor(h/2) - 2, "Shutting Down...")
  290.         sleep(1)
  291.         printCentered(math.floor(h/2) - 1, "")
  292.             shell.run("shutdown")
  293.         end
  294.         if nOpt == 1 and scr == 1 then
  295.         scr = 2
  296.         nOpt = 2
  297.         drawMenu()
  298.         dB()
  299.         Wtd()
  300.         end
  301.         if nOpt == 1 and scr == 251 then
  302.         term.setCursorPos(1,1)
  303.         data()
  304.         print("type 'cd ..' then 'os' to return. type 'ls' for drive content")
  305.        
  306.        
  307.         shell.run("shell")
  308.         --shell.run("ls")
  309.         break
  310.         end
  311.         if nOpt == 3 and scr == 22 then
  312.        
  313.         nOpt = 1
  314.         drawMenu()
  315.         if disk.hasAudio("bottom") == true then
  316.         scr = 25
  317.         Pw()
  318.        
  319.         elseif disk.hasData("bottom") == true then
  320.         scr = 251
  321.         PwB()
  322.         else
  323.         end
  324.        
  325.         end
  326.         if nOpt == 5 and scr == 2 then
  327.         scr = 1
  328.         nOpt = 1
  329.         drawMenu()
  330.         dA()
  331.         Wtd()
  332.         end
  333.         if nOpt == 3 and scr == 2 then
  334.         scr = 22
  335.         nOpt = 1
  336.         dBB()
  337.         Wtd()
  338.         end
  339.         if nOpt == 3 and scr == 3 then
  340.         scr = 1
  341.         nOpt = 1
  342.    
  343.         dA()
  344.         end
  345.         if nOpt == 2 and scr == 3 then
  346.             local d = fs.open("des", "w")
  347.        
  348.            
  349.             if g == 0 then
  350.            
  351.         d.write("t")
  352.         d.close()
  353.         g = 1
  354.         dC()
  355.         printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Disable password <-]") or "Disable password" )
  356.         elseif g == 1 then
  357.        
  358.         d.write("f")
  359.         d.close()
  360.         g = 0
  361.         dC()
  362.         printCentered(math.floor(h/2) + 1, ((nOpt == 2) and "[-> Enable password <-]") or "Enable password" )
  363.         end
  364.    
  365.        
  366.            
  367.        
  368.         end
  369.         if nOpt == 1 and scr == 3 then
  370.         pset()
  371.         end
  372.         if nOpt == 2 and scr == 1 then
  373.         scr = 3
  374.         nOpt = 1
  375.    
  376.         dC()
  377.         end
  378.         if nOpt == 2 and scr == 2 then
  379.         scr = 21
  380.         nOpt = 1
  381.         dBA()
  382.         Wtd()
  383.         end
  384.         if nOpt == 1 and scr == 21 then
  385.         local newTabID = multishell.launch({}, "osdata/snake")
  386.  
  387. multishell.setTitle(newTabID, "Snake")
  388. multishell.setFocus(newTabID)
  389.         end
  390.         if nOpt == 2 and scr == 22 then
  391.         local newTabID = multishell.launch({}, "osdata/ink")
  392.  
  393. multishell.setTitle(newTabID, "Ink")
  394. multishell.setFocus(newTabID)
  395.         end
  396.         if nOpt == 4 and scr == 22 then
  397.         local newTabID = multishell.launch({}, "luaide")
  398.  
  399. multishell.setTitle(newTabID, "LUAIDE")
  400. multishell.setFocus(newTabID)
  401.         end
  402.         if nOpt == 2 and scr == 21 then
  403.         local newTabID = multishell.launch({}, "osdata/minesweep")
  404.  
  405. multishell.setTitle(newTabID, "Mines")
  406. multishell.setFocus(newTabID)
  407.         end
  408.                 if nOpt == 3 and scr == 21 then
  409.         local newTabID = multishell.launch({}, "rom/programs/fun/adventure")
  410.  
  411. multishell.setTitle(newTabID, "Advent")
  412. multishell.setFocus(newTabID)
  413.         end
  414.         if nOpt == 4 and scr == 2 then
  415.         term.clear()
  416.         term.setCursorPos(1,1)
  417.         print("Type 'os' to return.")
  418.         shell.run("shell")
  419.         break
  420.         end
  421.         if nOpt == 5 and scr == 22 then
  422.             nOpt = 2
  423.             scr = 2
  424.             drawMenu()
  425.             dB()
  426.             end
  427.             if nOpt == 3 and scr == 25 then
  428.             nOpt = 1
  429.             scr = 22
  430.             drawMenu()
  431.             dBB()
  432.             end
  433.             if nOpt == 3 and scr == 251 then
  434.             nOpt = 1
  435.             scr = 22
  436.             drawMenu()
  437.             dBB()
  438.             end
  439.             if nOpt == 2 and scr == 251 then
  440.             nOpt = 1
  441.             scr = 252
  442.             drawMenu()
  443.             PwC()
  444.             end
  445.             if nOpt == 1 and scr == 25 then
  446.             disk.playAudio("bottom")
  447.             end
  448.             if nOpt == 2 and scr == 25 then
  449.             disk.stopAudio("bottom")
  450.             end
  451.         if nOpt == 4 and scr == 21 then
  452.        
  453.         scr = 2
  454.         nOpt = 2
  455.         drawMenu()
  456.         dB()
  457.         Wtd()  
  458.             end
  459.         end
  460.         end
  461.         end
  462.         end
  463.        
  464.         term.clear()
  465.          --Display
  466.   drawMenu()
  467.   dA()
  468.   Wtd()
  469.         --cond
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement