Advertisement
atlasim

menu of loginsys

Oct 30th, 2023
2,990
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | None | 1 0
  1. -- Define Functions for program
  2.  
  3. local function centerText(text) -- Write centered text, Never ysed
  4.     local x,y = term.getSize()
  5.     local x2,y2 = term.getCursorPos()
  6.     term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  7.     write(text)
  8. end
  9.  
  10. local function titlebar(title) -- Write Yellow Title bar
  11.     term.clear()
  12.     term.setTextColor(colors.yellow)
  13.     term.setCursorPos(1,1)
  14.     term.write(title)
  15.     term.setTextColor(colors.white)
  16.     term.setCursorPos(1,2)
  17. end
  18.  
  19. local function invokemenu(menucontents, menutitle) -- Invokes a menu dialog
  20.     selectpos = 1
  21.     lengh = #menucontents
  22.     while true do
  23.         titlebar(menutitle)
  24.         print("")
  25.         for i=1, lengh, 1 do
  26.             if i == selectpos then
  27.                 print(" > "..menucontents[i].."")
  28.             else
  29.                 print("   "..menucontents[i].."")
  30.             end
  31.         end
  32.         a,b = os.pullEventRaw()
  33.         if a == "key" then
  34.             if b == 200 and selectpos > 1 then
  35.                 selectpos = selectpos - 1
  36.             elseif b == 208 and selectpos < lengh then
  37.                 selectpos = selectpos + 1
  38.             elseif b == 28 then
  39.                 break
  40.             end
  41.         end
  42.     end
  43.     return selectpos
  44. end
  45.  
  46. -- Start of program
  47. multishell.setTitle(shell.openTab("shell"), "Shell") -- Open default shell
  48.  
  49. while true do
  50.     multishell.setTitle(multishell.getCurrent(), "Menu")
  51.     local menu1 = invokemenu({"Programs","Shell","Logout","Power Options"},"Main Menu")
  52.     -- Program Selector
  53.     if menu1 == 1 then
  54.         local proglist = fs.list("/Programs")
  55.         local exitnumber = #proglist + 1
  56.         table.insert(proglist, "Back")
  57.         local programsmenu = invokemenu(proglist,"Programs")
  58.         if programsmenu == exitnumber then
  59.             a = 1
  60.         else
  61.             local progtorun = "/Programs/"..proglist[programsmenu]
  62.             shell.switchTab(shell.openTab(progtorun))
  63.         end
  64.     -- Open Shell
  65.     elseif menu1 == 2 then
  66.         local tabnum = shell.openTab("shell")
  67.         multishell.setTitle(tabnum, "Shell")
  68.         shell.switchTab(tabnum)
  69.     -- Logout
  70.     elseif menu1 == 3 then
  71.         shell.run("startup/loginsys")
  72.         os.exit()
  73.     -- Shutdown Options
  74.     elseif menu1 == 4 then
  75.         shutdownmenu = invokemenu({"Shutdown", "Reboot", "Back"},"Power Options")
  76.         if shutdownmenu == 1 then
  77.             os.shutdown()
  78.         elseif shutdownmenu == 2 then
  79.             os.reboot()
  80.         elseif os.shutdown == 3 then
  81.             a = 1
  82.         end
  83.     end
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement