CharlieOS

setup

Jun 30th, 2017
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.87 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2.  
  3. local w,h = term.getSize()
  4.  
  5. --Print Centered Function
  6. function printCentered(y,s,c)
  7.     local x = math.floor((w - string.len(s)) /2)
  8.     term.setCursorPos(x,y)
  9.     term.setTextColor(c or colors.white)
  10.     term.clearLine()
  11.     term.write(s)
  12. end
  13.  
  14. function printC(s,c)
  15.     term.setTextColor(c or colors.white)
  16.     print(s)
  17. end
  18.  
  19. --Draw Menu Function
  20.  
  21. local nOption = 1
  22.  
  23. local function drawMenu()
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26.     term.write("")
  27.    
  28.     term.setCursorPos(w-11,1)
  29.     if nOption == 1 then
  30.         term.write("Install")
  31.     elseif nOption == 2 then
  32.         term.write("Uninstall")
  33.     else
  34.         end
  35. end
  36.  
  37. --Interface
  38. term.clear()
  39. local function drawFrontend()
  40.     term.setCursorPos(1,1)
  41.     printC("+-------------------------------------------------+", colors.yellow)
  42.     printC("|                                                 |", colors.yellow)
  43.     term.setCursorPos(22,2)
  44.     printC("CharlieOS", colors.lime)
  45.     printC("|                                                 |", colors.yellow)
  46.     term.setCursorPos(23,3)
  47.     printC("dev1.0b")
  48.     printC("+-------------------------------------------------+", colors.yellow)
  49.     printCentered(math.floor(h/2) + 0, ((nOption == 1 and "[ Install ]") or "Install"), colors.lime)
  50.     printCentered(math.floor(h/2) + 1, ((nOption == 2 and "[ Uninstall ]") or "Uninstall"), colors.red)
  51.     printCentered(math.floor(h/2) + 2, ((nOption == 3 and "[ About ]") or "About"), colors.purple)
  52. end
  53.  
  54. --About
  55. local function about()
  56.     while true do
  57.     term.clear()
  58.     printCentered(math.floor(h/2) + 0, "CharlieOS is created by: Charlestone Maru")
  59.     printCentered(math.floor(h/2) + 1, "Contact [email protected]")
  60.     printCentered(math.floor(h/2) + 2, "To help me improve this OS.")
  61.     term.setCursorPos(1,19)
  62.     term.setTextColor(colors.yellow)
  63.     print("Press Enter to go back...")
  64.     local e,p = os.pullEvent()
  65.     if e == "key" then
  66.         local key = p
  67.         if key == 28 then
  68.         shell.run("setup")
  69.         end
  70.     end
  71. end
  72. end
  73.  
  74. --Install
  75. local function install()
  76.     while true do
  77.     term.clear()
  78.     term.setCursorPos(1,1)
  79.     printC("Are you sure to install CharlieOS? (y/n)", colors.yellow)
  80.     printC("Installation cannont be teminated...", colors.yellow)
  81.     printC(">", colors.yellow)
  82.     term.setCursorPos(3,3)
  83.     term.setTextColor(colors.white)
  84.     say = read()
  85.     if say == "Y" or say == "y" then
  86.         term.clear()
  87.         term.setTextColor(colors.white)
  88.         term.setCursorPos(1,1)
  89.         shell.run("pastebin","run B2aetUKP")
  90.     elseif say == "N" or say == "n" then
  91.         printC("Installation Aborded.", colors.red)
  92.         sleep(1)
  93.         shell.run("setup")
  94.     else
  95.         printC("Invalid Choice...", colors.red)
  96.         sleep(1)
  97.     end
  98.     end
  99. end
  100.  
  101. --Uninstall
  102. local function uninstall()
  103.         while true do
  104.         term.clear()
  105.         term.setCursorPos(1,1)
  106.         printC("Are you sure to Uninstall CharlieOS? (y/n)", colors.yellow)
  107.         printC("Uninstallation cannont be teminated...", colors.yellow)
  108.         printC(">", colors.yellow)
  109.         term.setCursorPos(3,3)
  110.         term.setTextColor(colors.white)
  111.         say = read()
  112.         if say == "Y" or say == "y" then
  113.             term.clear()
  114.             term.setTextColor(colors.white)
  115.             term.setCursorPos(1,1)
  116.             shell.run("pastebin","run eVLZwCy1")
  117.         elseif say == "N" or say == "n" then
  118.             printC("Uninstallation Aborded.", colors.red)
  119.             sleep(1)
  120.             shell.run("setup")
  121.         else
  122.             printC("Invalid Choice...", colors.red)
  123.             sleep(1)
  124.         end
  125.     end
  126. end
  127.  
  128. --Display
  129. drawMenu()
  130. drawFrontend()
  131.  
  132. while true do
  133.     local e,p = os.pullEvent()
  134.     if e == "key" then
  135.         local key = p
  136.         if key == 17 or key == 200 then
  137.             if nOption > 1 then
  138.                 nOption = nOption - 1
  139.                 drawMenu()
  140.                 drawFrontend()
  141.             end
  142.             elseif key == 31 or key == 208 then
  143.                 if nOption < 3 then
  144.                     nOption = nOption + 1
  145.                     drawMenu()
  146.                     drawFrontend()
  147.                 end
  148.            
  149.         elseif key == 28 then
  150.             break
  151.         end
  152.     end
  153. end
  154. term.clear()
  155.  
  156. --Conditions
  157. if nOption == 1 then
  158.     install()
  159. elseif nOption == 2 then
  160.     uninstall()
  161. elseif nOption == 3 then
  162.     about()
  163. end
Advertisement
Add Comment
Please, Sign In to add comment