Skip to content

Commit d3b82df

Browse files
authored
Merge pull request #399 from pluiedev/pluie/jj-poqplzsntrln
docs/vt: document a bunch of OSCs
2 parents 98f16bc + 4a6a129 commit d3b82df

File tree

22 files changed

+759
-43
lines changed

22 files changed

+759
-43
lines changed

docs/nav.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@
182182
"path": "/reference",
183183
"title": "Reference"
184184
},
185+
{
186+
"type": "link",
187+
"path": "/external",
188+
"title": "External Protocols"
189+
},
185190
{
186191
"type": "folder",
187192
"path": "/concepts",
@@ -201,6 +206,11 @@
201206
"type": "link",
202207
"path": "/screen",
203208
"title": "Screen"
209+
},
210+
{
211+
"type": "link",
212+
"path": "/colors",
213+
"title": "Colors"
204214
}
205215
]
206216
},
@@ -434,6 +444,83 @@
434444
"title": "Shift-Escape Behavior (XTSHIFTESCAPE)"
435445
}
436446
]
447+
},
448+
{
449+
"type": "folder",
450+
"path": "/osc",
451+
"title": "OSC",
452+
"children": [
453+
{
454+
"type": "link",
455+
"path": "/0",
456+
"title": "Change Window Icon and Title (OSC 0)"
457+
},
458+
{
459+
"type": "link",
460+
"path": "/1",
461+
"title": "Change Window Icon (OSC 1)"
462+
},
463+
{
464+
"type": "link",
465+
"path": "/2",
466+
"title": "Change Window Title (OSC 2)"
467+
},
468+
{
469+
"type": "link",
470+
"path": "/4",
471+
"title": "Query or Change Palette Colors (OSC 4)"
472+
},
473+
{
474+
"type": "link",
475+
"path": "/5",
476+
"title": "Query or Change Special Colors (OSC 5)"
477+
},
478+
{
479+
"type": "link",
480+
"path": "/7",
481+
"title": "Change Working Directory (OSC 7)"
482+
},
483+
{
484+
"type": "link",
485+
"path": "/9",
486+
"title": "Show Desktop Notification (OSC 9)"
487+
},
488+
{
489+
"type": "link",
490+
"path": "/conemu",
491+
"title": "ConEmu Extensions (OSC 9;n)"
492+
},
493+
{
494+
"type": "link",
495+
"path": "/1x",
496+
"title": "Query or Change Dynamic Colors (OSC 10–19)"
497+
},
498+
{
499+
"type": "link",
500+
"path": "/22",
501+
"title": "Change Pointer Shape (OSC 22)"
502+
},
503+
{
504+
"type": "link",
505+
"path": "/52",
506+
"title": "Query or Change Clipboard Data (OSC 52)"
507+
},
508+
{
509+
"type": "link",
510+
"path": "/104",
511+
"title": "Reset Palette Colors (OSC 104)"
512+
},
513+
{
514+
"type": "link",
515+
"path": "/105",
516+
"title": "Reset Special Colors (OSC 105)"
517+
},
518+
{
519+
"type": "link",
520+
"path": "/11x",
521+
"title": "Reset Dynamic Colors (OSC 110–119)"
522+
}
523+
]
437524
}
438525
]
439526
},

docs/vt/concepts/colors.mdx

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
title: Colors
3+
description: All sorts of information regarding colors in terminal emulation.
4+
---
5+
6+
Ghostty emulates a full 256-color palette, as well as 5 **special colors**
7+
and 3 **dynamic colors**.
8+
9+
## Special Colors
10+
11+
The special colors, when specified, are used to color cells with particular
12+
styles — bold, underline, blink, reversed and italic. They can be queried
13+
or changed either with [OSC 4] using indices from 256 to 260 inclusive,
14+
or [OSC 5] with indices from 0 to 4 inclusive respectively. The ordinary
15+
palette colors are used instead of special colors when not specified.
16+
17+
[OSC 4]: /docs/vt/osc/4-5
18+
[OSC 5]: /docs/vt/osc/4-5
19+
20+
## Dynamic Colors
21+
22+
The dynamic colors are used by the terminal to color cells independent of
23+
their own styles, when they are selected, highlighted, etc. They are also
24+
supposed to be *dynamically updated* by programs after the terminal has been
25+
initialized, hence their name. Ghostty currently supports three of these
26+
colors: the foreground color, the background color and the cursor color,
27+
which are queried or modified with [OSCs 10 to 12] respectively.
28+
29+
[OSCs 10 to 12]: /docs/vt/osc/1x
30+
31+
## Color Specifications
32+
33+
Each color in the terminal is specified with a **color specification**.
34+
These originated from xterm, which allows any string that can be parsed by
35+
X11's standard [`XParseColor`] function to serve as a color. However, since
36+
Ghostty supports platforms other than X11, we have our own color parser that
37+
is compatible but not guaranteed to be the same as xterm, which is
38+
documented below.
39+
40+
[`XParseColor`]: https://linux.die.net/man/3/xparsecolor
41+
42+
### Hexadecimal RGB
43+
44+
<VTSequence sequence={["rgb:", "Pr", "/", "Pg", "/", "Pb"]} /><br/>
45+
<VTSequence sequence={["#", "Pr", "Pg", "Pb"]} />
46+
47+
Where each of `r`, `g` and `b` can be one to four hexadecimal digits,
48+
corresponding to 4, 8, 12 or 16 bit color channels respectively.
49+
50+
> [!NOTE]
51+
> When using the `#` syntax, each channel **must have the same number of
52+
> digits**.
53+
>
54+
> Additionally, Ghostty does not yet recognize 16-bit color channels when
55+
> using the `#` syntax. This is a limitation that may be resolved in the
56+
> future.
57+
58+
### Intensity RGB
59+
60+
Another format uses the numerical *intensity* of each channel, as follows:
61+
62+
<VTSequence sequence={["rgbi:", "Pr", "/", "Pg", "/", "Pb"]} />
63+
64+
Where each of `r`, `g` and `b` is a decimal number between `0` and `1`.
65+
66+
### Named
67+
68+
Certain colors can also be specified with their names. The exact list of
69+
accepted color names are implementation-defined, but Ghostty uses the
70+
[X color name database](https://gitlab.freedesktop.org/xorg/app/rgb) as used
71+
by X11 itself. The colors are ASCII case-insensitive, meaning `red` and `RED`
72+
correspond to the same color.

docs/vt/concepts/sequences.mdx

Lines changed: 97 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,89 @@ that programs interact with the terminal.
1010

1111
Programs running within terminals only have a single way to communicate
1212
with the terminal: writing bytes to the connected file descriptor
13-
(typically a pty). In order to differentiate between text to be
14-
displayed and commands to be executed, terminals use special syntax
15-
known collectively as **control sequences**.
16-
17-
Due to the historical nature of terminals, control sequences come
18-
in a handful of different formats. Most begin with an escape character
19-
(`0x1B`), so control sequences are sometimes referred to as
20-
**escape codes** or **escape sequences**.
21-
22-
There are eight types of control sequences:
23-
24-
- Control Characters
25-
- Escape Sequences
26-
- CSI Sequences ("Control Sequence Introducer")
27-
- OSC Sequences ("Operating System Command")
28-
- DCS Sequences ("Device Control Sequence")
29-
- SOS Sequences ("Start Of String")
30-
- PM Sequences ("Privacy Message")
31-
- APC Sequences ("Application Program Command")
13+
(typically a pseudo-terminal, or a "pty" for short). In order to
14+
differentiate between text to be displayed and commands to be executed,
15+
terminals use special syntax known collectively as **control sequences**.
3216

3317
Each type of control sequence has a different format and purpose.
3418
They are described below along with their specific syntax. The
3519
[reference](/docs/vt/reference) contains a full list of supported
3620
control sequences grouped by type.
3721

38-
## Control Characters
22+
## C0 control characters
3923

40-
Control characters are single byte characters that have a special
41-
meaning. They have no encoding format; you send the bytes as-is.
42-
For example, [backspace](/docs/vt/control/bs) is `0x08`,
43-
[linefeed](/docs/vt/control/lf) is `0x0A`, etc.
24+
Each control sequence starts with a special, unprintable character, known
25+
as a **control character**. The simplest control characters, known as
26+
**C0 control characters**, lie between `0x00` and `0x20` in the ASCII
27+
encoding and take no parameters other than themselves.
4428

4529
There are very few control characters, but they're important
4630
to be aware of because the single byte value impacts the terminal
4731
state.
4832

49-
## Escape Sequences
33+
C0 characters meaningful to terminal emulation include:
5034

51-
Escape sequences are in the format below. An example escape sequence
52-
is `ESC D`.
35+
| C0 | Abbr | Full name | Function |
36+
|--------|---------|-----------------|---------------------------------------------|
37+
| `0x07` | [`BEL`] | Bell | Raise the attention of the user. |
38+
| `0x08` | [`BS`] | Backspace | Move the cursor backward one position. |
39+
| `0x09` | [`TAB`] | Tab | Move the cursor right to the next tab stop. |
40+
| `0x0A` | [`LF`] | Linefeed | Move the cursor down one line. |
41+
| `0x0D` | [`CR`] | Carriage Return | Move the cursor to the leftmost column. |
42+
43+
[`BEL`]: /docs/vt/control/bel
44+
[`BS`]: /docs/vt/control/bs
45+
[`TAB`]: /docs/vt/control/tab
46+
[`LF`]: /docs/vt/control/lf
47+
[`CR`]: /docs/vt/control/cr
48+
49+
## Escape sequences
50+
51+
One of the C0 characters, Escape (`0x1b`, `ESC`), is special. It can either
52+
start a few discrete sequences or begin entire families of sequences, which is
53+
also why control sequences are also *pars pro toto* commonly known as
54+
**escape sequences**.
55+
56+
Not all sequences that begin with Escape are Escape sequences as defined here
57+
(they are more likely to be [C1 sequences](#c1-sequences)),
58+
but a true Escape sequence like `ESC D` are in the format below.
5359

5460
```
5561
esc_sequence = "0x1B" intermediates final
5662
intermediates = [0x20-0x2F]*
5763
final = [0x30-0x7E]
5864
```
5965

60-
## CSI Sequences
66+
## `Fe` sequences
67+
68+
When Escape is followed by certain printable characters, for various historical
69+
reasons they are instead interpreted together as **C1 control characters**,
70+
some of which are responsible for many families of sequences known collectively
71+
as `Fe` sequences. These characters can also be represented by single 8-bit
72+
characters, but they remain **predominantly** encoded with Escape characters as
73+
to avoid conflicting with UTF-8 and other high-byte encodings usually used in
74+
modern terminals.
75+
76+
| ESC code | C1 | Abbr | Full name | Function |
77+
|----------|--------|------|-----------------------------|----------------------------------------------------------------------------------------------------------|
78+
| `ESC [` | `0x9b` | CSI | Control Sequence Introducer | By far the most common. Uses integers to control the cursor, the screen, modes, cells, and their styles. |
79+
| `ESC ]` | `0x9d` | OSC | Operating System Command | Often used in modern terminal extensions to transmit string data. |
80+
| `ESC P` | `0x90` | DCS | Device Control Sequence | Most often used when querying the terminal's capabilities (XTGETTCAP). Rare otherwise. |
81+
| `ESC _` | `0x9f` | APC | Application Program Command | Used in very complex protocols like the Kitty Graphics Protocol that require arbitrary payloads. |
82+
| `ESC X` | `0x98` | SOS | Start of String | Obsolete. Ignored by Ghostty. |
83+
| `ESC ^` | `0x9e` | PM | Private Message | Obsolete. Ignored by Ghostty. |
84+
85+
### CSI
86+
87+
CSI sequences are *by far* the most common type of C1 sequences.
88+
They use integer parameters separated either with colons (`:`) or semicolons
89+
(`;`) to move the cursor, set the terminal's mode, scroll up or down, insert
90+
and delete cells and lines, change the styles of cells, etc.
6191

62-
CSI sequences are in the format below. An example CSI sequence
63-
is `ESC [ 1 ; 2 m`. CSI sequences are only capable of encoding integer values.
92+
Their primary limitation is that they can **only** encode integer values.
93+
Other sequence types such as OSC or DCS are needed to encode string data.
94+
95+
CSI sequences follow the format below. An example CSI sequence is `ESC [ 1 ; 2 m`.
6496

6597
```
6698
csi_sequence = "0x1B" "[" params intermediates final
@@ -71,21 +103,45 @@ intermediates = [0x20-0x2F]*
71103
final = [0x40-0x7E]
72104
```
73105

74-
## OSC Sequences
106+
### OSC
107+
108+
OSC sequences are typically used to encode strings or other non-integer data to
109+
transmit between the terminal and an application. They usually alter variables
110+
regarding the terminal emulator itself, such as its title, palette,
111+
clipboard, etc., or instruct it on extra features like hyperlinks, progress
112+
reports, the current working directory, and so on.
113+
114+
As a result of its flexibility, OSC sequences are very often used by modern
115+
extensions to offer new functionality that older terminals can simply ignore.
116+
117+
An OSC sequence begins with OSC (`ESC ]` or `0x9d`). Then, by convention, an
118+
integer is added to identify the operation
75119

76-
OSC Sequences are typically used to encode strings or other non-integer data to
77-
transmit between the terminal and the application. The format of an OSC sequence
78-
is below. An example OSC sequence is `OSC 2 ; 👻 Ghostty 👻 ST` (where `ST` is
79-
the String Terminator). By convention, OSC sequences *usually* have some integer
80-
identifier to identify the sequence.
120+
The format of an OSC sequence is below. By convention, OSC sequences are
121+
identified by an integer identifier followed by a semicolon (`;`), although
122+
this is never required by the standard. Certain obsolete OSC sequences use
123+
non-numeric identifiers before the semicolon, but Ghostty does not support
124+
125+
> [!NOTE]
126+
> Due to yet more convoluted historical reasons, OSC sequences in xterm (and
127+
> by extension Ghostty) may be terminated with the Bell character (`BEL`,
128+
> `0x07`) instead of the standard String Terminator (`ST`, `ESC \` or `0x9c`).
129+
>
130+
> While they are in most cases interchangeable, Ghostty will try to echo back
131+
> the terminator used in an OSC sequence when replying, to ensure maximum
132+
> compatibility with older programs and terminals. New code should always
133+
> prefer `ST` due to standards compliance.
134+
135+
them. An example OSC sequence is `OSC 2 ; 👻 Ghostty 👻 ST` (where `ST` is
136+
the String Terminator).
81137

82138
```
83-
osc_sequence = "0x1B" "]" data ST
139+
osc_sequence = "0x1B" "]" data terminator
84140
data = [0x20-0xFF]
85-
ST = "0x1B" "0x5C"
141+
terminator = "0x1B" "0x5C"
86142
```
87143

88-
## DCS Sequences
144+
### DCS
89145

90146
DCS Sequences are like a CSI sequence combined with an OSC sequence: they
91147
natively support integer parameters as well as string values. An example DSC
@@ -101,7 +157,7 @@ data = [0x20-0xFF]
101157
ST = "0x1B" "0x5C"
102158
```
103159

104-
## APC Sequences
160+
### APC
105161

106162
Ghostty supports APC sequences. Currently there is only one supported APC
107163
sequence: the Kitty Graphics Protocol sequence. This is documented [here](https://sw.kovidgoyal.net/kitty/graphics-protocol/).
@@ -112,7 +168,7 @@ data = [0x20-0xFF]
112168
ST = "0x1B" "0x5C"
113169
```
114170

115-
## SOS and PM Sequences
171+
### SOS and PM
116172

117173
SOS and PM sequences are entirely ignored by Ghostty.
118174

docs/vt/external.mdx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
title: External Protocols
3+
description: A list of external protocols that Ghostty supports.
4+
---
5+
6+
Ghostty inherits the rich tradition of innovation from other terminal
7+
emulators, and many modern, well-written specifications do not need to
8+
be reinvented here. If Ghostty's behavior deviates from these specifications,
9+
we treat them as bugs which will be fixed according to spec.
10+
11+
Note that we may still provide specifications here if upstream behavior is
12+
not well-specified (such is the case for most xterm and [ConEmu] extensions),
13+
or Ghostty intentionally deviates from it for good reason.
14+
15+
[ConEmu]: /docs/vt/osc/conemu
16+
17+
Below is a list of protocols that Ghostty supports, which originate from other
18+
terminal emulators:
19+
20+
| Protocol | Specification |
21+
|-------------------------------|--------|
22+
| OSC 8 (Hyperlinks) | [VTE and iTerm2](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda)|
23+
| OSC 21 (Kitty Color Protocol) | [Kitty](https://sw.kovidgoyal.net/kitty/color-stack/)|

0 commit comments

Comments
 (0)