Input file: output of Tower of Hanoi in Brainfuck (some codepoints may not render properly in your browser). The file basically uses escape codes (more specifically ^[[m;nH) to rewrite lines.

Running the command (you may need to do sudo apt-get install pv or equivalent)

cat hanoi.b.out |  pv -l -L 10 -q

gives output like

enter image description here

if the window size is big enough.

If not, the output looks like

enter image description here

where the image starts "scrolling down."

Naturally, this begs the question: why does this (mis-)behaviour happen when the window size is too small?


Not all of the output is cursor-addressing. Some of it is line-feeds, which will (when the cursor happens to be on the bottom row) cause the terminal to scroll up. Here's a visible rendering using unmap of the beginning of the output: look for the \n (newlines are "line-feeds");

\E[2;27HTowers of Hanoi in Brainf*ck
\E[3;15HWritten by Clifford Wolf <http://www.clifford.at/bfcpu/>

When you use a smaller screen-size, the line-feeds that didn't cause scrolling are more likely to be on the bottom row, so you'll see it scroll up.

  • So the zero-point (for the later rewrite commands) shifts once the output has scrolled down? – cutculus Jul 29 '17 at 14:02
  • yes - the chunks with \E[ to H move the cursor to an absolute point on the screen, but the part of the screen you'd like to update has scrolled up. – Thomas Dickey Jul 29 '17 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.