Skip to content

Commit

Permalink
docs: improve visualizations in TTY and PTY explanations
Browse files Browse the repository at this point in the history
  • Loading branch information
gabyx authored and wez committed Aug 19, 2023
1 parent 87a0099 commit f2d78ff
Showing 1 changed file with 40 additions and 17 deletions.
57 changes: 40 additions & 17 deletions docs/what-is-a-terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ A shell indirectly communicates with the terminal via the TTY interface to the
kernel, which manages the actual communication with the terminal.

```mermaid
graph TD
TTY[TTY device in the kernel, such as /dev/tty0] -- input --> SHELL[Shell Program]
TERM[Terminal Device] -- input --> TTY
SHELL -- output --> TTY
TTY -- output --> TERM
flowchart LR
subgraph Kernel
direction LR
TTY["TTY device\n(e.g. /dev/tty/0)"]
end
subgraph Userspace
SHELL["Shell Program (e.g. zsh)"] <-- "input\noutput" --> TTY
end
TTY <-- "input\noutput" --> TE["Terminal Device"]:::td
classDef td stroke:#00F,stroke-width:2px
```

Again, the TTY interface doesn't provide a way for the shell program to know
Expand Down Expand Up @@ -128,13 +134,20 @@ on the associated terminal also needs to respect the setting of `TERM` and use
an appropriate library to resolve the correct escape sequences.

```mermaid
graph TD
TTY[TTY device in the kernel, such as /dev/tty0] -- input --> SHELL[Shell Program]
SHELL -- output --> TTY
APP[Application, such as vim] -- output --> TTY
TTY -- input --> APP
TTY -- output --> TERM
TERM[Terminal Device] -- input --> TTY
flowchart
subgraph Kernel
direction TB
TTY["TTY device\n(e.g. /dev/tty/0)"]
end
subgraph Userspace
SHELL["Shell Program (e.g. zsh)"] <-- input/output --> TTY
SHELL -. "starts" .-> APP
APP["Application\n(e.g. vim)"] <-- input/output --> TTY
end
TTY <-- input/output --> TE["Terminal Device"]:::td
classDef td stroke:#00F,stroke-width:2px
```

## What about stdin, stdout and stderr?
Expand Down Expand Up @@ -208,11 +221,21 @@ side allowing for passing information about the window size, and the client side
essentially just being the I/O stream.

```mermaid
graph TD
PTY[PTY device in the kernel, such as /dev/pts/0] -- input --> SHELL[Shell Program]
TE[Terminal Emulator] -- input --> PTY
SHELL -- output --> PTY
PTY -- output --> TE
flowchart
subgraph Kernel
direction TB
PTYC["PTY client\n(e.g. /dev/pts/0)"]
PTYM[PTY master]
PTYC <--> PTYM
end
subgraph Userspace
SHELL["Shell Program (e.g. zsh)"] <-- input/output --> PTYC
SHELL -. "starts" .-> APP
APP["Application\n(e.g. vim)"] <-- input/output --> PTYC
PTYM <-- input/output --> TE["Terminal Emulator\n(e.g. wezterm)"]:::wezterm
classDef wezterm stroke:#00F,stroke-width:2px
end
```

A *Terminal Emulator* is a program that creates a PTY and then spawns a child
Expand Down

0 comments on commit f2d78ff

Please sign in to comment.