Advertisement
BruceWplays

Untitled

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