Guest User

todo

a guest
Dec 15th, 2019
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- The main function
  2. function main()
  3.   -- Read tasks from the task list
  4.   taskfile = fs.open("tasks.txt", "r")
  5.   tasks = {}
  6.   task = taskfile.readLine()
  7.   i = 1
  8.   while task do
  9.     tasks[i] = task
  10.     i = i+1
  11.     task = taskfile.readLine()
  12.   end
  13.    
  14.   --Wrap monitors
  15.   mon = peripheral.wrap("bottom")
  16.   monOut = peripheral.wrap("back")
  17.  
  18.   --Write tasks to monitors
  19.   mon.clear()
  20.   monOut.clear()
  21.   mon.setCursorPos(1,1)
  22.   monOut.setCursorPos(1,1)
  23.   for i = 1, #tasks do
  24.     printWrapped(mon, i .. "." .. tasks[i])
  25.     printWrapped(monOut, i .. "." .. tasks[i])
  26.   end
  27. end
  28.  
  29.  
  30. -- Writes a string to the given display
  31. -- wrapped to a new line if necessary
  32. function writeWrapped(out, str)
  33.   -- Get the cursor boundary and pos
  34.   maxX, maxY = out.getSize()
  35.   currX, currY = out.getCursorPos()
  36.  
  37.   -- Iterate over each character
  38.   for i = 1, #str do
  39.     -- Write the current character
  40.     out.write(string.sub(str, i, i))
  41.     currX = currX + 1
  42.    
  43.     -- Move down to the next line if needed
  44.     if (currX > maxX) and (i < #str) then
  45.       -- Skip spaces
  46.       while string.sub(str, i + 1, i + 1) == ' ' do
  47.         i = i + 1
  48.       end
  49.      
  50.       -- Move down a line
  51.       currX = 1
  52.       currY = currY + 1
  53.       out.setCursorPos(currX, currY)
  54.     end
  55.   end
  56. end
  57.  
  58.  
  59. -- Prints a string to the given display
  60. -- It's the same as above but with a newline
  61. function printWrapped(out, str)
  62.   -- Do the thing
  63.   writeWrapped(out, str)
  64.  
  65.   -- Move to the next line
  66.   _, currY = out.getCursorPos()
  67.   out.setCursorPos(1, currY+1)
  68. end
  69.  
  70.  
  71. -- Run everything
  72. main()
RAW Paste Data