Advertisement
Guest User

todo1

a guest
Mar 3rd, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.52 KB | None | 0 0
  1. --TODO LIST (c)GoldProgramming 2014
  2. --Csstform & M1cr0man
  3.  
  4. os.loadAPI(shell.resolve("GS/GSAPI"))
  5.  
  6. --Setup basic variables
  7. local titleEnd, theme, settings, x, y = 2, {[1] = "default", [2] = "blue.gst", [3] = "dark.gst"}, {};
  8. local xmax, ymax = term.getSize()
  9.  
  10. local themes = {[1]="default",[2]="blue.gst",[3]="dark.gst"}
  11.  
  12. theme = GSAPI.loadTheme()
  13. if theme == "" then
  14. theme = {[1]="Default",[2]=colors.brown,[3]=colors.lightGray,[4]=colors.yellow,[5]="",[6]=colors.black,[7]=colors.red}
  15. end
  16.  
  17. local todo = {}
  18.  
  19. xmax, ymax = term.getSize()
  20.  
  21. --All inclusive print function
  22. function printex(bgNumber, colourNumber, x, y, text)
  23. if term.isColour() then
  24. term.setBackgroundColor(theme[bgNumber])
  25. term.setTextColor(theme[colourNumber])
  26. end
  27. term.setCursorPos(x, y)
  28. print(text)
  29. end
  30.  
  31. --Draws background fillings
  32. function drawBG()
  33. if not term.isColour() then return end
  34. term.setBackgroundColor(theme[4])
  35. term.clear()
  36. term.setBackgroundColor(theme[2])
  37. for y = 1, titleEnd do
  38. term.setCursorPos(1, y)
  39. term.clearLine()
  40. end
  41. term.setBackgroundColor(theme[3])
  42. for y = ymax - titleEnd + 1, ymax do
  43. term.setCursorPos(1, y)
  44. term.clearLine()
  45. end
  46. end
  47.  
  48. --Load last saved list on user request
  49. function loadLast()
  50. if fs.exists("tdl.list") then
  51. drawBG()
  52. printex(2, 7, 1, 1, "Would you like to load your previously saved todo list? (y/n)")
  53. input = select(2, os.pullEvent("char")):lower()
  54. if input == "y" then
  55. local file = fs.open("tdl.list", "r")
  56. local data = file.readAll()
  57. file.close()
  58. todo = textutils.unserialize(data)
  59. end
  60. end
  61. end
  62.  
  63. --Main function. All running happens here
  64. function main()
  65. drawBG()
  66. printex(2, 7, 1, 1, "TODO LIST: ")
  67.  
  68. --List the list
  69. for i,v in ipairs(todo) do
  70. printex(4, 6, 1, 2 + i, v)
  71. if 2 + i == ymax then break end
  72. end
  73.  
  74. printex(3, 6, 1, ymax, "1-9 add/delete | E exit | S settings")
  75.  
  76. --Setup actions
  77. local menu = false
  78. local actions = {
  79. ["s"] = function()
  80. if menu then return end
  81. printex(2, 6, 1, 1, "[1] Save List\n[2] Change Theme\n[3] Exit")
  82. menu = true
  83. end,
  84.  
  85. ["1menu"] = function()
  86. local file = fs.open("tdl.list", "w")
  87. file.write(textutils.serialize(todo))
  88. file.close()
  89. end,
  90.  
  91. ["2menu"] = function()
  92. term.clear()
  93. for i, v in ipairs(themes) do
  94. printex(2, 6, 1, i, "["..i.."]"..v)
  95. end
  96.  
  97. local key;
  98. repeat key = tonumber(select(2, os.pullEvent("char"))) until key
  99.  
  100. settings = {[1] = "", [2] = themes[key] or "default"}
  101.  
  102. local file = fs.open("GS/universal.settings", "w")
  103. file.write(textutils.serialize(settings))
  104. file.close()
  105. end,
  106.  
  107. ["edit"] = function(index)
  108. if not todo[index] then
  109. term.clear()
  110. term.setCursorPos(1,1)
  111. print("What do you need to do?")
  112. input = read()
  113. tostring(input)
  114. todo[index] = "["..index.."]" .. input
  115.  
  116. local file = fs.open("tdl.list", "w")
  117. file.write(textutils.serialize(todo))
  118. file.close()
  119. else todo[index] = nil end
  120. end
  121. }
  122.  
  123. --Get input, run according action
  124. repeat
  125. drawBG()
  126. key = select(2, os.pullEvent("char")):lower()
  127.  
  128. if menu and actions[key.."menu"] then
  129. actions[key]()
  130. menu = false
  131.  
  132. elseif tonumber(key) and tonumber(key) > 0 then actions["edit"](tonumber(key))
  133.  
  134. elseif actions[key] then actions[key]() end
  135.  
  136. until (not menu and key == "e") or (menu and key == "3")
  137. end
  138.  
  139. --Run the program
  140. loadLast()
  141. main()
  142.  
  143. if (term.isColor()) then
  144. term.setBackgroundColor(colors.black)
  145. term.setTextColor(colors.white)
  146. end
  147.  
  148. term.clear()
  149. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement