1

telnet towel.blinkenlights.nl

Typing the above command in a terminal on Linux produces a Star Wars animation.

What baffles me is how the writers were able to produce an animation in a terminal in the first place. Normally one cannot undelete previous lines in a terminal right? Even with ~Ctrl+L~ the terminal prompt remains. Same goes for the famous steam locomotive animation in linux produced via the command sl/

How does the source code work for these commands in the first place, What terminal magic is required to produce individual frames of an animation and delete previous ones onto the screen?

I can imagine how one might doe this with Emacs, (for instance "M-x butterfly") but on a terminal it seems like magic!

3
  • 4
    (1) telnet towel.blinkenlights.nl | head -c 400K > capture (2) Wait. (3) less capture (4) Notice ESC[H and ESC[J. (5) Investigate: CUP and ED here. (6) Notice frames starting with ESC[H. (7) Exit less and replay in a constant rate: <capture pv -qL 10000 // Conclusion: the server clears your screen by sending ESC[J and then sends single frames, each printed from the top thanks to ESC[H. The animation is "smooth" because ESC[H and the following frame is sent without delay. The server waits between frames. Feb 25, 2020 at 22:20
  • 4
    So the magic is like "send control sequence to move the cursor to the upper left corner, send next frame, wait, repeat". Feb 25, 2020 at 22:27
  • 1
    Thanks Kamil! That clears it! Feb 25, 2020 at 23:27

0

Browse other questions tagged .