Advertisement
BruceWplays

todo V6

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