Table of Contents
- hosho_terminal.h
- Types
- HoshoMode
- HoshoCursorShape
- HOSHO_CLIPBOARD_READ and the other values
- HOSHO_LED_NUM_LOCK and the other values
- HoshoKeySet
- HOSHO_KITTY_DISAMBIGUATE and the other values
- HoshoKittyImage
- HoshoPointerEvent
- HoshoWindowFunction
- HoshoWindowReport
- HoshoShellState
- HoshoTerminalHost
- HoshoSavedCursor
- HoshoTerminal
- Constants
- Functions
- hosho_terminal_create
- hosho_terminal_destroy
- hosho_terminal_feed
- hosho_terminal_typed
- hosho_terminal_shell_forget
- hosho_terminal_shell_state
- hosho_terminal_resize
- hosho_terminal_reset
- hosho_terminal_mode
- hosho_terminal_set_default_colors
- hosho_terminal_set_default_cursor
- hosho_terminal_set_cell_size
- hosho_terminal_set_clipboard_access
- hosho_terminal_set_default_keyboard
- hosho_terminal_set_default_key_set
- hosho_terminal_kitty_flags
- hosho_terminal_set_answerback
- hosho_terminal_set_window_access
- hosho_terminal_status_line
- hosho_terminal_pointer
- hosho_terminal_user_key
- hosho_terminal_clipboard_reply
- hosho_terminal_set_palette_color
- hosho_terminal_color
hosho_terminal.h
Terminal: What Each Control Function Does.
Copyright (c) 2016-2026 Michael Grey (liquibyte) liquibyte@gmail.com SPDX-License-Identifier: Artistic-2.0 Distributed under the Artistic License 2.0; see LICENSE for terms.
Joins the parser and the screen. It takes the bytes a program writes, and keeps the screen, the cursor, the modes, the colors and the title as that program expects from an xterm-compatible terminal. It has no display and no keyboard: a host draws the screen and sends the keys.
Features:
- Cursor movement, tab stops, scroll region, origin mode, autowrap
- Erase, insert and delete of characters, lines and columns; selective erase
- SGR: 16, 256 and direct colors, bold, faint, italic, underline styles, blink, inverse, invisible, strike, overline
- Alternate screen (modes 47, 1047, 1049), saved cursor
- Left and right margins (DECSLRM), rectangle functions (DECCRA, DECFRA, DECERA, DECSERA, DECCARA, DECRARA, DECRQCRA), protected cells (DECSCA, SPA, EPA), double-width and double-height lines, 132 columns (DECCOLM)
- DEC Special Graphics, DEC Supplemental, DEC Technical and the national replacement character sets
- Pictures: sixel, iTerm2's inline images (OSC 1337) and the Kitty graphics protocol (APC G)
- Hyperlinks (OSC 8), the shell's directory (OSC 7), the clipboard when the host permits it (OSC 52), the title stack
- Every picture a program sends can be taken apart by the host instead (image_decode, sixel_decode, inflate): a host can do that in a jail, as the data can be hostile
- Key modes a host's input encoder reads: modifyOtherKeys, the Kitty keyboard protocol's flags, the function keys' set, user-defined keys (DECUDK)
- Reports: device attributes, cursor position, mode state, settings (DECRQSS), terminfo capabilities (XTGETTCAP), text area size, checksums
- Window title, icon name, palette and default colors (OSC 0, 1, 2, 4, 10 to 19, 104, 110 to 119)
- Shell integration (OSC 133): the lines where a prompt and a command's output start are marked, and a prompt line gets its command's result
- Notifications (OSC 9, 777, 99), a job's progress (OSC 9;4), a pointer shape (OSC 22)
- The status line (DECSSDT), printing (MC), the DEC locator, the window functions (XTWINOPS) when the host permits them, VT52 mode
- Modes a host reads to encode its input: application cursor keys and keypad, mouse reports, focus reports, bracketed paste
Internal design notes:
- The functions and their meaning come from ECMA-48, the DEC VT manuals and xterm's ctlseqs
- wrap_pending is the VT100 "last column flag": a character in the last column leaves the cursor there, and the wrap is done when the next character comes
- A sequence the terminal does not know is ignored
#include "hosho_terminal.h"
Types: HoshoMode, HoshoCursorShape, HOSHO_CLIPBOARD_READ and the other values, HOSHO_LED_NUM_LOCK and the other values, HoshoKeySet, HOSHO_KITTY_DISAMBIGUATE and the other values, HoshoKittyImage, HoshoPointerEvent, HoshoWindowFunction, HoshoWindowReport, HoshoShellState, HoshoTerminalHost, HoshoSavedCursor, HoshoTerminal
Constants: HOSHO_KITTY_IMAGE_LIMIT, HOSHO_KITTY_STACK_LIMIT, HOSHO_USER_KEY_LIMIT, HOSHO_TITLE_STACK_LIMIT
Functions: hosho_terminal_create, hosho_terminal_destroy, hosho_terminal_feed, hosho_terminal_typed, hosho_terminal_shell_forget, hosho_terminal_shell_state, hosho_terminal_resize, hosho_terminal_reset, hosho_terminal_mode, hosho_terminal_set_default_colors, hosho_terminal_set_default_cursor, hosho_terminal_set_cell_size, hosho_terminal_set_clipboard_access, hosho_terminal_set_default_keyboard, hosho_terminal_set_default_key_set, hosho_terminal_kitty_flags, hosho_terminal_set_answerback, hosho_terminal_set_window_access, hosho_terminal_status_line, hosho_terminal_pointer, hosho_terminal_user_key, hosho_terminal_clipboard_reply, hosho_terminal_set_palette_color, hosho_terminal_color
Types
HoshoMode
The modes a program can set and a host can read with hosho_terminal_mode().
| Name | Value | Description |
|---|---|---|
HOSHO_MODE_INSERT |
IRM: a character pushes the rest of the line right. | |
HOSHO_MODE_NEWLINE |
LNM: line feed also goes to the first column. | |
HOSHO_MODE_CURSOR_KEYS_APPLICATION |
DECCKM: cursor keys send ESC O x, not ESC [ x. | |
HOSHO_MODE_REVERSE_VIDEO |
DECSCNM: the default colors are exchanged. | |
HOSHO_MODE_ORIGIN |
DECOM: rows count from the top of the scroll region. | |
HOSHO_MODE_AUTOWRAP |
DECAWM: a full line continues on the next. | |
HOSHO_MODE_CURSOR_BLINK |
the cursor blinks | |
HOSHO_MODE_CURSOR_VISIBLE |
DECTCEM: the cursor is shown. | |
HOSHO_MODE_KEYPAD_APPLICATION |
DECKPAM: the keypad sends application sequences. | |
HOSHO_MODE_ALTERNATE_SCREEN |
the alternate buffer is in use | |
HOSHO_MODE_MOUSE_X10 |
report a mouse button press (mode 9) | |
HOSHO_MODE_MOUSE_BUTTON |
report press and release (mode 1000) | |
HOSHO_MODE_MOUSE_DRAG |
also report movement with a button down (mode 1002) | |
HOSHO_MODE_MOUSE_ANY |
also report all movement (mode 1003) | |
HOSHO_MODE_MOUSE_UTF8 |
mouse coordinates as UTF-8 (mode 1005) | |
HOSHO_MODE_MOUSE_SGR |
mouse reports in the SGR form (mode 1006) | |
HOSHO_MODE_MOUSE_URXVT |
mouse reports in the urxvt form (mode 1015) | |
HOSHO_MODE_FOCUS_EVENTS |
report focus in and out (mode 1004) | |
HOSHO_MODE_ALTERNATE_SCROLL |
the wheel sends cursor keys on the alternate screen (mode 1007) | |
HOSHO_MODE_BRACKETED_PASTE |
pasted text goes between ESC [ 200 ~ and ESC [ 201 ~ (mode 2004) | |
HOSHO_MODE_SYNCHRONIZED_OUTPUT |
the program asks the host not to draw until it resets this (mode 2026) | |
HOSHO_MODE_LEFT_RIGHT_MARGINS |
DECLRMM: the left and right margins can be set (mode 69) | |
HOSHO_MODE_NATIONAL_CHARSETS |
DECNRCM: the national replacement character sets are in use (mode 42) | |
HOSHO_MODE_ALLOW_COLUMN_132 |
the program can change between 80 and 132 columns (mode 40) | |
HOSHO_MODE_COLUMN_132 |
DECCOLM: 132 columns (mode 3) | |
HOSHO_MODE_REVERSE_WRAP |
backspace at the first column goes to the end of a line that continued (mode 45) | |
HOSHO_MODE_SIXEL_DISPLAY |
DECSDM: a picture goes to the top left and the screen does not scroll (mode 80) | |
HOSHO_MODE_BACKARROW_BACKSPACE |
DECBKM: the Backspace key sends BS, not DEL (mode 67) | |
HOSHO_MODE_BIDI_IMPLICIT |
BDSM: the display puts right-to-left text in its order (standard mode 8); set after a reset. Reset, the program gives the characters in the order they are shown. | |
HOSHO_MODE_BIDI_AUTODETECT |
a line's direction is that of its first character with a direction (mode 2501); if not, each line is left to right | |
HOSHO_MODE_VT52 |
DECANM is reset: the terminal is a VT52, with the VT52's escape sequences and keys (mode 2, the other way round) | |
HOSHO_MODE_MOUSE_PIXELS |
the SGR mouse reports give pixels, not cells (mode 1016) | |
HOSHO_MODE_META_EIGHTH_BIT |
Alt sets the eighth bit of the character (mode 1034) | |
HOSHO_MODE_META_ESCAPE |
Alt sends ESC in front of the character (mode 1036); set after a reset. | |
HOSHO_MODE_LOCAL_ECHO |
SRM is reset: the host shows what the user types (standard mode 12, the other way round) | |
HOSHO_MODE_KEEP_ON_COLUMN_CHANGE |
DECNCSM: a change between 80 and 132 columns does not erase the screen (mode 95) | |
HOSHO_MODE_PRINT_FORM_FEED |
DECPFF: a form feed goes to the printer after a printed screen (mode 18) | |
HOSHO_MODE_PRINT_FULL_SCREEN |
DECPEX: a printed screen is all of the screen, not the scroll region only (mode 19) | |
HOSHO_MODE_AUTO_PRINT |
MC ?5: a line goes to the printer when the cursor leaves it with LF, VT, FF or a wrap. | |
HOSHO_MODE_PRINTER_CONTROLLER |
MC 5: the program's bytes go to the printer and not to the screen. | |
HOSHO_MODE_EIGHT_BIT_CONTROLS |
S8C1T: answers and keys start with one C1 byte (0x9B for CSI), not with ESC and a second byte. | |
HOSHO_MODE_KEYBOARD_VT220 |
the keyboard is a VT220's: Home and End are Find and Select, the keypad sends its own codes in application mode (mode 1061) | |
HOSHO_MODE_GRAPHEME_CLUSTERS |
each grapheme cluster (UAX #29) is one cell or two: a flag, an emoji with a skin tone, a letter with its spacing mark (mode 2027); set after a reset. Reset, each character with a width has cells of its own, as wcwidth() counts | |
HOSHO_MODE_COUNT |
how many modes there are |
HoshoCursorShape
The cursor shapes of DECSCUSR.
| Name | Value | Description |
|---|---|---|
HOSHO_CURSOR_BLOCK |
a full cell | |
HOSHO_CURSOR_UNDERLINE |
a line below the character | |
HOSHO_CURSOR_BAR |
a line at the left of the cell |
HOSHO_CLIPBOARD_READ and the other values
Bits of what a program can do with the clipboard (OSC 52). A terminal starts with none.
| Name | Value | Description |
|---|---|---|
HOSHO_CLIPBOARD_READ |
1 << 0 |
the program can ask for the clipboard's text |
HOSHO_CLIPBOARD_WRITE |
1 << 1 |
the program can set the clipboard's text |
HOSHO_LED_NUM_LOCK and the other values
The keyboard lights a program can switch (DECLL), as bits of HoshoTerminal.leds.
| Name | Value | Description |
|---|---|---|
HOSHO_LED_NUM_LOCK |
1 << 0 |
the Num Lock light |
HOSHO_LED_CAPS_LOCK |
1 << 1 |
the Caps Lock light |
HOSHO_LED_SCROLL_LOCK |
1 << 2 |
the Scroll Lock light |
HoshoKeySet
The function keys' set of codes: what F1 to F12, Home, End, Insert, Delete, Page Up and Page Down send with no modifier.
| Name | Value | Description |
|---|---|---|
HOSHO_KEY_SET_PC |
xterm's codes for a PC's keyboard; the default | |
HOSHO_KEY_SET_SUN |
a Sun keyboard's codes (mode 1051; the xterm-sun terminal description) | |
HOSHO_KEY_SET_HP |
an HP keyboard's codes (mode 1052; xterm-hp) | |
HOSHO_KEY_SET_SCO |
the SCO console's codes (mode 1053; xterm-sco) | |
HOSHO_KEY_SET_RXVT |
rxvt's codes (the rxvt terminal description) | |
HOSHO_KEY_SET_LINUX |
the Linux console's codes (the linux terminal description) |
HOSHO_KITTY_DISAMBIGUATE and the other values
Bits of the Kitty keyboard protocol's flags (HoshoTerminal.kitty_flags).
| Name | Value | Description |
|---|---|---|
HOSHO_KITTY_DISAMBIGUATE |
1 << 0 |
Escape, and keys with Alt or Control, say what they are; the encoder does this whenever any flag is set. |
HOSHO_KITTY_EVENT_TYPES |
1 << 1 |
a key that repeats and a key that goes up are reported |
HOSHO_KITTY_ALTERNATES |
1 << 2 |
the key with Shift and the key of the standard layout are reported too |
HOSHO_KITTY_ALL_KEYS |
1 << 3 |
each key is reported as an escape code, the keys that type text too |
HOSHO_KITTY_TEXT |
1 << 4 |
with HOSHO_KITTY_ALL_KEYS: the text a key types is in its report |
HoshoKittyImage
One picture a program sent with the Kitty graphics protocol and can show again by its number.
| Field | Type | Description |
|---|---|---|
number |
uint32_t |
the number the program gave it (i=), or the terminal gave it for an I=; 0 for a picture with no number |
alias |
uint32_t |
the image number of I= the program sent it with, or 0; a=p,I= shows the newest picture with it |
pixels |
uint32_t * |
width times height pixels, each 0xAARRGGBB; NULL for a free place |
width |
int |
pixels in a row |
height |
int |
rows of pixels |
placed |
int |
the screen's picture number of the last place it was shown, or 0 |
HoshoPointerEvent
What the pointer did, for hosho_terminal_pointer().
| Name | Value | Description |
|---|---|---|
HOSHO_POINTER_MOTION |
the pointer moved | |
HOSHO_POINTER_PRESS |
a button went down | |
HOSHO_POINTER_RELEASE |
a button went up |
HoshoWindowFunction
The window functions a program can ask for (XTWINOPS), given to HoshoTerminalHost.window.
| Name | Value | Description |
|---|---|---|
HOSHO_WINDOW_SHOW |
1 |
show the window again after HOSHO_WINDOW_ICONIFY |
HOSHO_WINDOW_ICONIFY |
2 |
make the window an icon |
HOSHO_WINDOW_MOVE |
3 |
move the window to first, second (x, y in pixels) |
HOSHO_WINDOW_SIZE_PIXELS |
4 |
make the text area first pixels high and second pixels wide; -1 keeps the value, 0 is the screen's |
HOSHO_WINDOW_RAISE |
5 |
put the window above the others |
HOSHO_WINDOW_LOWER |
6 |
put the window below the others |
HOSHO_WINDOW_REFRESH |
7 |
paint the window again |
HOSHO_WINDOW_MAXIMIZE |
9 |
first is 1 to make the window as large as the screen, 0 to put it back |
HOSHO_WINDOW_FULL_SCREEN |
10 |
first is 1 for full screen, 0 for not, 2 for the other state |
HoshoWindowReport
What a program can ask about the window, given to HoshoTerminalHost.window_report.
| Name | Value | Description |
|---|---|---|
HOSHO_WINDOW_REPORT_ICONIFIED |
11 |
first gets 1 when the window is an icon |
HOSHO_WINDOW_REPORT_POSITION |
13 |
first, second get x, y of the window in pixels |
HOSHO_WINDOW_REPORT_SCREEN |
15 |
first, second get the height and width of the screen in pixels |
HoshoShellState
What the shell does, as its marks say (shell integration, OSC 133).
| Name | Value | Description |
|---|---|---|
HOSHO_SHELL_UNKNOWN |
0 |
the shell sent no marks, or it is between a command's end and the next prompt |
HOSHO_SHELL_PROMPT |
1 |
a prompt shows and no text waits after it |
HOSHO_SHELL_INPUT |
2 |
a prompt shows with text after it that was not sent yet |
HOSHO_SHELL_RUNNING |
3 |
a command runs |
HoshoTerminalHost
What the terminal tells its host. Each function can be NULL.
| Field | Type | Description |
|---|---|---|
reply |
void (*)(void *user, const char *bytes, size_t length) |
Bytes to send to the program, as if typed: the answer to a report request. With S8C1T a C1 control in it is two bytes of UTF-8 (C2 9B for CSI). |
title |
void (*)(void *user, const char *title) |
The program set the window title (UTF-8). |
bell |
void (*)(void *user) |
The program rang the bell. |
resize |
void (*)(void *user, int rows, int columns) |
The screen has another size, or the program asks for one. For 132 columns (DECCOLM) and for a page size the program set (DECSCPP, DECSLPP, DECSNLS, only after hosho_terminal_set_window_access()) the terminal has the new size already and the host's window follows; for a size request (CSI 8 t, only after hosho_terminal_set_window_access()) nothing changed, and a host that agrees calls hosho_terminal_resize(). |
clipboard_set |
void (*)(void *user, char selection, const char *text, size_t length) |
The program sets a selection's text (OSC 52, with HOSHO_CLIPBOARD_WRITE): selection is 'c' for the clipboard, 'p' for PRIMARY. |
clipboard_request |
void (*)(void *user, char selection) |
The program asks for a selection's text (OSC 52, with HOSHO_CLIPBOARD_READ). The host answers with hosho_terminal_clipboard_reply(). |
leds |
void (*)(void *user, int leds) |
The program switched keyboard lights (DECLL): leds has the HOSHO_LED_* bits that are on now. |
print |
void (*)(void *user, const char *bytes, size_t length) |
Bytes for the printer (MC): text with a line feed after each line, or in printer controller mode the program's bytes as they are. A call with length 0 says the print job ended. With no such function the terminal has no printer and the bytes are dropped. |
image_decode |
uint32_t * (*)(void *user, const uint8_t *data, size_t length, int *width, int *height) |
Decode a picture file a program sent (an iTerm2 inline image, or kitty's f=100: PNG, and what more the host knows): gives width times height pixels from malloc(), each 0xAARRGGBB, or NULL. The data can be hostile: a host can do this in a process of its own (a jail). With no such function the terminal shows only pictures that come as pixels (sixel, kitty's f=24 and f=32). |
notify |
void (*)(void *user, const char *title, const char *body) |
The program asks the user's attention (OSC 9, OSC 777, OSC 99): title can be NULL; the texts are UTF-8. |
progress |
void (*)(void *user, int state, int percent) |
The program tells how far a job is (OSC 9;4): state is 0 for no job, 1 for a job at percent, 2 for an error, 3 for a job with no known end, 4 for a job that waits. |
icon_name |
void (*)(void *user, const char *name) |
The program set the name of the window's icon (OSC 1, OSC 0); in hexadecimal title mode, decoded. The terminal keeps it in HoshoTerminal.icon_name. |
pointer_shape |
void (*)(void *user, const char *name) |
The program asks for a pointer shape by its name (OSC 22), for example "text" or "pointer"; "" for the host's own. |
text |
void (*)(void *user, const char *bytes, size_t length) |
Text for a log: each character the program shows, as UTF-8, and a line feed for each line feed. |
command_end |
void (*)(void *user, int status, double seconds) |
A command of the shell ended (OSC 133;D after OSC 133;C): its exit status (the number after D;, up to the next ;, or 0 when the shell sent none), and how many seconds it ran. |
window |
void (*)(void *user, HoshoWindowFunction function, int first, int second) |
The program asks for a window function (only after hosho_terminal_set_window_access()). |
window_report |
int (*)(void *user, HoshoWindowReport report, int *first, int *second) |
The program asks about the window (only after hosho_terminal_set_window_access()). Returns 1 when first and second have the answer. |
shell_state |
void (*)(void *user, HoshoShellState state) |
The shell's state changed (hosho_terminal_shell_state()): told after the bytes that changed it, after typed bytes did, and after hosho_terminal_shell_forget() and hosho_terminal_reset(). |
sixel_decode |
uint32_t * (*)(void *user, const char *data, size_t length, uint32_t *colors, int fill_background, int *width, int *height) |
Read a sixel picture's data in place of the terminal, as hosho_sixel_decode() does: colors are the terminal's 256 color registers, which the picture can change, and the host puts the changed ones back. Gives width times height pixels from malloc(), each 0xAARRGGBB, at most HOSHO_SIXEL_SIZE_LIMIT each way, or NULL. For a host that reads what programs send in a process of its own (a jail): the data can be hostile. With no such function the terminal reads it itself. |
inflate |
uint8_t * (*)(void *user, const uint8_t *data, size_t length, size_t *result_length) |
Make zlib-compressed picture data whole (kitty's o=z) in place of the terminal, as hosho_inflate() does: at most HOSHO_INFLATE_LIMIT bytes from malloc(), or NULL. As sixel_decode, for a host that does it in a jail; with no such function the terminal does it itself. |
HoshoSavedCursor
What DECSC saves and DECRC puts back.
| Field | Type | Description |
|---|---|---|
row |
int |
cursor row |
column |
int |
cursor column |
pen |
HoshoCell |
colors and attributes |
charsets[4] |
uint8_t |
G0..G3. |
charset_left |
uint8_t |
which of G0..G3 is in use |
origin |
uint8_t |
origin mode |
wrap_pending |
uint8_t |
the last column flag |
HoshoTerminal
One terminal. Make it with hosho_terminal_create(); read the fields, change them only through the functions.
| Field | Type | Description |
|---|---|---|
screen |
HoshoScreen |
the cells |
parser |
HoshoParser |
reads the input |
host |
const HoshoTerminalHost * |
where reports, the title and the bell go |
user |
void * |
given back to each host function |
cursor_row |
int |
the cursor's row, from 0 |
cursor_column |
int |
the cursor's column, from 0 |
wrap_pending |
uint8_t |
the cursor is on the last column and the next character starts a new line |
cursor_shape |
uint8_t |
HoshoCursorShape. |
pen |
HoshoCell |
colors and attributes of the next character; its character field is not used |
scroll_top |
int |
first row of the scroll region |
scroll_bottom |
int |
last row of the scroll region |
modes[HOSHO_MODE_COUNT] |
uint8_t |
1 for each mode that is set |
tab_stops |
uint8_t * |
for each column, 1 when it has a tab stop |
charsets[4] |
uint8_t |
the character set designated to G0..G3 (a number the terminal gives each set) |
charset_left |
uint8_t |
which of G0..G3 the bytes 0x20..0x7E use |
single_shift |
uint8_t |
2 or 3: the next character uses G2 or G3; 0 for none |
saved[2] |
HoshoSavedCursor |
the saved cursor of the primary and of the alternate buffer |
last_character |
uint32_t |
the last character shown, for REP |
join_pending |
uint8_t |
the last character was U+200D (zero width joiner): the next one joins the same cell, as one emoji |
palette[256] |
uint32_t |
the palette colors now, as 0xRRGGBB |
palette_initial[256] |
uint32_t |
the palette colors a reset gives |
foreground |
uint32_t |
the default foreground now, as 0xRRGGBB |
background |
uint32_t |
the default background now |
cursor_color |
uint32_t |
the cursor color now |
foreground_initial |
uint32_t |
the default foreground a reset gives |
background_initial |
uint32_t |
the default background a reset gives |
cursor_color_initial |
uint32_t |
the cursor color a reset gives |
title |
char * |
the window title, or NULL when the program set none |
icon_name |
char * |
the icon's name (OSC 0 and OSC 1), or NULL when the program set none |
cursor_shape_initial |
uint8_t |
the cursor shape a reset gives (HoshoCursorShape) |
cursor_blink_initial |
uint8_t |
whether the cursor blinks after a reset |
margin_left |
int |
first column of the scroll region; 0 without left and right margins |
margin_right |
int |
last column of the scroll region |
protection |
uint8_t |
how cells were protected last: 0 not, 1 by DECSCA, 2 by SPA (then ED, EL and ECH keep them too) |
attribute_rectangle |
uint8_t |
DECSACE: DECCARA and DECRARA change a rectangle, not a stream of cells. |
modify_other_keys |
uint8_t |
XTMODKEYS level 0, 1 or 2: how much a modified key says of itself. |
title_modes |
uint8_t |
XTSMTITLE: bit 0 a title comes in hexadecimal; bits 1 to 3 are kept for the report. |
format_other_keys |
uint8_t |
1: such keys are sent as CSI code ; modifiers u, not CSI 27 ; modifiers ; code ~ |
clipboard_access |
uint8_t |
HOSHO_CLIPBOARD_* bits. |
checksum_extension |
uint8_t |
XTCHECKSUM: the bits that change how DECRQCRA counts. |
keyboard_vt220_initial |
uint8_t |
whether the keyboard is a VT220's after a reset |
leds |
uint8_t |
HOSHO_LED_* bits: the keyboard lights the program switched on. |
answerback[64] |
char |
what the terminal sends when a program sends ENQ; "" for nothing |
cell_width |
int |
the width of a cell in pixels at the host, for pictures and reports |
cell_height |
int |
the height of a cell in pixels at the host |
title_stack[HOSHO_TITLE_STACK_LIMIT] |
char * |
the titles a program saved (CSI 22 t) |
title_stack_count |
int |
how many titles are saved |
directory |
char * |
the shell's current directory, when the shell tells it (OSC 7); NULL when not known |
sixel_colors[256] |
uint32_t |
the color registers of sixel pictures |
user_keys[HOSHO_USER_KEY_LIMIT] |
char * |
DECUDK: what a function key sends with Shift, by its DEC key number; NULL for a key with no definition. |
user_key_lengths[HOSHO_USER_KEY_LIMIT] |
uint16_t |
the bytes of each definition |
user_keys_locked |
uint8_t |
DECUDK: the definitions cannot be changed until a reset. |
print_held[8] |
char |
printer controller mode: bytes that can be the start of the sequence that ends the mode |
print_held_count |
uint8_t |
how many such bytes |
status_type |
uint8_t |
DECSSDT: 0 no status line, 1 the terminal's own indicator line, 2 a line the program writes. |
status_active |
uint8_t |
DECSASD: 1 while the program's text goes to the status line. |
status_dirty |
uint8_t |
1 when the status line changed; the host sets it to 0 after it painted the line |
status_cells |
HoshoCell * |
the cells of the status line; read them with hosho_terminal_status_line() |
status_columns |
int |
how many cells the status line has |
status_column |
int |
the cursor's column in the status line |
status_pen |
HoshoCell |
colors and attributes of the next character of the status line |
locator_mode |
uint8_t |
DECELR: 0 the locator is off, 1 it reports, 2 it reports one time. |
locator_pixels |
uint8_t |
DECELR: 1 when positions are in pixels, 0 in cells. |
locator_events |
uint8_t |
DECSLE: bit 0 a button press is reported, bit 1 a release. |
locator_filter |
uint8_t |
DECEFR: 1 while a filter rectangle waits for the pointer to leave it. |
locator_rectangle[4] |
int |
the filter rectangle: top, left, bottom, right, in the locator's units |
pointer_known |
uint8_t |
1 after the host told a pointer position |
pointer_buttons |
uint8_t |
the buttons that are down: bit 0 right, bit 1 middle, bit 2 left, bit 3 the fourth |
pointer_row |
int |
the pointer's row, from 0 |
pointer_column |
int |
the pointer's column, from 0 |
pointer_x |
int |
the pointer's x in pixels from the left of the text |
pointer_y |
int |
the pointer's y in pixels from the top of the text |
window_access |
uint8_t |
1 when a program can use the window functions and reports |
key_set |
uint8_t |
HoshoKeySet: the function keys' codes now. |
key_set_initial |
uint8_t |
HoshoKeySet a reset gives. |
kitty_flags[2] |
uint8_t |
the Kitty keyboard protocol's flags now, for the primary and for the alternate buffer; read them with hosho_terminal_kitty_flags() |
kitty_stack[2][HOSHO_KITTY_STACK_LIMIT] |
uint8_t |
the flags a program saved |
kitty_stack_count[2] |
uint8_t |
how many are saved |
kitty_images[HOSHO_KITTY_IMAGE_LIMIT] |
HoshoKittyImage |
the pictures a program keeps in the terminal |
kitty_image_next |
int |
the place the next kept picture takes when all are in use |
kitty_data |
char * |
the data of a picture that comes in more than one part |
kitty_data_length |
size_t |
its bytes so far |
kitty_keys[256] |
char |
the keys of that picture's first part |
kitty_data_dropped |
uint8_t |
1 when the parts of that picture went past HOSHO_INFLATE_LIMIT: the rest are dropped, and the last one gets an error |
vt52_position |
uint8_t |
VT52 direct cursor address: how many of its two bytes are still to come. |
vt52_row |
uint8_t |
the row byte of that address |
vt100_level |
uint8_t |
1 after a program left VT52 mode: the terminal is then a VT100 until a reset, as a real VT is, with no DECSCL, no DECRQSS and no 8-bit controls |
dynamic_colors[7] |
uint32_t |
the colors of OSC 13 to 19: pointer foreground and background, Tektronix foreground and background, selection background, Tektronix cursor, selection foreground |
dynamic_set |
uint8_t |
for each of them, a bit that says a program set it |
command_started |
double |
when the shell said a command's output starts (OSC 133;C), in seconds of a clock that does not go back; less than 0 for none |
notify_title |
char * |
the title of a notification that is not complete yet (OSC 99) |
shell_phase |
uint8_t |
what the shell's marks said last: 0 nothing, 1 a prompt shows (OSC 133;A), 2 a command runs (OSC 133;C, or Return typed at a prompt of a shell that cannot say it) |
shell_input_marked |
uint8_t |
1 when this prompt's line knows where the user's command starts (OSC 133;B, or the cursor's place at the first typed byte) |
shell_infer |
uint8_t |
1 when the shell's prompt said the shell cannot tell that a command starts (OSC 133;A;hosho=infer): Return typed after text at the prompt says it |
shell_typed |
uint8_t |
1 when text was typed at the prompt that the program did not answer yet: the screen does not show it |
shell_reported |
uint8_t |
the HoshoShellState the host was told last |
Constants
HOSHO_KITTY_IMAGE_LIMIT
#define HOSHO_KITTY_IMAGE_LIMIT 32
How many pictures a program can send and keep to show later (the Kitty graphics protocol); one more replaces the oldest.
HOSHO_KITTY_STACK_LIMIT
#define HOSHO_KITTY_STACK_LIMIT 8
How many sets of flags the Kitty keyboard protocol's stack holds for each buffer.
HOSHO_USER_KEY_LIMIT
#define HOSHO_USER_KEY_LIMIT 35
One more than the largest key number of DECUDK (F20 is 34).
HOSHO_TITLE_STACK_LIMIT
#define HOSHO_TITLE_STACK_LIMIT 10
The most titles the title stack holds (CSI 22 t); one more drops the oldest.
Functions
hosho_terminal_create
HoshoTerminal *hosho_terminal_create(
int rows,
int columns,
int scrollback_limit,
const HoshoTerminalHost *host,
void *user);
Make a terminal.
| Parameter | Description |
|---|---|
rows |
Lines on the screen, 1 or more |
columns |
Cells in a line, 1 or more |
scrollback_limit |
The most lines of scrollback; 0 for none |
host |
The functions the terminal calls; can be NULL; must stay valid while the terminal is used |
user |
A pointer given back to each host function |
Returns: The terminal, or NULL when memory ran out or a size is not correct
hosho_terminal_destroy
void hosho_terminal_destroy(HoshoTerminal *terminal);
Release a terminal.
| Parameter | Description |
|---|---|
terminal |
The terminal; NULL is permitted |
hosho_terminal_feed
void hosho_terminal_feed(HoshoTerminal *terminal, const void *bytes, size_t length);
Give the terminal the bytes a program wrote.
| Parameter | Description |
|---|---|
terminal |
The terminal |
bytes |
The bytes |
length |
How many bytes |
hosho_terminal_typed
void hosho_terminal_typed(HoshoTerminal *terminal, const void *bytes, size_t length);
Tell the terminal what the user typed or pasted, when the host sends it to the program.
The terminal does not show these bytes. It learns from them where the user's command starts, for a shell that did not say it (no OSC 133;B), and that a command starts, for a shell that cannot say it (OSC 133;A;hosho=infer).
| Parameter | Description |
|---|---|
terminal |
The terminal |
bytes |
The bytes |
length |
How many bytes |
hosho_terminal_shell_forget
void hosho_terminal_shell_forget(HoshoTerminal *terminal);
Forget what the shell's marks said: the host calls this when the shell ended or another program starts.
| Parameter | Description |
|---|---|
terminal |
The terminal |
hosho_terminal_shell_state
HoshoShellState hosho_terminal_shell_state(const HoshoTerminal *terminal);
What the shell does now, from its marks (OSC 133)
| Parameter | Description |
|---|---|
terminal |
The terminal |
Returns: The state; HOSHO_SHELL_UNKNOWN for a shell that sends no marks
hosho_terminal_resize
int hosho_terminal_resize(HoshoTerminal *terminal, int rows, int columns);
Change the size of the screen.
The host must also tell the program (hosho_pseudoterminal_resize()). A new width wraps the text of the primary buffer and the scrollback again. The scroll region and the left and right margins become the whole screen.
| Parameter | Description |
|---|---|
terminal |
The terminal |
rows |
The new number of lines, 1 or more |
columns |
The new number of cells in a line, 1 or more |
Returns: 0, or -1 when memory ran out; the terminal is then still correct, with the size in screen.rows and screen.columns
hosho_terminal_reset
void hosho_terminal_reset(HoshoTerminal *terminal);
Put the terminal in the state it has after hosho_terminal_create(); the scrollback stays.
This is what RIS does, and a sequence that was not complete is dropped too. The defaults the host set (colors, palette, cursor, keyboard) stay, and so do the permissions, the answerback message and the cell size.
| Parameter | Description |
|---|---|
terminal |
The terminal |
hosho_terminal_mode
int hosho_terminal_mode(const HoshoTerminal *terminal, HoshoMode mode);
Read a mode.
| Parameter | Description |
|---|---|
terminal |
The terminal |
mode |
The mode |
Returns: 1 when the mode is set, 0 when it is not
hosho_terminal_set_default_colors
void hosho_terminal_set_default_colors(
HoshoTerminal *terminal,
uint32_t foreground,
uint32_t background,
uint32_t cursor);
Set the default colors a host shows; a program can change them and a reset puts these back.
| Parameter | Description |
|---|---|
terminal |
The terminal |
foreground |
The default foreground, 0xRRGGBB |
background |
The default background, 0xRRGGBB |
cursor |
The cursor color, 0xRRGGBB |
hosho_terminal_set_default_cursor
void hosho_terminal_set_default_cursor(
HoshoTerminal *terminal,
HoshoCursorShape shape,
int blink);
Set the cursor a host shows by default; a program can change it (DECSCUSR) and a reset puts this back.
| Parameter | Description |
|---|---|
terminal |
The terminal |
shape |
The shape |
blink |
1 when the cursor blinks, 0 when it does not |
hosho_terminal_set_cell_size
void hosho_terminal_set_cell_size(HoshoTerminal *terminal, int width, int height);
Tell the terminal the size of a cell in pixels; pictures and size reports use it.
| Parameter | Description |
|---|---|
terminal |
The terminal |
width |
The width of a cell in pixels |
height |
The height of a cell in pixels |
hosho_terminal_set_clipboard_access
void hosho_terminal_set_clipboard_access(HoshoTerminal *terminal, int access);
Say what a program can do with the clipboard (OSC 52); a terminal starts with nothing permitted.
| Parameter | Description |
|---|---|
terminal |
The terminal |
access |
HOSHO_CLIPBOARD_* bits |
hosho_terminal_set_default_keyboard
void hosho_terminal_set_default_keyboard(HoshoTerminal *terminal, int vt220);
Choose the keyboard a host has by default: a PC's or a VT220's; a program can change it (mode 1061) and a reset puts this back.
| Parameter | Description |
|---|---|
terminal |
The terminal |
vt220 |
1 for a VT220's keyboard, 0 for a PC's |
hosho_terminal_set_default_key_set
void hosho_terminal_set_default_key_set(HoshoTerminal *terminal, HoshoKeySet key_set);
Choose the function keys' codes a host has by default; a program can change them (modes 1051 to 1053) and a reset puts this back.
| Parameter | Description |
|---|---|
terminal |
The terminal |
key_set |
The set |
hosho_terminal_kitty_flags
int hosho_terminal_kitty_flags(const HoshoTerminal *terminal);
Get the Kitty keyboard protocol's flags of the buffer in use.
| Parameter | Description |
|---|---|
terminal |
The terminal |
Returns: HOSHO_KITTY_* bits; 0 when the program did not ask for the protocol
hosho_terminal_set_answerback
void hosho_terminal_set_answerback(HoshoTerminal *terminal, const char *text);
Set the answerback message: what the terminal sends when a program sends ENQ.
| Parameter | Description |
|---|---|
terminal |
The terminal |
text |
The message, cut to 63 bytes; NULL or "" for none |
hosho_terminal_set_window_access
void hosho_terminal_set_window_access(HoshoTerminal *terminal, int allowed);
Say if a program can use the window functions (move, size, raise, icon) and the window reports, the title's too; a terminal starts with this not permitted.
With it a program can also change the size in characters (CSI 8 t to HoshoTerminalHost.resize; DECSLPP, DECSCPP and DECSNLS at once) and read the icon's name (CSI 20 t). Without it the terminal still answers the size reports (CSI 14, 16, 18 and 19 t) and keeps the title stack (CSI 22 and 23 t), which change nothing.
| Parameter | Description |
|---|---|
terminal |
The terminal |
allowed |
1 to permit, 0 to refuse |
hosho_terminal_status_line
const HoshoCell *hosho_terminal_status_line(HoshoTerminal *terminal, int *columns);
Get the status line (DECSSDT)
With the indicator line the terminal writes the line's text when this is called.
| Parameter | Description |
|---|---|
terminal |
The terminal |
columns |
Gets the number of cells |
Returns: The cells, or NULL when there is no status line
hosho_terminal_pointer
int hosho_terminal_pointer(
HoshoTerminal *terminal,
HoshoPointerEvent event,
int button,
int row,
int column,
int x,
int y);
Tell the terminal what the pointer did; with the DEC locator on (DECELR), the terminal sends the program the locator reports.
| Parameter | Description |
|---|---|
terminal |
The terminal |
event |
What the pointer did |
button |
For a press or release: 1 left, 2 middle, 3 right, 4 the fourth; 0 for motion |
row |
The pointer's row, from 0 |
column |
The pointer's column, from 0 |
x |
The pointer's x in pixels from the left of the text |
y |
The pointer's y in pixels from the top of the text |
Returns: 1 when the locator is on, so the event is the program's; 0 when it is not
hosho_terminal_user_key
const char *hosho_terminal_user_key(
const HoshoTerminal *terminal,
int number,
size_t *length);
Get what a function key sends with Shift, when a program defined that (DECUDK)
| Parameter | Description |
|---|---|
terminal |
The terminal |
number |
The DEC number of the key: 11 to 15 for F1 to F5, 17 to 21 for F6 to F10, 23 to 26 for F11 to F14, 28 and 29 for F15 and F16, 31 to 34 for F17 to F20 |
length |
Gets the number of bytes |
Returns: The bytes, or NULL when the key has no definition
hosho_terminal_clipboard_reply
void hosho_terminal_clipboard_reply(
HoshoTerminal *terminal,
char selection,
const char *text,
size_t length);
Give the program a selection's text, as the answer to HoshoTerminalHost.clipboard_request.
| Parameter | Description |
|---|---|
terminal |
The terminal |
selection |
'c' or 'p', as in the request |
text |
The text; NULL for none |
length |
Its bytes |
hosho_terminal_set_palette_color
void hosho_terminal_set_palette_color(HoshoTerminal *terminal, int index, uint32_t color);
Set one palette color of the host's theme; a program can change it and a reset puts this back.
| Parameter | Description |
|---|---|
terminal |
The terminal |
index |
The palette number, 0..255 |
color |
The color, 0xRRGGBB |
hosho_terminal_color
uint32_t hosho_terminal_color(
const HoshoTerminal *terminal,
HoshoColor color,
int is_background);
Get the 0xRRGGBB to draw a cell color with.
It does not exchange the colors for HOSHO_ATTRIBUTE_INVERSE or HOSHO_MODE_REVERSE_VIDEO: the host does that.
| Parameter | Description |
|---|---|
terminal |
The terminal |
color |
The cell's foreground or background |
is_background |
1 when color is a background, so the default is the default background |
Returns: The color as 0xRRGGBB
Hosho API
The whole library
From bytes to a screen
For the host that shows it
The program