mastrkillerr

MastrOS

Feb 18th, 2013
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. local w,h = term.getSize()
  2. local select = 1
  3.  
  4. --Some draw functions to get us started
  5.  
  6. local function printCentered(str, ypos)
  7. term.setCursorPos(w/2 - #str/2, ypos)
  8. term.write(str)
  9. end
  10.  
  11. local function printRight(str, ypos)
  12. term.setCursorPos(w - #str, ypos)
  13. term.write(str)
  14. end
  15.  
  16. --Add the menus here
  17.  
  18. function drawMain()
  19. printCentered("Downloads", 8)
  20. printCentered("Files", 12)
  21. printCentered("Quit", h-2)
  22.  
  23. local ypos = 9
  24. if select == 2 then ypos = 13
  25. elseif select == 3 then ypos = h-1 end
  26. printCentered("---------", ypos)
  27. end
  28.  
  29. function dmenu()
  30. term.clear()
  31. term.setCursorPos(1,1)
  32. cPrint("---------------------")
  33. cPrint("DelOS v" ..version)
  34. cPrint("---------------------")
  35. print("Type 'Downloads' to view downloads.")
  36. print("Type 'Download' to download files.")
  37. command = read()
  38. if command == "Downloads" then
  39. path = "downloads"
  40. filemanager()
  41. elseif command == "Download" then
  42. term.clear()
  43. term.setCursorPos(1,1)
  44. cPrint("---------------------")
  45. cPrint("DelOS v" ..version)
  46. cPrint("---------------------")
  47. write("Please enter the file ID: ")
  48. code = read()
  49. write("Please enter the name: ")
  50. name = read()
  51. if fs.exists("downloads/" ..name) then
  52. write(name.. " already exists! Would you like to overwrite this file? ")
  53. option = read()
  54. if option == "Yes" then
  55. fs.delete("downloads/" ..name)
  56. shell.run("pastebin","get", code, "downloads/" ..name)
  57. sleep(2)
  58. dmenu()
  59. elseif option == "No" then
  60. print("Cancled...")
  61. sleep(2)
  62. dmenu()
  63. else
  64. print("Option does not exist! Say Yes or No.")
  65. sleep(2)
  66. dmenu()
  67. end
  68. else
  69. shell.run("pastebin","get", code, "downloads/" ..name)
  70. sleep(3)
  71. dmenu()
  72. end
  73. else
  74. print("Command does not exist!")
  75. sleep(2)
  76. dmenu()
  77. end
  78. end
  79.  
  80. function drawPicTwo()
  81. local bishopList = {
  82. " _<> ",
  83. " /\\\\ \\",
  84. " \\ \\) /",
  85. " \\__/ ",
  86. " (____) ",
  87. " | | ",
  88. " | | ",
  89. " | | ",
  90. " |__| ",
  91. " /____\\ ",
  92. "(______)"
  93. }
  94.  
  95. for i=1,#bishopList do
  96. printCentered(bishopList[i], 2 + i)
  97. end
  98.  
  99. printCentered("Picture 1", h-4)
  100. printCentered("Back", h-1)
  101. local ypos = h-3;
  102. if select == 2 then ypos = h end
  103. printCentered("---------", ypos)
  104. end
  105.  
  106. function drawHeader()
  107. printCentered("PICTURE VIEWER", 1)
  108. printCentered(string.rep("-", w), 2)
  109. printRight("by nitrofingers", h)
  110. end
  111.  
  112. --Menu state
  113.  
  114. local menustate = "main"
  115.  
  116. local mopt = {
  117. ["main"] = {
  118. options = {"Downloads", "Files", "Quit"},
  119. draw = drawMain
  120. },
  121. ["Downloads"] = {
  122. options = {"main"},
  123. draw = drawPicOne
  124. },
  125. ["Files"] = {
  126. options = {"main"},
  127. draw = drawPicTwo
  128. }
  129. }
  130.  
  131. --Run Function
  132.  
  133. function runMenu()
  134. while true do
  135. term.clear()
  136. drawHeader()
  137. mopt[menustate].draw()
  138.  
  139. local id, key = os.pullEvent("key")
  140. --UP = 200, DOWN = 208, ENTER = 28
  141.  
  142. if key == 200 and select > 1 then select = select-1
  143. elseif key == 208 and select < #mopt[menustate].options then select = select+1
  144. elseif key == 28 then
  145. if mopt[menustate].options[select] == "quit" then break end
  146. menustate = mopt[menustate].options[select]
  147. end
  148. end
  149. end
  150.  
  151. runMenu()
  152. term.clear()
  153. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment