It's a nice piece of work. I like it. Tree's output is probably easier for me to reason about when I'm handling it programmatically. There's a recursive structure.
A running total of maximum filename lengths per directory (i.e. column in display) triggers a flush-to-screen of the directories in buffer every time it hits a multiple of the terminal width.