Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function version()
- print("You are running...")
- print("OS version 0.7")
- print("Music version " ..musicAPI.version())
- print("Calculator version " ..calculatorAPI.version())
- end
- local function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- local function GUI(arg1)
- --define variables
- x, y = term.getSize()
- spacingy = math.ceil(y/(math.ceil(#arg1/3)))
- if #arg1 < 3 then
- spacingx = math.ceil(x/#arg1)
- else
- spacingx = math.ceil(x/3)
- end
- --grid
- for i=1, math.ceil(#arg1/3), 1 do
- paintutils.drawLine(1, spacingy * i, x, spacingy * i, colors.white)
- end
- for i=1, math.ceil(x/spacingx), 1 do
- paintutils.drawLine(spacingx * i, 1, spacingx * i, y, colors.white)
- end
- paintutils.drawLine(1, 1, x, 1, colors.white)
- paintutils.drawLine(1, 1, 1, y, colors.white)
- paintutils.drawLine(1, y, x, y, colors.white)
- term.setBackgroundColor(colors.black)
- --text
- counter = 1
- i = 1
- while i < #arg1 do
- for k=1, math.ceil(x/spacingx), 1 do
- if i > #arg1 then
- break
- end
- length = string.len(arg1[i])
- if length > spacingx then
- search = string.find(arg1[i], " ", length/2, spacingx)
- if search == nil then
- search = string.find(arg1[i], " ")
- end
- length1 = string.len(string.sub(arg1[i], 1, search))
- term.setCursorPos((spacingx/2 + spacingx * (k - 1)) - math.ceil(length1/2), (spacingy / 2) + (spacingy * (counter - 1)))
- term.write(string.sub(arg1[i], 1, search))
- length2 = string.len(string.sub(arg1[i], search))
- term.setCursorPos((spacingx/2 + spacingx * (k - 1)) - math.ceil(length2/2), (spacingy / 2) + (spacingy * (counter - 1) + 1))
- term.write(string.sub(arg1[i], search))
- else
- term.setCursorPos((spacingx/2 + spacingx * (k - 1)) + 1 - math.ceil(length/2), (spacingy / 2) + (spacingy * (counter - 1)))
- term.write(arg1[i])
- end
- i = i + 1
- end
- counter = counter + 1
- end
- --mapping
- event, button, x, y = os.pullEvent("mouse_click")
- counter = 1
- l = 1
- while l < #arg1 do
- for k=1, math.ceil(x/spacingx), 1 do
- if l > #arg1 then
- return false
- end
- if (((1 + (spacingx * (k - 1))) <= x) and ( x <= (spacingx * k))) and (((1 + (spacingy * (counter - 1))) <= y) and (y <= (1 + spacingy * counter))) then
- return arg1[l]
- end
- l = l + 1
- end
- counter = counter + 1
- end
- end
- local function menu(arg1)
- tMenu = arg1
- counter = 1
- textutils.tabulate(tMenu)
- term.write(tMenu[1])
- while true do
- event, keycode = os.pullEvent("key")
- if keycode == 200 then
- if counter == 1 then
- counter = #tMenu
- term.clearLine()
- local x, y = term.getCursorPos()
- term.setCursorPos(1, y)
- term.write(tMenu[counter])
- else
- counter = counter - 1
- term.clearLine()
- local x, y = term.getCursorPos()
- term.setCursorPos(1, y)
- term.write(tMenu[counter])
- end
- elseif keycode == 208 then
- if counter == #tMenu then
- counter = 1
- term.clearLine()
- local x, y = term.getCursorPos()
- term.setCursorPos(1, y)
- term.write(tMenu[counter])
- else
- counter = counter + 1
- term.clearLine()
- local x, y = term.getCursorPos()
- term.setCursorPos(1, y)
- term.write(tMenu[counter])
- end
- elseif keycode == 28 then
- break
- end
- end
- return tMenu[counter]
- end
- --os.loadAPI("OS/helpAPI")
- os.loadAPI("OS/scrollAPI")
- sProcess = nil
- drive = peripheral.wrap("right")
- history = fs.open("OS/history_OS", "a")
- --os.pullEvent = os.pullEventRaw
- clear()
- while true do
- if term.isColor() then
- sProcess = GUI(scrollAPI.mainmenu())
- history.writeLine(sProcess)
- else
- sProcess = menu(scrollAPI.mainmenu())
- history.writeLine(sProcess)
- end
- if sProcess == "music" then
- clear()
- os.loadAPI("OS/musicAPI")
- musicAPI.music()
- os.unloadAPI("OS/musicAPI")
- sProcess = nil
- clear()
- elseif sProcess == "calculator" then
- clear()
- os.loadAPI("OS/calculatorAPI")
- calculatorAPI.calculator()
- os.unloadAPI("OS/calculatorAPI")
- sProcess = nil
- clear()
- elseif sProcess == "command_prompt" or (sProcess == "command prompt") or (sProcess == "cmd_prmt") or (sProcess == "cmd prmt") then
- clear()
- print("Please enter username and password for authenication.")
- sUsername = read()
- history.writeLine(sUsername)
- sPassword = read("*")
- history.writeLine(sPassword)
- if ((sUsername == "Too_Quataz") and (sPassword == "fripSide")) or ((sUsername == "L2") and (sPassword == "bees")) then
- clear()
- print("Are you sure you want to exit the OS?")
- sExitDecision = read()
- if sExitDecision == "yes" then
- break
- else
- sProcess = nil
- end
- else
- clear()
- print("Authentication failed.")
- sProcess = nil
- end
- elseif sProcess == "history" then
- clear()
- print("Please enter username and password for authentication.")
- sUsername = read()
- sPassword = read("*")
- if ((sUsername == "Too_Quataz") and (sPassword == "fripSide")) or ((sUsername == "L2") and (sPassword == "bees")) then
- clear()
- history.close()
- history = fs.open("OS/history_OS", "r")
- print(history.readAll())
- history.close()
- history = fs.open("OS/history_OS", "a")
- sProcess = nil
- else
- clear()
- history.writeLine(sUsername)
- history.writeLine(sPassword)
- print("Authentication failed.")
- sProcess = nil
- end
- elseif sProcess == "peripheral_help" then
- clear()
- helpAPI.peripheral_help()
- sProcess = nil
- elseif sProcess == "clear" then
- clear()
- sProcess = nil
- elseif sProcess == "clear_history" then
- clear()
- history.close()
- fs.delete("OS/history_OS")
- history = fs.open("OS/history_OS", "a")
- sProcess = nil
- elseif sProcess == "about" then
- clear()
- os.loadAPI("OS/musicAPI")
- os.loadAPI("OS/calculatorAPI")
- version()
- os.unloadAPI("OS/musicAPI")
- os.unloadAPI("OS/calculatorAPI")
- sProcess = nil
- elseif sProcess == "reboot" then
- clear()
- print("Are you sure you want to restart the OS?")
- sRebootDecision = read()
- if sRebootDecision == "yes" then
- print("Rebooting...")
- sleep(1.5)
- history.close()
- os.reboot()
- else
- sProcess = nil
- end
- elseif sProcess == "shutdown" then
- clear()
- print("Are you sure you want to shut down the OS?")
- sShutdownDecision = read()
- if sShutdownDecision == "yes" then
- print("Shutting down...")
- sleep(1.5)
- history.close()
- os.shutdown()
- else
- sProcess = nil
- end
- elseif sProcess == "help" then
- clear()
- print("List of available commands:")
- helpAPI.generalhelp()
- print(" ")
- sProcess = nil
- end
- end
- clear()
- history.close()
Advertisement
Add Comment
Please, Sign In to add comment