Le_JuiceBOX

[OS] computerOS.lua

Mar 29th, 2024 (edited)
838
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.09 KB | None | 0 0
  1. -- CeGJp05X
  2.  
  3. local Terminal = require("/terminal").new()
  4.  
  5. function OpenSettings()
  6.     Terminal:reset()
  7.     Terminal:print("&c"..Terminal:makeSeperator("="))
  8.     Terminal:print("&dComputerOS &8- Settings")
  9.     Terminal:print("&c"..Terminal:makeSeperator("="))
  10.     Terminal:print()
  11.  
  12.     local t = {}
  13.     for i, name in pairs(settings.getNames()) do
  14.         if string.find(name,"bios.") then  
  15.         elseif string.find(name,"edit.") then  
  16.         elseif string.find(name,"shell.") then  
  17.         elseif string.find(name,"lua.") then
  18.         elseif string.find(name,"list.") then
  19.         elseif string.find(name,"paint.") then
  20.         else
  21.             table.insert(t,name)
  22.         end
  23.     end
  24.     for index, value in ipairs(t) do
  25.         print(index..". "..value)
  26.     end
  27.     Terminal:pressAnyKeyToContinue()
  28. end
  29.  
  30. function OpenShell()
  31.     Terminal:reset()
  32.     print("Opening shell...")
  33.     os.sleep(0.5)
  34.     Terminal:reset()
  35.     Terminal:reset()
  36.     Terminal:print("&c"..Terminal:makeSeperator("="))
  37.     Terminal:print("&dComputerOS &8- Shell")
  38.     Terminal:print("&c"..Terminal:makeSeperator("="))
  39.     Terminal:print()
  40.     print("Restart to go back!")
  41.     print()
  42.     return true
  43. end
  44.  
  45. function RunProgram()
  46.     Terminal:reset()
  47.     local path = Terminal:promptFilePath("/OS/Programs",false,"&1Select a program to run ~\n",1)
  48.     if path then
  49.         Terminal:reset()
  50.         print("Opening "..path.."...")
  51.         os.sleep(0.25)
  52.         shell.run(path)
  53.     else
  54.         return
  55.     end
  56. end
  57.  
  58. local mainMenu = {
  59.     {
  60.         Name = "Shell",
  61.         Func = function()
  62.            OpenShell()
  63.            return true;
  64.         end,
  65.     },
  66.     {
  67.         Name = "Applications",
  68.         Func = RunProgram,
  69.     },
  70.     {
  71.         Name = "File Explorer",
  72.         Func = require("/OS/fileExplorer"),
  73.     },
  74.     {
  75.         Name = "Update",
  76.         Func = function()
  77.             Terminal:reset()
  78.             if Terminal:promptConf("Are you sure?") then
  79.                 shell.run("/OS/update.lua")
  80.             end
  81.             Terminal:reset()
  82.         end,
  83.     },
  84.     {
  85.         Name = "Pastebin",
  86.         Func = function()
  87.             Terminal:reset()
  88.             Terminal:display(0,
  89.                 "&c"..Terminal:makeSeperator("="),
  90.                 " &dPastebin wizard ~",
  91.                 "&c"..Terminal:makeSeperator("=")
  92.             )
  93.             local _,mode = Terminal:promptOptions("Choose an option:",false,{"Run","Download","Cancel"},5)
  94.             if mode == 3 then
  95.                 return
  96.             end
  97.             Terminal:reset()
  98.             Terminal:display(0,
  99.                 "&c"..Terminal:makeSeperator("="),
  100.                 " &dPastebin wizard ~",
  101.                 "&c"..Terminal:makeSeperator("="),
  102.                 ""
  103.             )
  104.             local pasteId = Terminal:prompt("Enter the pastebin Id:")
  105.             Terminal:reset()
  106.             Terminal:display(0,
  107.                 "&c"..Terminal:makeSeperator("="),
  108.                 " &dPastebin wizard ~",
  109.                 "&c"..Terminal:makeSeperator("="),
  110.                 ""
  111.             )
  112.             if mode == 1 then
  113.                 shell.run("pastebin run "..pasteId)
  114.             elseif mode == 2 then
  115.                 Terminal:reset()
  116.                 Terminal:display(0,
  117.                     "&c"..Terminal:makeSeperator("="),
  118.                     " &dPastebin wizard ~",
  119.                     "&c"..Terminal:makeSeperator("="),
  120.                     ""
  121.                 )
  122.                 local saveLocations = {"OS/Programs/","OS/Programs/Turtle/","Custom Directory"}
  123.                 local _,fileLocInd = Terminal:promptOptions("Choose a directory:",false,saveLocations,5)
  124.                 local fileLoc = saveLocations[fileLocInd]
  125.                 if fileLocInd == 3 then
  126.                     Terminal:reset()
  127.                     Terminal:display(0,
  128.                         "&c"..Terminal:makeSeperator("="),
  129.                         " &dPastebin wizard ~",
  130.                         "&c"..Terminal:makeSeperator("="),
  131.                         ""
  132.                     )
  133.                     fileLoc = Terminal:prompt("Enter a directory to save the file into: (e.g /OS/)")
  134.                 end
  135.                 Terminal:reset()
  136.                 Terminal:display(0,
  137.                     "&c"..Terminal:makeSeperator("="),
  138.                     " &dPastebin wizard ~",
  139.                     "&c"..Terminal:makeSeperator("="),
  140.                     ""
  141.                 )
  142.                 local fileName = Terminal:prompt("Name the downloaded file: (e.g script.lua)")
  143.                 Terminal:reset()
  144.                 Terminal:display(0,
  145.                     "&c"..Terminal:makeSeperator("="),
  146.                     " &dPastebin wizard ~",
  147.                     "&c"..Terminal:makeSeperator("="),
  148.                     ""
  149.                 )
  150.                 Terminal:print("Connecting script to the updater redownloads")
  151.                 Terminal:print("this script when using this PC's updater.")
  152.                 Terminal:print()
  153.                 local addFileToUpdater = Terminal:promptConf("Connect to updater?",true)
  154.                 if addFileToUpdater then
  155.                     settings.load()
  156.                     local pastebinScripts = settings.get("PastebinScripts",{})
  157.                     table.insert(pastebinScripts,{
  158.                         FileName = fileName,
  159.                         FilePath = fileLoc,
  160.                         PasteId = pasteId
  161.                     })
  162.                     settings.set("PastebinScripts",pastebinScripts)
  163.                     settings.save()
  164.                 end
  165.                 shell.run("pastebin get "..pasteId.." "..fileLoc..fileName)
  166.                 Terminal:pressAnyKeyToContinue()
  167.             end
  168.         end,
  169.     },
  170.     {
  171.         Name = "Settings",
  172.         Func = function()
  173.             Terminal:reset()
  174.             shell.run("OS/options.lua")
  175.         end,
  176.     },
  177.     {
  178.         Name = "Lua",
  179.         Func = function()
  180.             Terminal:reset()
  181.             Terminal:display(0,
  182.             "&c"..Terminal:makeSeperator("="),
  183.             " &dLua ~",
  184.             "&c"..Terminal:makeSeperator("="),
  185.             ""
  186.             )
  187.             shell.run("lua")
  188.         end,
  189.     },
  190. }
  191.  
  192. local diskDrive = nil
  193.  
  194. function Main()
  195.     local mode = 0
  196.     fs.delete("."..Terminal:getComputerLabel() or ".Untitled")
  197.     fs.makeDir("."..Terminal:getComputerLabel() or ".Untitled")
  198.     diskDrive = peripheral.find("drive")
  199.     if diskDrive then
  200.         table.insert(mainMenu, {
  201.             Name = "Read Disk",
  202.             Func = function()
  203.                 if fs.exists("/disk/install.lua") then
  204.                     Terminal:reset()
  205.                     local resName, resInd = Terminal:promptOptions("What do you want to do?",true,{"Install","File Explorer","Cancel"})
  206.                     if resInd == 1 then
  207.                         shell.run("/disk/install.lua")
  208.                     elseif resInd == 2 then
  209.                         Terminal:promptFilePath("/disk/",true,"Choose file in disk ~")
  210.                     elseif resInd == 3 then
  211.                         return
  212.                     end
  213.                 else
  214.                     Terminal:promptFilePath("/disk/",true,"Choose file in disk ~")
  215.                     return
  216.                 end
  217.             end
  218.         })
  219.     end
  220.     local res = false
  221.     repeat
  222.         res = WriteHomeScreen()
  223.     until res
  224. end
  225.  
  226. function WriteHomeScreen()
  227.     Terminal:reset()
  228.     Terminal:display(0,
  229.         "&c"..Terminal:makeSeperator("="),
  230.         "&dComputer OS ~",
  231.         "&c"..Terminal:makeSeperator("=")
  232.     )
  233.     local m = {}
  234.     for i,data in ipairs(mainMenu) do
  235.         m[i] = (" "..data.Name)
  236.     end
  237.     if turtle == nil then
  238.         Terminal:writeLine(Terminal.size.y,"&7"..Terminal:getComputerLabel().." (ID: "..os.getComputerID()..")")
  239.     else
  240.         Terminal:writeLine(Terminal.size.y,"&7"..Terminal:getComputerLabel().." (ID: "..os.getComputerID()..") (FL: "..Terminal.formatInt(turtle.getFuelLevel())..")")
  241.     end
  242.     local _,res = Terminal:promptOptions(nil,false,m,4) -- prompt main menu options
  243.     return mainMenu[res].Func()
  244. end
  245.  
  246.  
  247. Main()
Advertisement
Add Comment
Please, Sign In to add comment