Guest User

startup

a guest
Aug 19th, 2013
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.97 KB | None | 0 0
  1. local function version()
  2.   print("You are running...")
  3.   print("OS version 0.7")
  4.   print("Music version " ..musicAPI.version())
  5.   print("Calculator version " ..calculatorAPI.version())
  6. end
  7.  
  8. local function clear()
  9.   term.clear()
  10.   term.setCursorPos(1,1)
  11. end
  12.  
  13. local function GUI(arg1)
  14.   --define variables
  15.   x, y = term.getSize()
  16.   spacingy = math.ceil(y/(math.ceil(#arg1/3)))
  17.   if #arg1 < 3 then
  18.     spacingx = math.ceil(x/#arg1)
  19.   else
  20.     spacingx = math.ceil(x/3)
  21.   end
  22.   --grid
  23.   for i=1, math.ceil(#arg1/3), 1 do
  24.     paintutils.drawLine(1, spacingy * i, x, spacingy * i, colors.white)
  25.   end
  26.   for i=1, math.ceil(x/spacingx), 1 do
  27.     paintutils.drawLine(spacingx * i, 1, spacingx * i, y, colors.white)
  28.   end
  29.   paintutils.drawLine(1, 1, x, 1, colors.white)
  30.   paintutils.drawLine(1, 1, 1, y, colors.white)
  31.   paintutils.drawLine(1, y, x, y, colors.white)
  32.   term.setBackgroundColor(colors.black)
  33.   --text
  34.   counter = 1
  35.   i = 1
  36.   while i < #arg1 do
  37.     for k=1, math.ceil(x/spacingx), 1 do
  38.       if i > #arg1 then
  39.         break
  40.       end
  41.       length = string.len(arg1[i])
  42.       if length > spacingx then
  43.         search = string.find(arg1[i], " ", length/2, spacingx)
  44.         if search == nil then
  45.           search = string.find(arg1[i], " ")
  46.         end
  47.         length1 = string.len(string.sub(arg1[i], 1, search))
  48.         term.setCursorPos((spacingx/2 + spacingx * (k - 1)) - math.ceil(length1/2), (spacingy / 2) + (spacingy * (counter - 1)))
  49.         term.write(string.sub(arg1[i], 1, search))
  50.         length2 = string.len(string.sub(arg1[i], search))
  51.         term.setCursorPos((spacingx/2 + spacingx * (k - 1)) - math.ceil(length2/2), (spacingy / 2) + (spacingy * (counter - 1) + 1))
  52.         term.write(string.sub(arg1[i], search))
  53.       else
  54.         term.setCursorPos((spacingx/2 + spacingx * (k - 1)) + 1 - math.ceil(length/2), (spacingy / 2) + (spacingy * (counter - 1)))
  55.         term.write(arg1[i])
  56.       end
  57.       i = i + 1
  58.     end
  59.     counter = counter + 1
  60.   end
  61.   --mapping
  62.   event, button, x, y = os.pullEvent("mouse_click")
  63.   counter = 1
  64.   l = 1
  65.   while l < #arg1 do
  66.     for k=1, math.ceil(x/spacingx), 1 do
  67.       if l > #arg1 then
  68.         return false
  69.       end
  70.       if (((1 + (spacingx * (k - 1))) <= x) and ( x <= (spacingx * k))) and (((1 + (spacingy * (counter - 1))) <= y) and (y <= (1 + spacingy * counter))) then
  71.         return arg1[l]
  72.       end
  73.       l = l + 1
  74.     end
  75.     counter = counter + 1
  76.   end
  77. end
  78.  
  79. local function menu(arg1)
  80.   tMenu = arg1
  81.   counter = 1
  82.   textutils.tabulate(tMenu)
  83.   term.write(tMenu[1])
  84.   while true do
  85.     event, keycode = os.pullEvent("key")
  86.     if keycode == 200 then
  87.       if counter == 1 then
  88.         counter = #tMenu
  89.         term.clearLine()
  90.         local x, y = term.getCursorPos()
  91.         term.setCursorPos(1, y)
  92.         term.write(tMenu[counter])
  93.       else
  94.         counter = counter - 1
  95.         term.clearLine()
  96.         local x, y = term.getCursorPos()
  97.         term.setCursorPos(1, y)
  98.         term.write(tMenu[counter])
  99.       end
  100.     elseif keycode == 208 then
  101.       if counter == #tMenu then
  102.         counter = 1
  103.         term.clearLine()
  104.         local x, y = term.getCursorPos()
  105.         term.setCursorPos(1, y)
  106.         term.write(tMenu[counter])
  107.       else
  108.         counter = counter + 1
  109.         term.clearLine()
  110.         local x, y = term.getCursorPos()
  111.         term.setCursorPos(1, y)
  112.         term.write(tMenu[counter])
  113.       end
  114.     elseif keycode == 28 then
  115.       break
  116.     end
  117.   end
  118. return tMenu[counter]
  119. end
  120.  
  121. --os.loadAPI("OS/helpAPI")
  122. os.loadAPI("OS/scrollAPI")
  123. sProcess = nil
  124. drive = peripheral.wrap("right")
  125. history = fs.open("OS/history_OS", "a")
  126. --os.pullEvent = os.pullEventRaw
  127. clear()
  128. while true do
  129.   if term.isColor() then
  130.     sProcess = GUI(scrollAPI.mainmenu())
  131.     history.writeLine(sProcess)
  132.   else
  133.     sProcess = menu(scrollAPI.mainmenu())
  134.     history.writeLine(sProcess)
  135.   end
  136.   if sProcess == "music" then
  137.     clear()
  138.     os.loadAPI("OS/musicAPI")
  139.     musicAPI.music()
  140.     os.unloadAPI("OS/musicAPI")
  141.     sProcess = nil
  142.     clear()
  143.   elseif sProcess == "calculator" then
  144.     clear()
  145.     os.loadAPI("OS/calculatorAPI")
  146.     calculatorAPI.calculator()
  147.     os.unloadAPI("OS/calculatorAPI")
  148.     sProcess = nil
  149.     clear()
  150.   elseif sProcess == "command_prompt" or (sProcess == "command prompt") or (sProcess == "cmd_prmt") or (sProcess == "cmd prmt") then
  151.     clear()
  152.     print("Please enter username and password for authenication.")
  153.     sUsername = read()
  154.     history.writeLine(sUsername)
  155.     sPassword = read("*")
  156.     history.writeLine(sPassword)
  157.     if ((sUsername == "Too_Quataz") and (sPassword == "fripSide")) or ((sUsername == "L2") and (sPassword == "bees")) then
  158.       clear()
  159.       print("Are you sure you want to exit the OS?")
  160.       sExitDecision = read()
  161.       if sExitDecision == "yes" then
  162.         break
  163.       else
  164.         sProcess = nil
  165.       end
  166.     else
  167.       clear()
  168.       print("Authentication failed.")
  169.       sProcess = nil
  170.     end
  171.   elseif sProcess == "history" then
  172.     clear()
  173.     print("Please enter username and password for authentication.")
  174.     sUsername = read()
  175.     sPassword = read("*")
  176.     if ((sUsername == "Too_Quataz") and (sPassword == "fripSide")) or ((sUsername == "L2") and (sPassword == "bees")) then
  177.       clear()
  178.       history.close()
  179.       history = fs.open("OS/history_OS", "r")
  180.       print(history.readAll())
  181.       history.close()
  182.       history = fs.open("OS/history_OS", "a")
  183.       sProcess = nil
  184.     else
  185.       clear()
  186.       history.writeLine(sUsername)
  187.       history.writeLine(sPassword)
  188.       print("Authentication failed.")
  189.       sProcess = nil
  190.     end
  191.   elseif sProcess == "peripheral_help" then
  192.     clear()
  193.     helpAPI.peripheral_help()
  194.     sProcess = nil
  195.   elseif sProcess == "clear" then
  196.     clear()
  197.     sProcess = nil
  198.   elseif sProcess == "clear_history" then
  199.     clear()
  200.     history.close()
  201.     fs.delete("OS/history_OS")
  202.     history = fs.open("OS/history_OS", "a")
  203.     sProcess = nil
  204.   elseif sProcess == "about" then
  205.     clear()
  206.     os.loadAPI("OS/musicAPI")
  207.     os.loadAPI("OS/calculatorAPI")
  208.     version()
  209.     os.unloadAPI("OS/musicAPI")
  210.     os.unloadAPI("OS/calculatorAPI")
  211.     sProcess = nil
  212.   elseif sProcess == "reboot" then
  213.     clear()
  214.     print("Are you sure you want to restart the OS?")
  215.     sRebootDecision = read()
  216.     if sRebootDecision == "yes" then
  217.       print("Rebooting...")
  218.       sleep(1.5)
  219.       history.close()
  220.       os.reboot()
  221.     else
  222.       sProcess = nil
  223.     end
  224.   elseif sProcess == "shutdown" then
  225.     clear()
  226.     print("Are you sure you want to shut down the OS?")
  227.     sShutdownDecision = read()
  228.     if sShutdownDecision == "yes" then
  229.       print("Shutting down...")
  230.       sleep(1.5)
  231.       history.close()
  232.       os.shutdown()
  233.     else
  234.       sProcess = nil
  235.     end
  236.   elseif sProcess == "help" then
  237.     clear()
  238.     print("List of available commands:")
  239.     helpAPI.generalhelp()
  240.     print(" ")
  241.     sProcess = nil
  242.   end
  243. end
  244. clear()
  245. history.close()
Advertisement
Add Comment
Please, Sign In to add comment