# "Rules" that terminal programs follow

DevFeed: ["Rules" that terminal programs follow](<https://devfeed.tech/articles/rules-that-terminal-programs-follow-21114.md>)

Original publisher: [Read original article](<https://jvns.ca/blog/2024/11/26/terminal-rules/>)

Author: Julia Evans

Published: 2024-12-12T09:28:22Z

Content type: article

Language: en

Sources: [Julia Evans](<https://devfeed.tech/sources/julia-evans.md>)

Topics: [Terminal](<https://devfeed.tech/topics/terminal.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Shell](<https://devfeed.tech/topics/shell.md>), [Bash](<https://devfeed.tech/topics/bash.md>), [Linux](<https://devfeed.tech/topics/linux.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [c](<https://devfeed.tech/tags/c.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [linux](<https://devfeed.tech/tags/linux.md>), [posix](<https://devfeed.tech/tags/posix.md>), [terminal](<https://devfeed.tech/tags/terminal.md>), [utilities](<https://devfeed.tech/tags/utilities.md>)

## AI overview

An exploration of the informal rules and conventions that terminal programs commonly follow, including interrupt handling, quitting interfaces, color output, readline keybindings, and stdin/stdout conventions.

## Source excerpt

Recently I've been thinking about how everything that happens in the terminal is some combination of: Your operating system's job Your shell's job Your terminal emulator's job The job of whatever program you happen to be running (like top or vim or cat) The first three (your operating system, shell, and terminal emulator) are all kind of known quantities - if you're using bash in GNOME Terminal on Linux, you can more or less reason about how how all of those things interact, and some of their behaviour is standardized by POSIX. But the fourth one ("whatever program you happen to be running") feels like it could do ANYTHING. How are you supposed to know how a program is going to behave? This post is kind of long so here's a quick table of contents: programs behave surprisingly consistently these are meant to be descriptive, not prescriptive it's not always obvious which "rules" are the program's responsibility to implement rule 1: noninteractive programs should quit when you press Ctrl-C rule 2: TUIs should quit when you press q rule 3: REPLs should quit when you press Ctrl-D on an empty line rule 4: don't use more than 16 colours rule 5: vaguely support readline keybindings rule 5.1: Ctrl-W should delete the last word rule 6: disable colours when writing to a pipe rule 7: - means stdin/stdout these "rules" take a long time to learn programs behave surprisingly consistently As far as I know, there are no real standards for how programs in the terminal should behave - the closest things I know of are: POSIX, which mostly dictates how your terminal emulator / OS / shell should work together. I think it does specify a few things about how core utilities like cp should work but AFAIK it doesn't have anything to say about how for example htop should behave. these command line interface guidelines But even though there are no standards, in my experience programs in the terminal behave in a pretty consistent way. So I wanted to write down a list of "rules" that in my experi