Advertisement
DoomRater

udo 0.2

Jan 27th, 2020
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. --udo By Zambonie
  2. --Just a Quick Attempt at a todo list.
  3. --Though Planning to be bigger ;p
  4. --Added sanity checks to all pullevents by DoomRater
  5.  
  6. --v. 0.2
  7.  
  8. local size = {term.getSize()}
  9. local cur = 1
  10. local colorp = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768}
  11. local bg = nil
  12. local txt = nil
  13. local maxF = false
  14.  
  15. function checkAndCreate() --Checks For a Todo Folder. If None, It will create one.
  16. if fs.exists("TodoFiles") then
  17. return
  18. else fs.makeDir("TodoFiles")
  19. return
  20. end
  21. end
  22.  
  23. function loadTodos(file)
  24. local file = fs.open("TodoFiles/"..file,"r")
  25. local file = textutils.unserialize(file.readAll())
  26. return file
  27. end
  28.  
  29. function drawTodo()
  30. term.setCursorPos(1,1)
  31. write(" ")
  32. term.setTextColor(colors.white)
  33. term.setCursorPos(1,1)
  34. write(t[cur])
  35. local l = 0
  36. maxF = false
  37. for i = 2, size[2]-1 do
  38. if l == 0 then l = 1
  39. paintutils.drawLine(1, i, size[1], i, f[1])
  40. if f[i+3] ~= nil then
  41. term.setCursorPos(1,i)
  42. term.setTextColor(f[3])
  43. write((i-1)..". "..f[i+3])
  44. bg = f[2]
  45. txt = f[4]
  46. end
  47.  
  48. elseif l == 1 then l = 0
  49. paintutils.drawLine(1, i, size[1], i, f[2])
  50. if f[i+3] ~= nil then
  51. term.setCursorPos(1,i)
  52. term.setTextColor(f[4])
  53. write((i-1)..". "..f[i+3])
  54. bg = f[1]
  55. txt = f[3]
  56. end
  57. end
  58. end
  59.  
  60. term.setCursorPos(size[1]-2, 1)
  61. term.setTextColor(colors.lightGray)
  62. term.setBackgroundColor(colors.gray)
  63. write("-")
  64.  
  65. term.setCursorPos(size[1]-4, 1)
  66. write("<")
  67.  
  68. if #f-4 >= size[2]-2 then
  69. maxF = true
  70. term.setCursorPos(size[1],1)
  71. term.setTextColor(colors.black)
  72. write("+")
  73. end
  74. end
  75.  
  76. function makeTodo()
  77. term.setBackgroundColor(colors.gray)
  78. term.clear()
  79. term.setTextColor(colors.lightGray)
  80. term.setCursorPos(1,1)
  81. write("Name : ")
  82. local name = read()
  83.  
  84. term.setCursorPos(1,4)
  85. write("Line Color 1")
  86. for x = 1, 16 do
  87. paintutils.drawPixel(x, 5, colorp[x])
  88. end
  89.  
  90. term.setCursorPos(1,6)
  91. term.setBackgroundColor(colors.gray)
  92. write("Line Color 2")
  93. for x = 1, 16 do
  94. paintutils.drawPixel(x, 7, colorp[x])
  95. end
  96.  
  97. term.setCursorPos(1,8)
  98. term.setBackgroundColor(colors.gray)
  99. write("Text Color 1")
  100. for x = 1, 16 do
  101. paintutils.drawPixel(x, 9, colorp[x])
  102. end
  103.  
  104. term.setCursorPos(1,10)
  105. term.setBackgroundColor(colors.gray)
  106. write("Text Color 2")
  107. for x = 1, 16 do
  108. paintutils.drawPixel(x, 11, colorp[x])
  109. end
  110.  
  111. term.setCursorPos(1, 13)
  112. term.setTextColor(colors.white)
  113. term.setBackgroundColor(colors.gray)
  114. write("Done")
  115.  
  116. local l1 = 1
  117. local l2 = 1
  118. local t1 = 1
  119. local t2 = 1
  120.  
  121. while true do
  122. paintutils.drawLine(18, 5, size[1], 5, l1)
  123. paintutils.drawLine(18, 7, size[1], 7, l2)
  124. paintutils.drawLine(18, 9, size[1], 9, t1)
  125. paintutils.drawLine(18, 11, size[1], 11, t2)
  126.  
  127. local e, b, x, y = os.pullEvent("mouse_click")
  128. if y == 5 and x <= 16 then
  129. l1 = colorp[x]
  130.  
  131. elseif y == 7 and x <= 16 then
  132. l2 = colorp[x]
  133.  
  134. elseif y == 9 and x <= 16 then
  135. t1 = colorp[x]
  136.  
  137. elseif y == 11 and x <= 16 then
  138. t2 = colorp[x]
  139.  
  140. elseif x >= 1 and x <= 4 and y == 13 then
  141. local nt = fs.open("TodoFiles/"..name, "w")
  142. nt.write("{"..l1..","..l2..","..t1..","..t2.."}")
  143. nt.close()
  144. break
  145. end
  146. end
  147. end
  148.  
  149. function makeDo()
  150. if #f < 5 then
  151. term.setBackgroundColor(f[1])
  152. term.setTextColor(f[3])
  153. else
  154. term.setBackgroundColor(bg)
  155. term.setTextColor(txt)
  156. end
  157. term.setCursorPos(1, #f-4+2)
  158. write((#f-4+1)..". ")
  159. local newinput = read()
  160. table.insert(f, newinput)
  161. local fw = fs.open("TodoFiles/"..t[cur],"w")
  162. fw.write(textutils.serialize(f))
  163. fw.close()
  164. end
  165.  
  166. while true do
  167. checkAndCreate()
  168.  
  169. term.setBackgroundColor(colors.gray) --Setting Up Background
  170. term.clear()
  171. term.setCursorPos(size[1], 1)
  172. term.setTextColor(colors.lightGray)
  173. write("+")
  174. term.setCursorPos(size[1]-2, 1)
  175. write(">")
  176. term.setCursorPos(1,1)
  177. write("<"..cur.."/"..#fs.list("TodoFiles")..">")
  178.  
  179. term.setCursorPos(size[1]-3, size[2])
  180. write("udo")
  181.  
  182.  
  183. if #fs.list("TodoFiles") == 0 then
  184. term.setTextColor(colors.white)
  185. term.setCursorPos(size[1]/2-#"No Todos Found!"/2+1, size[2]/2-1)
  186. write("No Todos Found!")
  187. term.setCursorPos(1, size[2]/2)
  188. write("Click Anywhere To Make one")
  189. os.pullEvent("mouse_click")
  190. makeTodo()
  191.  
  192.  
  193. elseif #fs.list("TodoFiles") ~= 0 then
  194. t = fs.list("TodoFiles")
  195. f = loadTodos(t[cur])
  196.  
  197. local l = 0
  198. for i = size[2]/2-5, size[2]/2+3 do
  199. if l == 0 then l = 1
  200. paintutils.drawLine(size[1]/2-5, i, size[1]/2+2, i, f[1])
  201.  
  202. elseif l == 1 then l = 0
  203. paintutils.drawLine(size[1]/2-5, i, size[1]/2+2, i, f[2])
  204. end
  205. end
  206.  
  207. paintutils.drawLine(size[1]/2-4, size[2]/2+4, size[1]/2+3, size[2]/2+4, colors.black)
  208. paintutils.drawLine(size[1]/2+3, size[2]/2-4, size[1]/2+3, size[2]/2+3, colors.black)
  209.  
  210. term.setBackgroundColor(colors.gray)
  211. term.setTextColor(colors.white)
  212. term.setCursorPos(size[1]/2-#t[cur]/2, size[2]/2+6)
  213. write(t[cur])
  214.  
  215. local e, b, x, y = os.pullEvent("mouse_click")
  216.  
  217. if x == size[1]-2 and y == 1 then
  218. while true do
  219. drawTodo()
  220. local e2, b2, x2, y2 = os.pullEvent("mouse_click")
  221. if x2 == size[1]-4 and y2 == 1 then
  222. break
  223.  
  224. elseif x2 == size[1] and y2 == 1 and not maxF then
  225. term.setCursorPos(size[1], 1)
  226. term.setTextColor(colors.lime)
  227. write("+")
  228. makeDo()
  229. term.setCursorPos(size[1], 1)
  230. term.setTextColor(colors.lightGray)
  231. term.setBackgroundColor(colors.gray)
  232. write("+")
  233.  
  234. elseif x2 == size[1]-2 and y2 == 1 then
  235. term.setCursorPos(size[1]-2, 1)
  236. term.setTextColor(colors.red)
  237. write("-")
  238.  
  239. local e3, b3, x3, y3 = os.pullEvent("mouse_click")
  240. if y3 ~= 1 and y3 ~= size[2] then
  241. if f[y3+4-1] ~= nil then
  242. table.remove(f, y3+4-1)
  243. local fw = fs.open("TodoFiles/"..t[cur],"w")
  244. fw.write(textutils.serialize(f))
  245. fw.close()
  246. term.setCursorPos(size[1],1)
  247. term.setTextColor(colors.lightGray)
  248. write("+")
  249. end
  250. end
  251. end
  252. end
  253.  
  254. elseif x == 1 and y == 1 and cur ~= 1 then
  255. cur = cur - 1
  256.  
  257. elseif x == 5 and y == 1 and cur ~= #fs.list("TodoFiles") then
  258. cur = cur + 1
  259.  
  260. elseif x == size[1] and y == 1 then
  261. makeTodo()
  262.  
  263. elseif y == size[2] and b == 2 then
  264. term.setBackgroundColor(colors.black)
  265. term.clear()
  266. term.setCursorPos(1,1)
  267. print("Thanks for using udo!")
  268. break
  269. end
  270. end
  271. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement