Everything you ever wanted to know about terminals
One thing that the author doesn&#x27;t seem to know about is &#x2F;dev&#x2F;tty. In the article the escape codes are just sent to stdout. Though an awful lot of applications (including the greatest ones) do this, IMHO this is wrong. The terminal control codes are used to control a terminal, and they are often not meant to be part of the output stream, for example when the output is piped or redirected to a text file. When what you intend to do is to make your output fancy only when the output is a terminal, surely you should just send everything to stdout and use isatty to decide whether to also send those terminal control codes. But if what you want to build is a whole TUI like vim or the author&#x27;s example app, you should send all the control to &#x2F;dev&#x2F;tty. This way if needed you can extend your app to be able to be a useful part of a pipe, as bytes sent to &#x2F;dev&#x2F;tty will not be redirected but will always be handled by the terminal. To prove that this can be useful, fzf, a fuzzy matcher, uses a TUI to let users input the pattern and pick among the matches, and prints the result to stdout. Sadly, however, it uses stderr to control the terminal instead of &#x2F;dev&#x2F;tty; this makes its ability to print error messages somewhat limited and its behavior unexpected when stderr is redirected. Also imagine that you can use vim in a pipe, instead of sed or awk, to see the effect of your edits live. Also, try `vi &gt; &#x2F;dev&#x2F;null`. I&#x27;d say the behavior is a bug. IIRC ncurses makes use of &#x2F;dev&#x2F;tty and by default makes the app made with it redirectable, and this is a reason we should use it in the 21st century, among others. What&#x27;s sad to me is that so far all the Rust terminal libs I&#x27;ve seen ignore &#x2F;dev&#x2F;tty, so it&#x27;s impossible to use them to build something that both have a good TUI and can be used in pipes.