Advertisement
BruceWplays

todo V8

Sep 14th, 2022 (edited)
680
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local isUsing = true
  2. local maxX, maxY = term.getSize()
  3. local color1 = colors.lime
  4. local color2 = colors.white
  5. if fs.exists("/.todocfg") then
  6.   local opfile = fs.open("/.todocfg", "r")
  7.   color1 = tonumber(opfile.readLine())
  8.   color2 = tonumber(opfile.readLine())
  9.   opfile.close()
  10. end
  11.  
  12. local colnames = {[0] = "White",
  13.                 [1] = "Orange",
  14.                 [2] = "Magenta",
  15.                 [3] = "Light Blue",
  16.                 [4] = "Yellow",
  17.                 [5] = "Lime",
  18.                 [6] = "Pink",
  19.                 [7] = "Gray",
  20.                 [8] = "Light Gray",
  21.                 [9] = "Cyan",
  22.                 [10] = "Purple",
  23.                 [11] = "Blue",
  24.                 [12] = "Brown",
  25.                 [13] = "Green",
  26.                 [14] = "Red",
  27.                 [15] = "Black"}
  28.                
  29. local numconv = {[0] = colors.white,
  30.                 [1] = colors.orange,
  31.                 [2] = colors.magenta,
  32.                 [3] = colors.lightBlue,
  33.                 [4] = colors.yellow,
  34.                 [5] = colors.lime,
  35.                 [6] = colors.pink,
  36.                 [7] = colors.gray,
  37.                 [8] = colors.lightGray,
  38.                 [9] = colors.cyan,
  39.                 [10] = colors.purple,
  40.                 [11] = colors.blue,
  41.                 [12] = colors.brown,
  42.                 [13] = colors.green,
  43.                 [14] = colors.red,
  44.                 [15] = colors.black}
  45.  
  46. --Maybe need to rewrite this :P
  47. local choice = 0
  48. local choice2 = 0
  49. while numconv[choice] ~= color1 do
  50.     choice=choice+1
  51. end
  52. while numconv[choice2] ~= color2 do
  53.     choice2=choice2+1
  54. end
  55. local taskFile = "/.tasks"
  56. local page = 1
  57. local Options = false
  58.  
  59. local function getTasks()
  60.  if not fs.exists(taskFile) then
  61.   local A = fs.open(taskFile, "w")
  62.   A.write("{}")
  63.   A.close()
  64.   return {}
  65.  else
  66.   local A = fs.open(taskFile, "r")
  67.   local tmp = textutils.unserialize(A.readAll())
  68.   A.close()
  69.   return tmp
  70.  end
  71. end
  72.  
  73. local mineminute = 60 / 72
  74.  
  75. function time_refresh()
  76.       --time start
  77.     redrawTimer = os.startTimer(mineminute)
  78.       time_nospace_zero = string.gsub(textutils.formatTime(os.time(), false), " ", " ")  
  79.        time_nospace_10error = string.gsub(time_nospace_zero, "0:", "12:")
  80.          time_nospace = string.gsub(time_nospace_10error, "112:", "10:")
  81.      timeposfloat = (maxX / 2) - (#time_nospace / 2)  
  82.        timepos = math.floor(timeposfloat+2.6) - 1
  83.                         term.setCursorPos(timepos,1)
  84. print(time_nospace)
  85.     end
  86.  
  87. local function redraw(page)
  88.    
  89.  if isUsing and not Options then
  90.     local tasks = getTasks()
  91.     local nMaxY = maxY - 2
  92.  
  93.     term.clear()
  94.     term.setCursorPos(1,1)
  95.     term.setBackgroundColour(color1)
  96.     if color1 ~= color2 and color1 ~= colors.white then
  97.         term.setTextColour(color2)
  98.     elseif color1 == color2 and color1 ~= colors.white then
  99.         term.setTextColor(colors.white)
  100.     else
  101.         term.setTextColor(colors.black)
  102.     end
  103.     term.clearLine()
  104.     print(" + / -  ")
  105.     term.setCursorPos(maxX-12,1)
  106.     print("     Opt Exit")
  107. time_refresh()
  108. --time end        
  109.        
  110.     for i=1, nMaxY do
  111.         if i%2 == 1 and color1 ~= color2 then
  112.             term.setBackgroundColour(color2)
  113.             term.setTextColour(color1)
  114.         elseif color1 ~= color2 then
  115.             term.setBackgroundColour(color1)
  116.             term.setTextColour(color2)
  117.         elseif color1 == colors.white then
  118.             term.setBackgroundColor(color1)
  119.             term.setTextColor(colors.black)
  120.         else
  121.             term.setBackgroundColor(color1)
  122.             term.setTextColor(colors.black)
  123.         end
  124.  
  125.         term.setCursorPos(1,1+i)
  126.         term.clearLine()
  127.  
  128.         local num = i+(nMaxY*(page-1))
  129.  
  130.         if tasks[num] ~= nil then
  131.             write(num..": "..tasks[num])
  132.         else
  133.             write(num..": ")
  134.         end
  135.     end
  136.  
  137.  if maxY%2 == 0 and color1 ~= color2 then
  138.   term.setBackgroundColour(color2)
  139.   term.setTextColour(color1)
  140.  elseif color1 ~= color2 then
  141.   term.setBackgroundColour(color1)
  142.   term.setTextColour(color2)
  143.  elseif color1 == colors.white then
  144.     term.setBackgroundColor(color1)
  145.     term.setTextColor(colors.black)
  146.  else
  147.     term.setBackgroundColor(color1)
  148.     term.setTextColor(colors.white)
  149.  end
  150. term.setCursorPos(2,maxY)
  151.  term.clearLine()
  152.  write("<")
  153.  term.setCursorPos((maxX/2-#tostring(page)/2)+1,maxY)
  154.  write(page)
  155.  term.setCursorPos(maxX-1,maxY)
  156.  write(">")
  157.        
  158.  
  159.        
  160.  elseif not isUsing and not Options then --Exited program
  161.     term.setBackgroundColor(colors.black)
  162.     term.setTextColor(colors.white)
  163.     term.clear()
  164.     term.setCursorPos(1,1)
  165.     print("Goodbye !")
  166.  elseif isUsing and Options then
  167.     term.setBackgroundColor(colors.gray)
  168.     if color1 ~= colors.white then
  169.         term.setTextColor(colors.white)
  170.     else
  171.         term.setTextColor(colors.black)
  172.     end
  173.     term.clear()
  174.     color1 = numconv[choice]
  175.     color2 = numconv[choice2]
  176.     term.setCursorPos(1,1)
  177.     term.setBackgroundColor(color1)
  178.     term.clearLine()
  179.     term.setCursorPos(maxX-(maxX-2),1)
  180.     print("Options")
  181.     term.setCursorPos(math.ceil(maxX/2)+1,1)
  182.     print("|")
  183.     term.setCursorPos(maxX-6,1)
  184.     print("Return")
  185.     term.setBackgroundColor(colors.gray)
  186.     term.setTextColor(colors.white)
  187.     term.setCursorPos(15,3)
  188.     print("<->")
  189.     paintutils.drawLine(14,4,14+string.len(colnames[choice]),4,numconv[choice])
  190.     term.setCursorPos(3,4)
  191.     if color1 ~= colors.white then
  192.         term.setTextColor(colors.white)
  193.     else
  194.         term.setTextColor(colors.black)
  195.     end
  196.     print("1st color : " .. colnames[choice])
  197.     term.setBackgroundColor(colors.gray)
  198.     paintutils.drawLine(14,6,14+string.len(colnames[choice2]),6,numconv[choice2])
  199.     if color2 ~= colors.white then
  200.         term.setTextColor(colors.white)
  201.     else
  202.         term.setTextColor(colors.black)
  203.     end
  204.     term.setCursorPos(3,6)
  205.     print("2nd color : " .. colnames[choice2])
  206.     term.setBackgroundColor(colors.gray)
  207.     term.setTextColor(colors.white)
  208.     term.setCursorPos(15,7)
  209.     print("<->")
  210.     term.setCursorPos(5,10)
  211.     print("About this program")
  212.     term.setCursorPos(4,12)
  213.     print("HD's Todo list V1.6")
  214.     term.setCursorPos(1,14)
  215.     print("-masterdisasterHD : Orignal program and idea")
  216.     term.setCursorPos(1,17)
  217.     print("-s0r00t : V1.5 enhancements")
  218.    
  219.  end
  220. end
  221.  
  222. local function saveTasks(tbl)
  223.  local A = fs.open(taskFile, "w")
  224.  A.write(textutils.serialize(tbl))
  225.  A.close()
  226. end
  227.  
  228. local function addTask()
  229.  local tasks = getTasks()
  230.  term.setBackgroundColour(colors.black)
  231.  term.setTextColour(colors.white)
  232.  term.clear()
  233.  term.setCursorPos(1,1)
  234.  term.setCursorBlink(true)
  235.  write("Task: ")
  236.  local tsk = read()
  237.  table.insert(tasks, tsk)
  238.  saveTasks(tasks)
  239. end
  240.  
  241. local function delTask()
  242.  local tasks = getTasks()
  243.  term.setBackgroundColour(colors.black)
  244.  term.setTextColour(colors.white)
  245.  term.clear()
  246.  term.setCursorPos(1,1)
  247.  write("Task number: ")
  248.  local tsknmbr = tonumber(read())
  249.  table.remove(tasks, tsknmbr)
  250.  saveTasks(tasks)
  251. end
  252.  
  253. local function showTask(pg, pos, h, w)
  254.  local tasks = getTasks()
  255.  local step1 = (h-2)*(pg-1)
  256.  local step2 = (pos-1)+step1
  257.  term.setBackgroundColour(color2)
  258.  term.setTextColour(color1)
  259.  term.clear()
  260.  term.setCursorPos(1,1)
  261.  if tasks[step2] ~= nil then
  262.   write("Task #"..step2..":")
  263.   local text = tasks[step2]
  264.   local k = 1
  265.   for i=1, h-1 do
  266.    term.setCursorPos(1,i+1)
  267.    for j=1,w do
  268.     write(string.sub(text, k, k))
  269.     k = k + 1
  270.    end
  271.   end
  272.  term.setCursorPos(1,h)
  273.  write("Press any key to continue")
  274.  os.pullEvent("key")
  275.  end
  276. end
  277.  
  278. --Program loop
  279. redraw(page)
  280. local maxX, maxY = term.getSize()
  281. while isUsing do
  282.  sleep(0)
  283.  ev, b, xPos, yPos = os.pullEvent()
  284.    
  285.  
  286.   if ev == "mouse_click" then
  287.   if xPos == 2 and yPos == 1 and not Options then
  288.    addTask()
  289.   elseif xPos == 6 and yPos == 1 and not Options then
  290.    delTask()
  291.   elseif xPos >= maxX-12 and xPos <= maxX-4 and yPos == 1 and not Options then
  292.   Options = true
  293.   elseif xPos >=maxX-3 and xPos <= maxX and yPos == 1 and not Options then
  294.   isUsing = false
  295.   elseif xPos == 2 and yPos == maxY and not Options then
  296.    if page > 1 then
  297.     page = page - 1
  298.    end
  299.   elseif xPos == maxX-1 and yPos == maxY and not Options then
  300.    page = page + 1
  301.   elseif xPos > 1 and yPos < maxY and not Options then
  302.    showTask(page, yPos, maxY, maxX)
  303.   elseif xPos >= maxX-6 and xPos <= maxX-1 and yPos == 1 and Options then
  304.    Options = false
  305.    local opfile = fs.open("/.todocfg", "w")
  306.    opfile.writeLine(color1)
  307.    opfile.write(color2)
  308.    opfile.close()
  309.   elseif xPos == 15 and yPos == 3 and Options then
  310.     if choice-1 ~= -1 then
  311.         choice = choice-1
  312.     else
  313.         choice = 15
  314.     end
  315.     redraw(page)
  316.   elseif xPos == 17 and yPos == 3 and Options then
  317.     if choice+1 ~= 16 then
  318.         choice = choice+1
  319.     else
  320.         choice = 0
  321.     end
  322.     redraw(page)
  323.   elseif xPos == 15 and yPos == 7 and Options then
  324.     if choice2-1 ~= -1 then
  325.         choice2 = choice2-1
  326.     else
  327.         choice2 = 15
  328.     end
  329.     redraw(page)
  330.   elseif xPos == 17 and yPos == 7 and Options then
  331.     if choice2+1 ~= 16 then
  332.         choice2 = choice2+1
  333.     else
  334.         choice2 = 0
  335.     end
  336.     redraw(page)
  337.    end
  338.  elseif ev == "mouse_scroll" then
  339.   if b == -1 then
  340.    if page > 1 then page = page - 1 end
  341.   elseif b == 1 then
  342.    page = page + 1
  343.   end
  344.  
  345.  elseif ev == "timer" then
  346.      time_refresh()
  347. end
  348.  redraw(page)
  349. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement