# What a terminal is

Address: https://nowa.im/cotty/posts/what-a-terminal-is/  
Created: 2026-11-22

A terminal is a byte-stream interface between a person and a program. That one fact explains why coding agents moved into terminals, and what terminals still fail to give them. cotty starts from it.

The interface has two directions:

- Input: the terminal turns key presses into bytes and sends them to the program.
- Output: it turns the bytes the program sends back into characters on a screen.

Control commands such as color, cursor movement and clearing the screen are special byte sequences inside the same stream.

## History

"Terminal" first meant hardware: the device at the end (the terminal) of a line. First came the teletype, from which Unix has the abbreviation `tty`. Then came terminals with screens such as the DEC VT100, connected to a host by a serial line. The host only sent and received bytes. The terminal device did the displaying.

Today's foot, Alacritty and the like are properly called **terminal emulators**. They emulate the behavior of hardware of the VT100 generation.

## Layers in modern Linux

```text
 you ⇄ terminal emulator (draws characters, reads the keyboard)
        ⇅  byte stream
     PTY master ── kernel tty layer (line discipline) ── PTY slave /dev/pts/N
                                                   ⇅
                                            bash / vim / agent …
```

- **Terminal emulator**: displays and reads the keyboard. It runs no commands itself.
- **PTY (pseudo-terminal)**: a pair of virtual devices provided by the kernel. It replaces the serial line.
- **tty layer and line discipline**: what the kernel does for programs, such as echo, backspace handling, and turning `Ctrl+C` into SIGINT.
- **Shell**: an ordinary program running in the terminal. It is not the terminal.

Terms:

- Terminal: the device or the emulator.
- Console: the main terminal of a machine.
- Shell: the command interpreter.

## Standards

There are two halves, and they govern different things:

1. **The side of programs and the kernel: POSIX.** POSIX defines a terminal as "a character special file that obeys the specifications of the general terminal interface", and it specifies `termios`: whether input is echoed, whether it is read by line or by character, and which key produces which signal. By this definition a terminal is a **device interface**, not a window.
2. **The control language inside the byte stream: ECMA-48.** It is the same content as ISO/IEC 6429 and the older ANSI X3.64, and it defines escape sequences such as `ESC [ ... m`. "ANSI escape codes" come from here. Example: `printf '\e[1;31mhi\e[0m'`.

In practice:

- No standard says what a terminal emulator must do. The de facto standard is **compatibility with VT100, VT220 and xterm**, and the xterm control sequence document is the reference everyone uses.
- True color, OSC 8 hyperlinks, the Kitty keyboard protocol, Sixel and the Kitty graphics protocol are all extensions outside any standard.
- Because terminals differ in ability, the `terminfo` database describes what each kind can do, and the `TERM` environment variable tells a program which kind it is talking to. In foot, `TERM=foot`.

## Terminal and GUI

A terminal can also handle keyboard and mouse, and it has color, images and partial updates. The difference is not in features. It is in the **basic abstraction**:

- A terminal program faces **a character grid drawn by someone else**, and talks to it over **one byte stream**.
- A GUI program controls **every pixel** itself, and talks to the system through **structured messages and events**.

| | Terminal (TUI) | GUI |
|---|---|---|
| Smallest display unit | A character cell (row and column): a character plus attributes such as color and bold | A pixel |
| Who draws | The terminal emulator. Font, size and colors belong to the terminal and the user | The program, or its toolkit |
| How it talks to the system | One byte stream, with control commands among the text | A structured protocol, such as Wayland's surfaces, buffers and typed events |
| Keyboard | Keys are encoded as bytes, and some combinations cannot be told apart | Press and release are separate events with full modifier information |
| Mouse | The program turns it on. Clicks are encoded as byte sequences, with coordinates in cells | Pixel coordinates, with hover, drag and drop, and gestures |
| Partial update | Move the cursor and overwrite those cells | The program manages layers and composes by frame |
| Images | A later extension (Sixel, the Kitty protocol), placed over cells | Native |

The key differences:

1. **Input is lossy bytes.**
   - `Ctrl+I` and `Tab` are both `0x09`. `Ctrl+M` and Enter are the same.
   - `Esc` alone and `Alt+key` start with the same byte, and a program can only guess by waiting.
   - A program never receives "key released".
   - A mouse click reaches the program as bytes such as `ESC [<0;12;5M`. Extensions such as the Kitty keyboard protocol exist to fill these holes.
2. **A program only writes output, and does not know what is on the screen.** To learn the terminal's state it must send a request and wait for the answer to come back mixed into its input. So vim and ncurses keep a copy in memory of what they believe the screen shows, compute the difference, and send that. A GUI has a complete widget tree, and the system can read it through accessibility interfaces.
3. **A byte stream can go anywhere, and this is the terminal's greatest strength.**
   - A program can run remotely over ssh or a serial line, be detached and reattached in tmux, be recorded and replayed with `script`, and be used at very low bandwidth.
   - A program does not need a connection to a display server.
   - Output is also data and composes through pipes. A program uses `isatty()` to tell whether it is writing for a person or for a pipe.
   - A GUI depends on a local display server. Remote use needs a whole solution such as waypipe or RDP.
4. **Appearance belongs to the user.** The terminal decides font and colors, and when the theme changes every TUI changes with it. A GUI program must adapt one by one.

In summary, a terminal is like **a remote display protocol designed in the 1970s**. Its unit is the character cell, control and content share one channel, and drawing is left to the other end. It looks more and more like a restricted GUI, but this base gives it what a GUI finds hard: it works remotely, it composes, it costs very little, and it can be driven entirely from the keyboard.

## What we take from this

Three consequences shape cotty.

1. **The base is why agents live here.** A byte stream goes anywhere, and output is also data. A language model reads and writes text, so the terminal is the one interface it can use without an adapter. We keep that base. `TERM` and terminfo must keep working, and so must an old program reached over ssh.
2. **The same base carries no meaning.** The stream has no command boundaries and no exit codes, and it does not say which program is in the foreground. A person supplies all of that by looking. An agent cannot, so it wraps a subshell of its own, or takes a snapshot of the screen, sleeps, and guesses. cotty's session kernel fills this gap, and it does so without breaking the stream.
3. **What a terminal shows is the state of a grid.** So two ends can sync the state and not the bytes. That makes a session usable over a poor network, and it lets the same session open on a laptop and on a phone.

How these become a product is in [Positioning](https://nowa.im/cotty/product/positioning/) and [Capabilities](https://nowa.im/cotty/product/capabilities/).

## References

- [POSIX: General Terminal Interface](https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/V1_chap11.html)
- [ECMA-48: Control functions for coded character sets](https://ecma-international.org/publications-and-standards/standards/ecma-48/)
- [XTerm Control Sequences](https://invisible-island.net/xterm/ctlseqs/ctlseqs.html)

This post was written from working knowledge of these documents. It was not checked against them line by line.
