Terminal Compatibility¶
fish writes various control sequences to the terminal. Some must be implemented to enable basic functionality, while others enable optional features and may be ignored by the terminal.
The terminal must be able to parse Control Sequence Introducer (CSI) commands, Operating System Commands (OSC) and optionally Device Control Strings (DCS). These are defined by ECMA-48. If a valid CSI, OSC or DCS sequence does not represent a command implemented by the terminal, the terminal must ignore it.
Control sequences are denoted in a fish-like syntax.
Special characters other than \
are not escaped.
Spaces are only added for readability and are not part of the sequence.
Placeholders are written as <Ps>
for a number or <Pt>
for an arbitrary printable string.
NOTE: fish does not rely on your system’s terminfo database. In this document, terminfo (TI) codes are included for reference only.
Required Commands¶
Sequence |
TI |
Description |
Origin |
---|---|---|---|
|
n/a |
Move cursor to the beginning of the line |
|
|
cud1 |
Move cursor down one line. |
|
|
cuu |
Move cursor up Ps columns, or one column if no parameter. |
VT100 |
|
cuf |
Move cursor to the right Ps columns, or one column if no parameter. |
VT100 |
|
cub1 |
Move cursor one column to the left. |
VT100 |
|
cub |
Move cursor to the left Ps times. |
VT100 |
|
cup |
Set cursor position (no parameters means: move to row 1, column 1). |
VT100 |
|
el |
Clear to end of line. |
VT100 |
|
ed |
Clear to the end of screen. |
VT100 |
|
clear |
Clear the screen. |
VT100 |
|
Request primary device attribute.
The terminal must respond with a CSI command that starts with the Failure to implement this will cause a brief pause at startup followed by a warning.
For the time being, both can be turned off by turning off the |
VT100 |
|
n/a |
am |
Soft wrap text at screen width. |
|
n/a |
xenl |
Printing to the last column does not move the cursor to the next line.
Verify this by running |
Optional Commands¶
Sequence |
TI |
Description |
Origin |
---|---|---|---|
|
it |
Move the cursor to the next tab stop (à 8 columns). This is mainly relevant if your prompt includes tabs. |
|
|
sgr0 |
Turn off bold/dim/italic/underline/reverse attribute modes and select default colors. |
|
|
bold |
Enter bold mode. |
|
|
dim |
Enter dim mode. |
|
|
sitm |
Enter italic mode. |
|
|
smul |
Enter underline mode. |
|
|
Su |
Enter double underline mode. |
kitty |
|
Su |
Enter curly underline mode. |
kitty |
|
Su |
Enter dotted underline mode. |
kitty |
|
Su |
Enter dashed underline mode. |
kitty |
|
rev |
Enter reverse video mode (swap foreground and background colors). |
|
|
ritm |
Exit italic mode. |
|
|
rmul |
Exit underline mode. |
|
|
setaf |
Select foreground color Ps from the 256-color-palette. |
|
|
setab |
Select background color Ps from the 256-color-palette. |
|
|
Su |
Select underline color Ps from the 256-color-palette. |
kitty |
|
setaf setab |
Select foreground/background color. This uses a color in the aforementioned 256-color-palette, based on the range that contains the parameter: 30-37 maps to foreground 0-7, 40-47 maps to background 0-7, 90-97 maps to foreground 8-15 and 100-107 maps to background 8-15. |
|
|
Select foreground color from 24-bit RGB colors. |
||
|
Select background color from 24-bit RGB colors. |
||
|
Reset background color to the terminal’s default. |
||
|
Su |
Select underline color from 24-bit RGB colors. |
kitty |
|
Su |
Reset underline color to the default (follow the foreground color). |
kitty |
|
indn |
Scroll up the content (not the viewport) Ps lines (called |
ECMA-48 |
|
n/a |
Enable the kitty keyboard protocol. |
kitty |
|
n/a |
Request cursor position report.
The response must be of the form This is used by the scrollback-push special input function, and inside terminals that implement the OSC 133 click_events feature. |
VT100 |
|
Se |
Reset cursor style to the terminal’s default. This is not used as of today but may be in future. |
VT520 |
|
Ss |
Set cursor style (DECSCUSR); Ps is 2, 4 or 6 for block, underscore or line shape. |
VT520 |
|
n/a |
Request terminal name and version (XTVERSION). This is only used for temporary workarounds for incompatible terminals. |
XTerm |
|
cvvis |
Enable cursor visibility (DECTCEM). |
VT220 |
|
n/a |
Disable mouse reporting. |
XTerm |
|
n/a |
Enable focus reporting. |
|
|
n/a |
Disable focus reporting. |
|
|
n/a |
Enable alternate screen buffer. |
XTerm |
|
n/a |
Disable alternate screen buffer. |
XTerm |
|
Enable bracketed paste. |
XTerm |
|
|
Disable bracketed paste. |
XTerm |
|
|
ts |
Set window title (OSC 0). |
XTerm |
|
Report working directory (OSC 7).
Since the terminal may be running on a different system than a (remote) shell,
the hostname (first parameter) will not be |
iTerm2 |
|
|
Create a hyperlink (OSC 8). This is used in fish’s man pages. |
GNOME Terminal |
|
|
Copy to clipboard (OSC 52). Used by fish_clipboard_copy. |
XTerm |
|
|
Mark prompt start (OSC 133), with kitty’s |
FinalTerm, kitty |
|
|
Mark command start (OSC 133), with kitty’s |
FinalTerm, kitty |
|
|
Mark command end (OSC 133); Ps is the exit status. |
FinalTerm |
|
|
Request terminfo capability (XTGETTCAP).
The parameter is the capability’s hex-encoded terminfo code.
To advertise a capability, the response must be of the form
Currently, fish only queries the indn string capability. |
XTerm (but without string capabilities), kitty; also adopted by foot, wezterm, contour, ghostty |
DCS commands and GNU screen¶
Fully-correct DCS parsing is optional because fish switches to the alternate screen before printing any DCS commands.
However, since GNU screen neither allows turning on the alternate screen buffer by default,
nor treats DCS commands in a compatible way,
fish’s initial prompt may be garbled by a DCS payload like +q696e646e
.
For the time being, fish works around this by checking for presence of the STY
environment variable.
If that doesn’t work for some reason, you can add this to your ~/.screenrc
:
altscreen on
Or add this to your config.fish
:
function GNU-screen-workaround --on-event fish_prompt
commandline -f repaint
functions --erase GNU-screen-workaround
end