Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- local select = 1
- --Some draw functions to get us started
- local function printCentered(str, ypos)
- term.setCursorPos(w/2 - #str/2, ypos)
- term.write(str)
- end
- local function printRight(str, ypos)
- term.setCursorPos(w - #str, ypos)
- term.write(str)
- end
- --Add the menus here
- function drawMain()
- printCentered("Downloads", 8)
- printCentered("Files", 12)
- printCentered("Quit", h-2)
- local ypos = 9
- if select == 2 then ypos = 13
- elseif select == 3 then ypos = h-1 end
- printCentered("---------", ypos)
- end
- function dmenu()
- term.clear()
- term.setCursorPos(1,1)
- cPrint("---------------------")
- cPrint("DelOS v" ..version)
- cPrint("---------------------")
- print("Type 'Downloads' to view downloads.")
- print("Type 'Download' to download files.")
- command = read()
- if command == "Downloads" then
- path = "downloads"
- filemanager()
- elseif command == "Download" then
- term.clear()
- term.setCursorPos(1,1)
- cPrint("---------------------")
- cPrint("DelOS v" ..version)
- cPrint("---------------------")
- write("Please enter the file ID: ")
- code = read()
- write("Please enter the name: ")
- name = read()
- if fs.exists("downloads/" ..name) then
- write(name.. " already exists! Would you like to overwrite this file? ")
- option = read()
- if option == "Yes" then
- fs.delete("downloads/" ..name)
- shell.run("pastebin","get", code, "downloads/" ..name)
- sleep(2)
- dmenu()
- elseif option == "No" then
- print("Cancled...")
- sleep(2)
- dmenu()
- else
- print("Option does not exist! Say Yes or No.")
- sleep(2)
- dmenu()
- end
- else
- shell.run("pastebin","get", code, "downloads/" ..name)
- sleep(3)
- dmenu()
- end
- else
- print("Command does not exist!")
- sleep(2)
- dmenu()
- end
- end
- function drawPicTwo()
- local bishopList = {
- " _<> ",
- " /\\\\ \\",
- " \\ \\) /",
- " \\__/ ",
- " (____) ",
- " | | ",
- " | | ",
- " | | ",
- " |__| ",
- " /____\\ ",
- "(______)"
- }
- for i=1,#bishopList do
- printCentered(bishopList[i], 2 + i)
- end
- printCentered("Picture 1", h-4)
- printCentered("Back", h-1)
- local ypos = h-3;
- if select == 2 then ypos = h end
- printCentered("---------", ypos)
- end
- function drawHeader()
- printCentered("PICTURE VIEWER", 1)
- printCentered(string.rep("-", w), 2)
- printRight("by nitrofingers", h)
- end
- --Menu state
- local menustate = "main"
- local mopt = {
- ["main"] = {
- options = {"Downloads", "Files", "Quit"},
- draw = drawMain
- },
- ["Downloads"] = {
- options = {"main"},
- draw = drawPicOne
- },
- ["Files"] = {
- options = {"main"},
- draw = drawPicTwo
- }
- }
- --Run Function
- function runMenu()
- while true do
- term.clear()
- drawHeader()
- mopt[menustate].draw()
- local id, key = os.pullEvent("key")
- --UP = 200, DOWN = 208, ENTER = 28
- if key == 200 and select > 1 then select = select-1
- elseif key == 208 and select < #mopt[menustate].options then select = select+1
- elseif key == 28 then
- if mopt[menustate].options[select] == "quit" then break end
- menustate = mopt[menustate].options[select]
- end
- end
- end
- runMenu()
- term.clear()
- term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment