docs: improve visualizations in TTY and PTY explanations

This commit is contained in:
Gabriel Nützi authored and Wez Furlong committed 2023-08-18 20:57:51 -07:00
1 parent 87a009924c
commit f2d78ff60d
1 file changed
+40 -17
+40 -17
View File
@@ -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
@@ -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?
@@ -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