The Widget in Use
What the user of a program that embeds the widget can do in the terminal, and what the widget shows: its keys, the mouse, the menu, search, links, the keyboard selection, and the way it draws the screen. A host gets all of this by embedding the widget; it can also offer the same actions from its own menus (see Embedding the Widget).
1. Keys
Every key goes to the program, except the few below. A key with Alt held is never one of the widget's own: it goes to the program. The only exceptions are the bars of sections 4 to 7: while one of them is open it takes the keys first, and in the search bar Alt+C and Alt+R are its own. When the user types or pastes, the view goes back to the screen's last lines and the cursor shows.
| Key | What it does |
|---|---|
Ctrl+Shift+C |
Copies the selection to the clipboard. |
Ctrl+Shift+V |
Pastes the clipboard. |
Shift+Insert |
Pastes the PRIMARY selection. |
Ctrl+Shift+F |
Opens the search bar, or closes it (section 4). |
Ctrl+Shift+Space |
Starts the selection with the keyboard (section 5). |
Ctrl+Shift+O |
Puts a letter on each link in view, to open one with a key (section 6). |
Ctrl+Shift+Up, Ctrl+Shift+Down |
Shows the prompt above or below the first line in view, with shell integration. Down past the last prompt goes back to the screen's last lines. Not on the alternate screen. |
Shift+Page Up, Shift+Page Down |
Moves the view one page (the screen's rows less one) through the scrollback. |
Ctrl+Plus (or Ctrl+=, or Control and the keypad's plus) |
Makes the font one pixel larger, up to 72 pixels. |
Ctrl+Minus (or Control and the keypad's minus) |
Makes the font one pixel smaller, down to 6 pixels. |
Ctrl+0 |
Gives the font the size the theme says again. |
Ctrl+Break |
Sends the answerback message (answerback in the theme), as the key of a VT100 does. |
The three font size keys are the widget's only while the program has not asked for modifyOtherKeys: a program that did gets them, as they then say what they are. Ctrl+Shift+Minus is never a font size key: it is Control+_, a control code. A new font size changes the size of the terminal in characters, and the program is told.
The widget reads keys through the host's input method, so text typed with an input method arrives whole. Keys that type no text and are not keys of their own (a modifier key alone) send nothing, unless the program asked for the Kitty keyboard protocol. A key that goes up is sent only to a program that asked for it in that protocol. What each key sends is on the page Keyboard, Mouse and Paste.
2. The mouse
| Mouse | What it does |
|---|---|
| Drag with the left button | Selects characters. Two clicks select words (a word is a run of characters with no space) and three select lines; the clicks must be in the same cell and within 400 milliseconds. When the button goes up, the selection is the PRIMARY selection. |
| Control and a drag | Selects a rectangle of cells. (Alt and a drag is the window manager's: it moves the window.) |
| Control and a click | Opens the link under the pointer: the host's link callback gets it when the button goes up with no drag. |
| Control and the pointer over a link | The link takes the theme's link color and is underlined, to show that a click opens it. |
| A drag past the top or bottom of the view | Moves the view one line at once, and one more every 0.05 seconds while the pointer stays there; the selection goes with it. |
| A click on a prompt's mark in the margin | Selects the output of that command, which then is the PRIMARY selection too. Two clicks hide or show the output, for a command that ended and wrote something. A third quick click does nothing. |
| Middle button | Pastes the PRIMARY selection. |
| Right button | Opens the menu (section 3). |
| Wheel | Moves the view three lines through the scrollback. On the alternate screen, where a full-screen program runs, there is no scrollback: when the program set alternate scroll mode (mode 1007) each step sends three Up or Down keys, and if not the wheel does nothing. |
A click in the terminal gives it the keyboard. When a program asked for mouse reports (vim, htop, mc), the buttons, the wheel and the motion go to the program, and none of the above happens; hold Shift to select, paste or open the menu as usual. When a program switched on the DEC locator, the left, middle and right buttons go to it in the same way.
3. The menu
The right mouse button opens a menu. The items that need a selection, a link or a command at the place of the click are grey without one. A host can add its own items below the widget's.
| Item | What it does |
|---|---|
Copy (Ctrl+Shift+C) |
Copies the selection to the clipboard. Grey with no selection. |
| Copy as HTML | Copies the selection as HTML: a pre element with the text's colors, bold, italic, underline and strike, to paste into a document or a mail. Grey with no selection or with a rectangle selection. |
Paste (Ctrl+Shift+V) |
Pastes the clipboard. |
| Select All | Selects the scrollback and the screen (on the alternate screen, which has no scrollback, the screen only). The selection is the PRIMARY selection too. |
Find... (Ctrl+Shift+F) |
Opens the search bar. |
| Open Link | Opens the link under the click. Grey when there is none, or when the host has no link callback. |
| Copy Link | Copies the link's address, or the file name without its line and column, to the clipboard. |
| Copy Command Output | Copies the output of the command whose lines the click is on (shell integration). Grey when the click is not on a command's lines, or the command wrote nothing. |
| Hide or Show Command Output | Hides that output, or shows it again. Grey unless the command ended. |
| Larger Text, Smaller Text, Normal Text Size | What the font size keys do (Ctrl++, Ctrl+-, Ctrl+0). The items work also while a program has asked for modifyOtherKeys and so gets those keys. |
| Clear Scrollback | Removes the lines of the scrollback. Grey when there are none. |
| Reset Terminal | Puts the terminal in the state it had at its start, as RIS does: modes, colors, character sets, margins and the two screens. The scrollback stays; the selection and a job's progress bar go. Use it after a program left the terminal in a strange state. |
4. Search
Ctrl+Shift+F opens the search bar over the view's last line. Type the text: each change looks for it again from the newest line back. Every match on the lines in view is marked in the theme's search-match colors, and the match the search is at in the search-current colors; the view moves to show it. The search goes through the scrollback and the screen, and starts again at the other end when it reaches one. A line that continues on the next row is one line of text for the search, so a match can go over the end of such a row; a match never goes over a real line end. The bar says "(not found)" when there is no match.
| Key in the search bar | What it does |
|---|---|
Enter |
Goes to the match before (older). |
Shift+Enter |
Goes to the match after (newer). |
Alt+C |
Makes upper and lower case different, or the same again. The bar shows [Aa] while they are different. |
Alt+R |
Makes the text a pattern (a POSIX extended regular expression), or plain text again. The bar shows [.*] while it is a pattern. |
Backspace |
Removes the last character of the text. |
Escape, Ctrl+Shift+F |
Closes the search bar. |
After Alt+C or Alt+R the search starts again from the newest line. Other keys without Control do nothing while the bar is open. Keys with Control keep their usual meaning: the widget's own keys work, and the others go to the program. The text can be up to 255 bytes long. With plain text and case not different, only the letters A to Z match their small letters; a pattern without case uses the system's rules for letters. A pattern that is not correct finds nothing, and a match of no characters is not a match. At most 32 matches are marked on one line.
5. Selection with the keyboard
Ctrl+Shift+Space puts an outline, in the cursor's color, on the cell of the cursor, and a bar over the last line names the keys. Each key is the mode's until it ends:
| Key | What it does |
|---|---|
Arrows, or h j k l |
Move one cell or one line. |
w, b |
To the start of the next word, or of this word (of the word in front). |
0 or Home, $ or End |
To the line's first column, or its last character. |
g, G |
To the first line of the scrollback, or the screen's last line. |
Page Up, Page Down |
Up or down by the screen's rows less two. |
v, V |
Starts a selection here, by characters (v) or by lines (V). While a selection is started, v or V drops it. |
y, Enter |
Copies the selection to the clipboard and to PRIMARY, and ends. With no selection it only ends. |
Escape, q |
Ends without copying. |
Other keys do nothing while the mode is on. The view follows the outline. When the mode ends, the selection is dropped and the view goes back to the screen's last lines.
6. Opening a link with a key
Ctrl+Shift+O puts a letter on the first cell of each link in view, in the colors of the search's current match: a to z, then A to Z, so at most 52 links. Type a link's letter to open it (the host's link callback gets it; with no callback the letter only closes the letters). Any other key closes the letters; a modifier key alone does not. The view's last line, where the bar is, gets no letters; the bar says "No link in view" when there are none.
A link is a hyperlink a program made (OSC 8), an address with a scheme and :// (for example https://... or file://...; the scheme is letters, digits, + and -), a mail address after mailto:, or a file name. A file name is a word with at least one letter that has a directory, an extension or a line number: main.c, src/main.c:120 or src/main.c:120:8. Such a word ends at a space, a quote, <, >, `, |, ;, a comma or a bracket, and a full stop or a colon at its end is not part of the name. A full stop, a comma, ;, :, ! or ? at the end of an address belongs to the sentence, not the address, and so does a closing bracket that has no opening bracket in the address. A line that continues on the next row is one line, so an address can go over the end of a row. A hyperlink a program made has a dotted underline in the theme's link color, unless the program gave the text an underline of its own.
7. Paste
Pasted text is made safe before the program gets it: each line end (a line feed, or a carriage return and a line feed) becomes a carriage return, and control characters other than tab and carriage return are removed (DEL and the C1 controls too), so a paste cannot send an escape sequence. The middle button, Shift+Insert, Ctrl+Shift+V and the menu's Paste all paste in this way. When the program asked for bracketed paste (a modern shell does), the text goes between the paste marks, and the program knows it was pasted.
A paste that can run a command (text with a line end and more text after it) to a program that does not mark pastes asks first. A bar over the last line says how many lines it has (a line ends in a line feed, a carriage return and a line feed, or a carriage return alone): Enter pastes, Escape does not, and other keys wait. paste-confirm = 0 in the theme turns the question off.
8. The scrollback view
Lines that scroll off the top of the screen go to the scrollback, up to the theme's scrollback-lines (10000 when the theme does not say). The wheel, Shift+Page Up, the scrollbar and the prompt keys show older lines. While old lines are in view, new output does not move them: the view stays on what the user reads. Typing goes back to the screen's last lines. A program on the alternate screen has no scrollback. A change between the two screens drops the selection and the search's match, and the view goes back to the screen's last lines; a change of the terminal's size in characters drops the selection and the match too, as the lines move. A new scrollback-lines in the theme keeps the newest lines.
A command's hidden output takes no lines: the prompt's line says at its right end how many lines are hidden (... 12 lines, in the theme's fold color), and its mark in the margin is hollow.
9. What the widget shows
- The cursor is a block, an underline or a bar, as the theme or the program (DECSCUSR) says, and blinks when either says so (0.6 seconds on, 0.6 off). Without the keyboard, a block is an outline, and no cursor blinks. A block shows its character in the theme's
cursor-textcolor, or in the cell's background. A bar is as tall as the font's letters, and an underline sits at their bottom, without the space between lines; both are about as thick as a stroke of a letter. A program can hide the cursor. - Text is drawn in four faces of the theme's font: regular, bold, italic, bold italic. A face the font does not have is the regular one. A character the font lacks is drawn from another font that has it, emoji in color when a color emoji font is installed. Runs of text are shaped: Arabic letters get their joined forms, and a programming font's ligatures (
->as an arrow) are drawn unless the theme hasligatures = 0. Each character stays in its cell, so joined letters of a font that is not monospaced can have small gaps. - Right-to-left text (Hebrew, Arabic) is shown in its reading order by the Unicode Bidirectional Algorithm, unless the program switched that off (
CSI 8 l). With mode 2501 a line that starts with such text goes from the right edge. - Colors come from the theme and the program. Reverse video (DECSCNM) exchanges only the default colors. Faint text with no color of the theme's is drawn halfway to its background, and invisible text in its background. With
bold-bright = 1, bold text in colors 0 to 7 is drawn in 8 to 15. Withminimum-contrastabove 1, text that has too little contrast to its background is made lighter or darker until it has enough. The selection is drawn in the theme'sselectioncolors, or in the colors a program set for it (OSC 17 and 19). The theme's rules give a style to text a pattern finds (see Themes). - Underlines in every style (single, double, curly, dotted, dashed), in their own color when the program gave one; strike and overline lines. Blinking text blinks with the cursor's period.
- Lines of double width and double height are drawn with the font made two times wider, or wider and taller. Such a line shows its characters only: no underline, strike, overline or picture, and no right-to-left order.
- 80 or 132 columns. A program that is permitted to choose the width (mode 40) keeps the width it chose (DECCOLM), whatever the window's size; the part that does not fit is not seen. When it gives the choice back, the width fits the window again.
- The margin (
gutter-widthpixels on the left) shows a mark beside each prompt, in the color of its command's result (prompt-success,prompt-failure, orprompt-markwhile it runs). A prompt's line and the output of a failed command can have backgrounds of their own (prompt-line,output-failure). - Pictures a program sends are drawn in the cells they cover (see Pictures), and a theme can put a picture behind all the text (
background-image): it covers the view and keeps its shape, and the background color covers it as much asbackground-opacitysays. That picture file is read in the jailed worker too, as a theme can come from anyone. - The bell is a sound, a frame in the cursor's color at the view's edge for 0.15 seconds, both, or nothing, as the theme's
bellsays. - A job's progress (OSC 9;4) is a bar two pixels high at the top of the view: in the
prompt-successcolor, inprompt-failurefor an error, and inprompt-markfor a job that waits. A job with no known end, or an error with no number, fills the whole bar. - The status line a program asks for (DECSSDT) takes a row below the screen. The terminal's own indicator line has the view's colors exchanged and shows the cursor's row and column and the words Insert, Printer, Auto print and Alternate while those modes are on.
- The pointer takes the shape a program names (OSC 22):
textorxterm,pointerorhand,crosshair,waitorprogress,move,help,not-allowed,ew-resize,ns-resize,left_ptrordefault. Another name gives the host's own pointer again. - Synchronized output. While a program holds the paint back (mode 2026) to draw a whole frame, the widget does not paint, for one second at most.
- Local echo. When a program resets SRM (
CSI 12 l), the widget shows what the user types itself.
Hosho API
The whole library
From bytes to a screen
For the host that shows it
The program