Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- The main function
- function main()
- -- Read tasks from the task list
- taskfile = fs.open("tasks.txt", "r")
- tasks = {}
- task = taskfile.readLine()
- i = 1
- while task do
- tasks[i] = task
- i = i+1
- task = taskfile.readLine()
- end
- --Wrap monitors
- mon = peripheral.wrap("bottom")
- monOut = peripheral.wrap("back")
- --Write tasks to monitors
- mon.clear()
- monOut.clear()
- mon.setCursorPos(1,1)
- monOut.setCursorPos(1,1)
- for i = 1, #tasks do
- printWrapped(mon, i .. "." .. tasks[i])
- printWrapped(monOut, i .. "." .. tasks[i])
- end
- end
- -- Writes a string to the given display
- -- wrapped to a new line if necessary
- function writeWrapped(out, str)
- -- Get the cursor boundary and pos
- maxX, maxY = out.getSize()
- currX, currY = out.getCursorPos()
- -- Iterate over each character
- for i = 1, #str do
- -- Write the current character
- out.write(string.sub(str, i, i))
- currX = currX + 1
- -- Move down to the next line if needed
- if (currX > maxX) and (i < #str) then
- -- Skip spaces
- while string.sub(str, i + 1, i + 1) == ' ' do
- i = i + 1
- end
- -- Move down a line
- currX = 1
- currY = currY + 1
- out.setCursorPos(currX, currY)
- end
- end
- end
- -- Prints a string to the given display
- -- It's the same as above but with a newline
- function printWrapped(out, str)
- -- Do the thing
- writeWrapped(out, str)
- -- Move to the next line
- _, currY = out.getCursorPos()
- out.setCursorPos(1, currY+1)
- end
- -- Run everything
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement