Terminal Emulation
clackatoo emulates enough of xterm for shells, ncurses programs such as htop,
and vim, under TERM=xterm-256color, with the extensions modern terminals
such as kitty, foot, WezTerm and Ghostty share: the kitty keyboard protocol,
synchronized output, styled and colored underlines, a program's progress
shown on its tab, the notifications programs ask for, and
images: kitty's graphics protocol, sixel and iTerm2's. Sequences it doesn't support are ignored, as xterm ignores
ones it doesn't know.
The environment #
A program started in a clackatoo terminal gets the daemon's environment, with these changes:
| Variable | Value |
|---|---|
TERM | xterm-256color |
COLORTERM | truecolor |
TERM_PROGRAM | clackatoo |
TERM_PROGRAM_VERSION | The clackatoo version. |
Variables describing whatever terminal the daemon was started in are removed,
so programs don't think they're inside it. These include TMUX, TMUX_PANE,
STY, VTE_VERSION, KITTY_WINDOW_ID, WEZTERM_PANE,
ALACRITTY_WINDOW_ID, ITERM_SESSION_ID, WT_SESSION, COLUMNS, and
LINES.
The program runs in its own session, with the terminal as its controlling terminal, so job control and Ctrl-C work as usual.
The display #
The variables that say which desktop a program opens its windows on follow the
desktop's logon, not the daemon's environment. A daemon started over ssh,
before anyone signed in to the machine, has no WAYLAND_DISPLAY, but a
terminal opened after you sign in there still gets one. The variables are
WAYLAND_DISPLAY, DISPLAY, XAUTHORITY, XDG_SESSION_TYPE,
XDG_CURRENT_DESKTOP, XDG_SESSION_DESKTOP, DESKTOP_SESSION, SWAYSOCK,
I3SOCK, HYPRLAND_INSTANCE_SIGNATURE, and NIRI_SOCKET. They come from the
first of these that has a display whose socket is still there
(WAYLAND_DISPLAY's in $XDG_RUNTIME_DIR, or where it names, and
/tmp/.X11-unix/XN for a DISPLAY of :N):
- The systemd user manager's environment, as
systemctl --user show-environmentprints it. GNOME, KDE, and sway or Hyprland with their usual config put their display there as you sign in; GNOME takes it out as you sign out, while sway and Hyprland leave it, which is why its socket must still be there. All of the variables are then systemd's, and one systemd hasn't got is removed, but forXDG_SESSION_TYPE. With neither of its displays' sockets there, none of systemd's variables are taken. - The daemon's own environment. A desktop that tells systemd nothing, as sway started by hand, keeps working this way for a daemon started inside it, while it lasts.
- None: all of the variables are removed, but
XDG_SESSION_TYPE.
A display whose socket has gone is removed. A display on another host, as
ssh's X forwarding gives (localhost:10.0), can't be checked, so one the
daemon was started with is kept for as long as it runs: only a desktop on this
machine that has gone is dropped.
XDG_SESSION_TYPE says what kind of session a program runs in, and toolkits
read it to choose between Wayland and X: Qt, Chromium, and Electron choose
Wayland only when it's wayland. A daemon started over ssh has tty, which
beside a WAYLAND_DISPLAY would send them to X. GNOME tells systemd wayland
as you sign in, so it comes with the display. Beside a display, a session type
that's missing or tty, as sway and Hyprland leave it, becomes wayland, or
x11 with only an X display. With no display, the daemon's own tty is still
true, so it stays.
The daemon reads systemd's environment as it starts, waiting up to 300 ms for
it so the terminals it makes again after a restart have the display. It reads
it again whenever a Wayland socket (wayland-N in $XDG_RUNTIME_DIR) or an X
socket (in /tmp/.X11-unix) appears or goes, and 0.5, 2 and 5 seconds after
that, as a desktop tells systemd a moment after making its socket; and as each
terminal is made, as systemd's can change with no socket coming or going,
which the terminal's shell takes at its first prompt. Nothing waits for these
reads, and only one runs at a time. It never checks on a timer. Where it can't
watch for sockets, it says so in its log, and tries again a while later,
waiting twice as long each time up to a minute, as when $XDG_RUNTIME_DIR is
removed as your last session ends and made again as you sign in. Each change
is logged, as
display: from systemd's user manager: WAYLAND_DISPLAY=wayland-0 ….
Every program the daemon starts from then on gets the display as it is: a terminal's program, an agent, a language server. The daemon never changes its own environment. A program already running keeps the environment it started with, as on any Unix, so an agent or language server started before you signed in has no display until it's started again.
Shells already open follow before the next command they run, or bash at
its next prompt. bash, zsh and fish, started as your shell with clackatoo's
integration, read shell/display in the daemon's
runtime directory at each prompt, and fish
and zsh again right before each command you type runs, and set or unset the
variables to match. So in fish or zsh, a command typed at a prompt drawn hours
before you signed in still gets the display. The daemon writes the file whole,
readable by you alone, whenever the display changes. A shell changes a
variable only while it has the value the shell started with, or the value the
shell last gave it, so one you set yourself, in your startup files or at the
prompt, stays yours. The file is read with the shell's own builtins, starting
nothing, and its few lines are only looked at when they've changed: about 20
to 30 µs a prompt or command.
fish reads it in its fish_preexec event, and zsh before your hooks in
preexec_functions (a plain preexec function of yours runs before those).
bash follows at its next prompt only, so in bash the command typed at a prompt
drawn before you signed in runs with the old display, and the one after it has
the new. What bash shows before running a command, PS0, runs its $(…) in a
subshell, which can't change the shell's variables. What could run in the
shell itself would get in the way of a DEBUG trap of your own: bash 5.3's
${| …; } in PS0 sets it off on clackatoo's call before your command, and a
DEBUG trap of clackatoo's would have to share it. Either breaks tools built
on it, as bash-preexec is.
A program you started from a shell is no different from one the daemon started: once running, it keeps the environment it started with. A shell following the display changes what the commands it runs from then on get, never what's already running, so an agent you started before you signed in has no display until you start it again.
clackatoo display shows the display
programs get now, and where it came from. CLACKATOO_DISPLAY=off in the
daemon's environment turns all of this off: programs get the daemon's own
environment, and shells change nothing. Each machine's daemon follows its own
desktop; nothing about it passes between machines.
Screen behavior #
- Scrollback: the primary screen keeps the last 10,000 lines that scroll
off its top. Lines only enter scrollback when the whole screen scrolls.
Scrolling inside a region an app has narrowed (as vim does) discards them.
Scrollback is stored as compact text, typically under 100 bytes a line, and
remembers which lines were wrapped, so they can be rewrapped to another
width. Compacting a line takes about as long as printing it did, so by
default the daemon waits until a terminal's output has paused for 100 ms.
Lines that scroll away during a flood (
catof a huge file) are never compacted at all. Until then, history keeps lines as they were on screen, about 8 bytes per column, capped at 16 MiB per terminal. The daemon's--scrollback-compactionoption changes this:eagercompacts each line as it scrolls off, which is the smallest but the slowest, andoffnever compacts, which is the fastest but the largest. - Floods: a terminal printing without end never holds up another you're typing in. The daemon reads it last in each turn, after updates have gone out, and stops as soon as anything else is ready. Output a program prints at once, such as a full-screen redraw, is still shown whole, and a program's last output always reaches its pane before the pane closes.
- Resizing: lines on the primary screen are rewrapped to the new width, and the cursor stays on the same character. A line that started in scrollback is rewrapped whole, as if it had been printed at the new width, so its part on screen still lines up with its part above. Only the last few screens' worth of a very long line is rewrapped, and older scrollback is left as it is. When the screen gets shorter, blank lines below the cursor go first, then lines above it move into scrollback. Erasing the top line or scrolling it away ends a line continuing from scrollback, so a resize never joins what's printed next onto it. The alternate screen is cut off or extended instead, because the full-screen programs that use it redraw after a resize.
- Alternate screen: full-screen programs switch to a second screen with no scrollback. Leaving it restores the primary screen and cursor exactly.
- Wrapping: printing in the last column leaves the cursor there, and the line wraps only when the next character arrives.
- Background color erase: clearing part of the screen fills it with the current background color.
- Wide characters take two columns. A wide character that doesn't fit at the end of a line wraps to the next one.
- Combining characters (accents, variation selectors) join the character before them. So do characters after a zero-width joiner, so emoji sequences such as 👩💻 stay one character.
- Variation selector 16 (U+FE0F), after a character that has an emoji
form one column wide, as ❤ or ✔ has, makes it two columns wide, as kitty
and Ghostty draw it: the cursor moves on a column more, over what was
there. In the last column, or at the right margin, with no room for it, the
selector is left out, and the character stays one column wide.
daemon.terminals.vs16 = falsein the daemon's config keeps it one column, for programs that count it so; each terminal keeps the rule it started with, through upgrades too, and one carried over from a build before the rule keeps the old one. A window older than protocol 147 gets each widened emoji's second column as a space, so what follows it stays in its column, whether the terminal is this machine's or one another machine's daemon passes on: a daemon makes the lines it passes on again for such a window, its history's too.
Supported sequences #
| Kind | Supported |
|---|---|
| Control characters | BS, HT, LF, VT, FF, CR, SO, SI. BEL is accepted and ignored. |
ESC | 7 8 (save/restore cursor), D (index), E (next line), H (set tab stop), M (reverse index), c (full reset), #8 (screen alignment test), ( and ) with B (ASCII) or 0 (DEC line drawing) |
CSI cursor | A B C D E F G H I Z ` a d e f, and s u without parameters (but s while DECLRMM is set: see margins) |
CSI editing | @ J (including 3J to clear scrollback) K L M P S T X b (repeat) |
CSI other | g (clear tab stops), r (scroll region), s with DECLRMM set (left and right margins), m (SGR), !p (soft reset), q (cursor shape: 0 the user's default, 1 and 2 block, 3 and 4 underline, 5 and 6 bar; blinking isn't drawn), t (window operations: 22 and 23 push and pop the title, with a second parameter of 0 or 2, ten titles deep, each kept to 4096 bytes; see queries for 18), >u <u =u (the kitty keyboard protocol) |
ESC keypad | = and > (application and numeric keypad) |
ANSI modes (CSI h/l) | 4 (insert), 20 (line feed is newline) |
DEC modes (CSI ? h/l) | 1 (application cursor keys), 6 (origin), 7 (autowrap), 25 (show cursor), 47, 1047 and 1049 (alternate screen), 66 (application keypad), 1048 (save cursor), 69 (left and right margins), 2004 (bracketed paste), 9, 1000, 1002 and 1003 (mouse tracking), 1005, 1006 and 1015 (mouse encodings), 1016 (the mouse in pixels, as 1006 but where the pointer is in pixels from the text area's top left; a drag is told at every pixel it moves, and the wheel at its cell's top left), 1004 (focus events), 2026 (synchronized output), 2027 (grapheme clusters), 2048 (resize reports) |
| SGR | Bold, dim, italic, blink, inverse, hidden, strikethrough, overline (53, drawn along the cell's top; a window older than protocol 147 draws none), and their resets (55 for the overline). Underlines: single, double (21 or 4:2), curly (4:3), dotted (4:4), dashed (4:5). 8, 16, 256 and 24-bit colors for text, background and underline (58), in both the ; and : spellings. |
OSC | 0 and 2 (window title, which names the tab and the window without control characters or those that show nothing but change what's around them, as the marks that turn text round and the line separators do; in the window's title, only its first 256 characters, set apart from the machine's name and anything clackatoo adds), 7 (working directory, as a file:// URL, which names a tab with no title; a path over 4096 bytes is ignored), 8 (hyperlinks, with id=; kept in history and through upgrades), 52 (clipboard: text a program copies goes to the window's clipboard or primary selection, as the window's osc52 option allows; reading it is refused unless allowed, with an empty answer), 133 (shell integration: A prompt, B where typing starts, C output, with an optional cmdline_url= (a command over 1024 bytes isn't kept) and clackatoo=, the secret clackatoo's own shell integration adds, which is checked and dropped, and D exit status, which marks a failed command's prompt line; see commands; the marks also say whether a background tab is running, and which signed command a terminal kept running runs again), 9;4 (progress), 9, 777 and 99 (notifications), 22 (pointer shapes), 46373 (secret regions: what a program marks hidden, never to be saved, or kept from agents) |
Queries answered #
| Query | Reply |
|---|---|
CSI c (primary device attributes) | CSI ? 62 ; 4 ; 22 c: a VT220 with sixel graphics and color |
CSI ? 1 ; 1 S, CSI ? 2 ; 1 S (XTSMGRAPHICS) | CSI ? 1 ; 0 ; 1024 S: 1024 sixel color registers; CSI ? 2 ; 0 ; 16384 ; 16384 S: the largest sixel image, in pixels. Setting them isn't supported (CSI ? Pi ; 3 ; 0 S). |
kitty graphics commands with an i or I (see images) | APC G i=<id> ; OK ST, with I=<number> and p=<placement> if the command had them, or APC G i=<id> ; <error> ST with one of a few fixed errors, such as ENOENT:no such image |
CSI 5 n (status) | CSI 0 n |
OSC 52 ; c ; ? (clipboard) | OSC 52 ; c ; <base64> ST, empty if refused or unanswered within 2 s, ended with BEL if the query was |
CSI 6 n and CSI ? 6 n (cursor position) | CSI <line> ; <col> R, with ? for the second form. Relative to the scroll region in origin mode. |
CSI > q (terminal version) | DCS > | clackatoo <version> ST |
CSI > c (secondary device attributes) | CSI > 1 ; <version> ; 0 c: a VT220, its version clackatoo's year and month, as 202611, as foot answers with its own. vim reads a number this high as a modern terminal's, not an old xterm's. |
CSI ? Ps $ p and CSI Ps $ p (DECRQM, is a mode set?) | CSI ? Ps ; Pm $ y, without the ? for an ANSI mode: Pm is 1 for set, 2 for reset, and 0 for a mode clackatoo doesn't know. Every mode in supported sequences is known, 2026 and 2027 included; 2027 is answered 4, can't be set, in a terminal carried over from a build before it, whose rows are laid out the old way. |
OSC 10 ; ?, OSC 11 ; ?, OSC 12 ; ? (the text's, background's, and cursor's colors) | OSC 11 ; rgb:1d1d/1f1f/2121 ST, ended with BEL if the question was. Several at once, as OSC 10 ; ? ; ?, are answered in turn. Neovim asks for the background as it starts, to choose its light or dark colors, as vim, bat and delta do. |
OSC 4 ; <index> ; ? (a palette entry, several pairs at once) | OSC 4 ; <index> ; rgb:… ST for each |
OSC 22 ; ? <names> ST (pointer shapes) | OSC 22 ; 1,0,… ST: whether each shape is known, and for __current__ the shape shown. Ended as asked. |
CSI ? u (kitty keyboard flags) | CSI ? <flags> u, the flags in effect |
CSI 18 t (text area size) | CSI 8 ; <lines> ; <columns> t. The sizes in pixels, the text area's (14t, as CSI 4 ; <height> ; <width> t) and a cell's (16t, as CSI 6 ; <height> ; <width> t), are answered once a window has said how big it draws a cell, as it does when it sizes the terminal; until then, not at all. Nor is the title read back (21t), which would let a program type what it set. |
DCS + q <names> ST (XTGETTCAP) | For each name, in hex: DCS 1 + r <name> = <value> ST, the value in hex, or without = for a boolean; DCS 0 + r <name> ST for one clackatoo doesn't say, the name said back only if it's hex, and DCS 0 + r ST otherwise: no answer ever says back what a program printed, which could have it type anything into the shell. It says xterm-256color's name (TN) and colors (Co), 24-bit color (RGB, Tc, setrgbf, setrgbb), styled and colored underlines (Su, Smulx, Setulc), overlines (Smol, Rmol), the clipboard (Ms), the cursor's shape (Ss, Se), synchronized output (Sync), bracketed paste (BE, BD, PS, PE), focus events (fe, fd, kxIN, kxOUT) and XT. At most 64 names a request, and a request over 1024 bytes isn't answered. |
DCS $ q <setting> ST (DECRQSS) | DCS 1 $ r <sequence> ST, the sequence that sets the setting as it is, for the pen (m, as 0;1;38:5:1m), the cursor's shape ( q, steady, or 0 for your own), the scroll region (r) and the left and right margins (s); DCS 0 $ r ST for any other. |
The colors are those the window draws terminals in, which it tells the daemon as it connects, so the daemon answers at once, as programs wait only a moment. Every terminal answers with those of the window that told it last, and the daemon tells those on other machines it's connected to. Until a window has told it, as with a window older than protocol 139, these questions aren't answered, and programs keep their defaults.
A program that asks faster than it reads the answers, as one at the far end of an ssh connection that has stopped reading can, gets no more once 64 KiB of answers and input wait for it. Answers are dropped whole, never cut, and what you type still goes in. The clipboard's answers go the same way, and so do answers to a program still reading a long paste: it gets none until it has read most of it.
Keyboard #
Keys are sent as xterm sends them, which nearly every program understands, until a program asks for the kitty keyboard protocol (https://sw.kovidgoyal.net/kitty/keyboard-protocol/), as fish 4, Neovim, Helix and Kakoune do. xterm's encoding can't tell some keys apart: Esc from the start of a sequence, Ctrl+I from Tab, Shift+Enter from Enter. The protocol sends those as sequences of their own.
A program asks a flag at a time:
| Flag | What changes |
|---|---|
| 1 (disambiguate) | Esc, and keys with Ctrl, Alt or Super, are sent as CSI <key> ; <modifiers> u. Enter, Tab and Backspace with no modifiers are sent as they are without the flag, so a shell a program left with the flag on can still be typed reset into. Text typed with or without Shift is text. |
| 2 (key events) | A key held down is sent again as a repeat, and one let go as a release: CSI <key> ; <modifiers>:2 u and :3, or in the key's own form, as CSI 1;1:3A for Up let go. Only for keys sent as sequences: text typed is sent again as it repeats, and says nothing as it's let go, and so do Enter, Tab and Backspace without flag 8. A key whose press the program heard is told as it comes up, whatever the pane's mode by then, and as the window loses the focus; a key held repeats only into the pane it went down in, and one a macro or a binding types is a press alone. |
| 4 (alternate keys) | Those sequences also say the key Shift made, and the key in a US layout, as CSI 97:65;2u. |
| 8 (all keys) | Every key is a sequence, text and all. |
| 16 (text) | With 8, each sequence also says the text its key types. |
Super is a modifier, 8, as the protocol numbers it. Hyper and Meta aren't sent: the window can't tell them from the others, nor are Caps Lock and Num Lock, or modifier keys pressed alone. The keypad's keys have numbers of their own, but type their text without Ctrl, Alt or Super. A window older than protocol 147 sends no repeats or releases, and the program is told flag 2 isn't set.
A program pushes the flags it wants (CSI > flags u) and pops them as it ends
(CSI < count u), leaving what was there before; CSI = flags ; mode u sets
(1), adds (2) or takes away (3) flags in effect. Each screen keeps a stack of
its own, sixteen deep, so a full-screen program leaves the shell's alone, and
a full reset (ESC c) ends them all. A program switching to the alternate
screen starts with none, whatever one before it left there, and the shell's
next prompt (OSC 133 A) drops what a program left on the primary screen, so
a program that dies with the protocol on doesn't leave
Ctrl+C reaching the shell as CSI 99;5u: a shell that
wants it, as fish 4 does, asks again after its prompt. They, the titles
pushed, and a program's progress go on through an upgrade in place. The window
encodes keys this way; the web app on your phone sends xterm's encoding still.
A window older than protocol 139 does too, which programs that ask still
understand.
Pointer shapes #
A program can choose the mouse pointer's shape over its terminal with kitty's
OSC 22 (https://sw.kovidgoyal.net/kitty/pointer-shapes/), as a link or a
divider in it would want: OSC 22 ; pointer ST sets it, by its CSS name
(text, pointer, crosshair, grab, ew-resize and the rest) or an X11
one kitty reads (xterm, hand2, left_ptr…); OSC 22 ; > name,fallback ST pushes the first known of a list, and OSC 22 ; < ST pops it. A name
clackatoo doesn't know changes nothing, and none shows the arrow, as a
program can't hide the pointer. The window shows it while the pointer is over
the terminal's live screen, ahead of the arrow a program that takes the mouse
gets; scrolled back, the pointer is clackatoo's again. Each screen keeps its
own, so a full-screen program's goes with it, and the shell's next prompt
(OSC 133 A) or a reset takes back what a program left. An upgrade in place
forgets it; a window older than protocol 147 shows its own.
Left and right margins #
A program that sets DECLRMM (CSI ? 69 h), as some editors and multiplexers
do to scroll part of a screen, can set left and right margins with DECSLRM,
CSI <left> ; <right> s, columns counted from 1. While it's set, CSI s
sets the margins rather than saving the cursor, as in xterm. Within them:
- Text wraps at the right margin to the left one, and a carriage return goes to the left one.
- The cursor stops at a margin moving across it, as at the scroll region's top and bottom.
- Scrolling, a line feed at the bottom of the scroll region, and inserting or deleting lines and characters move only what's between the margins, in the scroll region's lines; never into history. Outside the margins, a line feed moves the cursor on without scrolling, and editing does nothing.
- In origin mode, columns count from the left margin, as lines count from the scroll region's top.
Setting margins puts the cursor home. Resetting DECLRMM, a soft or full reset, and a resize put them back at the screen's edges. They go on through an upgrade in place.
Grapheme clusters #
By default, as in xterm, each character takes its own columns, and only a
zero-width one, or one after a zero-width joiner, joins the cell before it, as
programs counting widths with wcwidth expect. A program that counts by
grapheme clusters, what Unicode's segmentation (UAX #29) says reads as one
character, asks for mode 2027 (CSI ? 2027 h), as in Contour, WezTerm and
Ghostty. Then a cluster takes one cell: a letter and its spacing mark (कि), an
emoji and its skin tone (☝🏽), a flag's two halves (🇬🇧), a Hangul syllable
written in jamo. A cluster is as wide as its first character, but a flag, an
emoji with a skin tone, or one with variation selector 16
takes two columns. CSI ? 2027 $ p says whether it's on. A reset, soft or
full, turns it off.
What's printed either way stays as it was printed: rows are laid out again, in history, after a resize, through an upgrade and in every window, by the same rules, with what was printed side by side with the mode off kept apart. Selecting, searching and copying go by cells, so a cluster is one character to them. A cluster that would widen in the last column, or at the right margin, with no room there, is cut where it would widen: its next character starts a cell of its own.
Resize reports #
A program that asks with mode 2048 (CSI ? 2048 h), as Neovim and
notcurses can, is told the terminal's size in-band, in its input, as soon as
it asks and after every resize: CSI 48 ; <lines> ; <columns> ; <height> ; <width> t, the last two the text area in pixels, or 0 while no window has
said how big it draws a cell. It needn't wait for SIGWINCH, which can come
before the terminal is redrawn at its new size. The window sizing the terminal
says how big it draws a cell, so a bigger font is a resize too, in pixels;
the kernel's window size has the pixels too, as TIOCGWINSZ reads it. A
phone fitting a terminal leaves the pixels as the window said them. The mode
goes on through an upgrade in place; the size in pixels comes back with the
window's next resize.
Synchronized output #
A program that draws its screen in pieces can say it's drawing a frame
(CSI ? 2026 h) and that it's done (CSI ? 2026 l), as Neovim, Helix, tmux
and programs built on crossterm do. Meanwhile, the daemon sends windows
nothing of that terminal, and what changed goes out whole once the frame is
drawn, so you never see half a redraw. A frame that takes longer than 150 ms
is shown as far as it got, and nothing more is held back until the program
starts another, so a program that never says it's done only looks slow.
Progress #
A program can say how far a long task has got with
OSC 9 ; 4 ; <state> ; <percent> ST, as ConEmu began it and Windows Terminal,
Ghostty, kitty and WezTerm show it: state 1 is under way at a percent, 2
failed, 3 busy with no telling how far, 4 paused, and 0 done. The tab it's in
ends its name with 42%, ✗ (and the percent, if given) failed, … busy,
or ‖ paused: the focused pane's, or else the first of the tab's panes to
say, in a tab shown or not. It goes once the program says it's done (state 0),
or once the shell's next prompt shows the program has ended (OSC 133 A). Any
other OSC 9 is iTerm2's notification.
Notifications #
A program can ask for a desktop notification, as a build or a long command does when it ends, in any of the three ways terminals read:
| Sequence | What it says |
|---|---|
OSC 9 ; <text> ST | iTerm2's: a line, with no title. ConEmu's numbered commands, whose first part is a number, aren't notifications. |
OSC 777 ; notify ; <title> ; <body> ST | urxvt's, as foot and Ghostty read it. |
OSC 99 ; <metadata> ; <payload> ST | kitty's (https://sw.kovidgoyal.net/kitty/desktop-notifications/). The metadata is key=value pairs separated by :: p=title (as when it's left out) or p=body says which the payload is, d=0 that more of it comes in the next, e=1 that it's base64, u=0, 1 or 2 how urgent it is, and i=<id> names it, so that p=close with the same id takes it back. Buttons, icons, sounds and the rest are left out. |
A window shows it while you aren't looking at the program's pane: it's in a
tab not shown, or the window doesn't have the focus. Its title always starts
with what the terminal is called, so a program can't pass for another: the
tab's name if you gave it one, or else the pane's (the title its program set,
or its folder), as cargo — Build done; with no title of its own, it's that
name alone. The phone titles it the same way. It goes once you look, as
the program asks, or as the program ends, and clicking it goes to the pane. It
isn't sent at all while someone whose window has the focus, or whose phone
shows the terminal, is looking at it. A low urgency (u=0) is shown as such;
a critical one (u=2) as a normal one, since critical ones break through Do
Not Disturb. :set notify=off turns them off with chats', as the
notify option says.
:notify phone marks the focused terminal to have its notifications reach the
phone too, and :notify nophone
takes the mark away. A tab with a terminal so marked ends its name with
📱. The mark goes on through an upgrade in place and a restart, as :keep
does.
What a program says is cleaned as tab names are: control characters become
spaces, what shows nothing but changes what's around it goes, runs of spaces
become one, and a title is cut to 120 characters, a line to 300. A terminal
shows three at once, then one every ten seconds; one asking more often is
heard only as often, and so is one on another machine, whatever its daemon
passes on. However many terminals ask, at most ten notifications are shown in
a minute; the rest are told together as the minute ends, as 4 more notifications, and reach the phone if one of them would have. Nothing is ever said back to the program: kitty's
questions about what's supported (p=?), and its reports of a notification
clicked or closed, get no answer.
Long commands #
A command that ran for 10 seconds or more says so as it ends, in the same way
and to the same places as a program's notifications, while no one is looking
at its terminal: the command, how it ended, and how long it took, as
cargo build and failed (exit 101) after 2m14s. The command is named only
when clackatoo's own shell integration said it, signed; otherwise it's
A command. Its end is believed only once the shell has the terminal to
itself again, as with an agent's wait for a command, so a program printing
the marks of an end (OSC 133 D) while it runs on says nothing. Terminals an
agent started, and those showing what an agent's command printed, never say.
daemon.terminals.notify_after
in the daemon's config changes the 10 seconds, or with 0, turns it off.
Images #
Programs show images in a terminal in three ways, all of them kept and drawn through clackatoo's one image layer, the same as the images in chats, Markdown and image panes:
- kitty's graphics protocol (
APC G … ST), askitten icat, yazi, ranger, timg and chafa use it: transmitting an image by an ID or a number (i,I), in parts (m=1) or whole, as RGB, RGBA or PNG (f=24,32,100), compressed with zlib or not (o=z); showing it (a=T,a=p) at the cursor, all of it or a part (x,y,w,h), over some columns and rows (c,r), from a point in its first cell (X,Y), above the text or below it (z), the cursor moving past it or staying (C=1); deleting what's shown and kept (a=d, everyd=but animation frames'), and answering, unless told to keep quiet (q=1,q=2). Asking whether an image could be shown (a=q) is answered too, so programs find out images work. - kitty's Unicode placeholders: a virtual placement (
U=1), then U+10EEEE printed where the image goes, its colour naming the image, its underline's colour the placement, and its marks the row and column. They're text, so they scroll, wrap, split and go through tmux as text does. - sixel (
DCS q … ST), as img2sixel, chafa and notcurses send it, answering4among the device attributes. Its pixels nothing paints are see-through, and its pixels are square, as every encoder in use sends them. An image whose data paints its pixels more than 16 times over, as data cheap to send and slow to draw would, isn't shown. - iTerm2's inline images (
OSC 1337 ; File=… : <base64> ST), asimgcatsends them: PNG, JPEG, GIF and WebP,inline=1, at awidthandheightin cells, pixels (px), a share of the terminal (%) orauto, in proportion unlesspreserveAspectRatio=0, anddoNotMoveCursor=1.
An image sits on the rows it covers: it scrolls with them into history and
back, is kept with them through an upgrade, and
goes once they leave history. Text printed over it doesn't take it away, as in
kitty; clearing the screen (CSI 2 J, as clear does), a reset and
switching screens do. Each cell takes the image's part that covers it, so
copying text over an image, and what an agent reads of the terminal, says it
once, as [image 640×480], where it starts, and a placeholder's cells give no
text. A selection shows over an image. The cursor goes after a kitty or iTerm2
image, on its last row; after a sixel image, to the line below it, where it
started. Until a window has said how big it draws a cell, a cell is taken as
10 by 20 pixels.
A terminal waits while its image is kept, which a big image or a slow file
can take a moment for: its output is held, and read again once it's kept.
It waits 10 seconds at most, a file's wait for its turn to be read included,
then goes on without the image. Terminals' images are kept on threads of
their own, so one slow to keep holds up neither chats' images nor what
windows and phones fetch. While an image is being sent, what's come of it
counts against the limit for all images, and one sent in parts whose last
part hasn't come in 30 seconds is given up on. An
image is kept by the daemon of the terminal's machine, as sent: a PNG stays a
PNG, and pixels sent bare are kept as one. Each terminal keeps its images
within the limits: past them, the image
shown least lately that isn't on the screen is let go, and its place says
[image dropped: over the 64 MB limit]; an image over the limit by itself
isn't kept, and kitty's command is answered EFBIG. An image on the screen,
or one a Unicode placeholder on the screen shows, is never let go, so a
program whose screen shows more than the limit can't show another until some
scroll off.
Files and shared memory #
kitty's commands may name where the image is instead of sending it: a file
(t=f), a temporary file (t=t), or POSIX shared memory (t=s). The
daemon whose terminal it is reads it, so a terminal on another machine reads
that machine's files, off its loop and in time (10 seconds), through a link
at the path's end as kitty does, but never a pipe, a device, or anything under
/proc, /sys or /dev (shared memory, under /dev/shm, aside), and never
more than the limit for an image. Every failure says the same,
EBADF:Failed to read image file, so a program can't find out what files
there are, though one could still tell whether a file is an image clackatoo
shows. A temporary file is taken away once it's read only if its name holds
tty-graphics-protocol and it's in /tmp, /dev/shm or the daemon's own
folder for temporary files, reached through no link; it's read and taken away
through that folder, so they're the same file. Shared memory is taken away
once read, as kitty does, whoever made it. Either is left where it is if what
was read doesn't look like the image it's said to be: a PNG that doesn't start
as one, say, or too few pixels.
Since a program anywhere you ssh to can ask for a file on your own machine,
as in kitty, only the image is ever shown, to you, and never its bytes said
back.
Answers #
Answers are made of fixed words and numbers clackatoo read itself, never
anything a program sent, so a file that's cat-ed can't type into the shell
with them. A command with neither i nor I gets no answer, and a command
that looks like an answer, as one a program prints back without reading it,
is never one, so it can't answer itself for ever.
Not done #
- Animation (
a=f,a=a,a=c): an animated image shows its first frame, and animation commands are answeredEINVAL. - A placement relative to another (
P,Q), answeredEINVAL. - iTerm2's
MultipartFile, and files that aren'tinline=1, which iTerm2 downloads. - Sixel's display mode (DECSDM, mode 80), and pixels that aren't square.
- Images in a terminal kept across a restart: its history comes back, each image its size in words where it was.
- Recordings keep what was printed, byte for byte, so an image sent in the terminal's output plays back, and one named by a file or shared memory plays back as unreadable.
- Images are drawn only by windows and phones of protocol 150 or later: an older one, or one through an older daemon, shows what's under them.
Not supported #
These are ignored:
- Setting colors:
OSC 4,10,11,12,104, and the others. Asking about them is answered. - Hyper and Meta as modifiers.