|
ginnOS
The reference: libc, the libraries and the kernel
|
libvt: a terminal emulator without a screen. More...
Go to the source code of this file.
Data Structures | |
| struct | vt_cell_t |
| struct | vt_line_t |
| a line of cells: on the screen, or in the scrollback. More... | |
| struct | vt |
Macros | |
| #define | VT_COLOR_DEFAULT 0u |
| a colour of a cell: the default (the theme's text or background), one of the 256 palette colours, or a 24-bit colour. | |
| #define | VT_COLOR_INDEX 0x01000000u |
| #define | VT_COLOR_RGB 0x02000000u |
| #define | VT_COLOR_KIND(c) |
| #define | VT_BOLD 0x0001u |
| #define | VT_DIM 0x0002u |
| #define | VT_ITALIC 0x0004u |
| #define | VT_UNDERLINE 0x0008u |
| #define | VT_BLINK 0x0010u |
| #define | VT_INVERSE 0x0020u |
| #define | VT_HIDDEN 0x0040u |
| #define | VT_STRIKE 0x0080u |
| #define | VT_MOD_SHIFT 0x01 |
| #define | VT_MOD_ALT 0x02 |
| #define | VT_MOD_CTRL 0x04 |
Typedefs | |
| typedef void(*) | vt_reply_t(const char *data, size_t length, void *user) |
| where the terminal sends its answers (the cursor position, the device attributes): to the program, through the pty. | |
| typedef struct vt | vt_t |
Enumerations | |
| enum | vt_cursor_shape_t { VT_CURSOR_BLOCK , VT_CURSOR_UNDERLINE , VT_CURSOR_BAR } |
| enum | vt_mouse_mode_t { VT_MOUSE_OFF , VT_MOUSE_CLICKS , VT_MOUSE_DRAG , VT_MOUSE_MOTION } |
| enum | vt_key_t { VT_KEY_UP = 1 , VT_KEY_DOWN , VT_KEY_RIGHT , VT_KEY_LEFT , VT_KEY_HOME , VT_KEY_END , VT_KEY_INSERT , VT_KEY_DELETE , VT_KEY_PAGE_UP , VT_KEY_PAGE_DOWN , VT_KEY_ENTER , VT_KEY_TAB , VT_KEY_BACKSPACE , VT_KEY_ESCAPE , VT_KEY_F1 , VT_KEY_F12 = VT_KEY_F1 + 11 } |
| enum | vt_mouse_t { VT_MOUSE_PRESS , VT_MOUSE_RELEASE , VT_MOUSE_MOVE , VT_MOUSE_WHEEL_UP , VT_MOUSE_WHEEL_DOWN } |
Functions | |
| vt_t * | vt_new (int cols, int rows, int scrollback) |
| a terminal of a size, with room for so many lines of scrollback. | |
| void | vt_free (vt_t *vt) |
| void | vt_set_reply (vt_t *vt, vt_reply_t reply, void *user) |
| where the answers go (without it, they are dropped). | |
| void | vt_write (vt_t *vt, const void *data, size_t length) |
| the bytes the program wrote. | |
| void | vt_resize (vt_t *vt, int cols, int rows) |
| a new size. | |
| const vt_line_t * | vt_line (const vt_t *vt, int y) |
| a line of the screen (0 to rows - 1), or of the scrollback (-1 is the newest line, down to -vt_scrollback_lines). | |
| int | vt_scrollback_lines (const vt_t *vt) |
| the lines in the scrollback now | |
| bool | vt_line_dirty (const vt_t *vt, int y) |
| true if the screen line y changed since vt_clean | |
| void | vt_clean (vt_t *vt) |
| forget what changed: the app drew it | |
| size_t | vt_text (const vt_t *vt, int x0, int y0, int x1, int y1, char *out, size_t size) |
| the text from (x0, y0) to (x1, y1), both included, as UTF-8; y as for vt_line. | |
| uint32_t | vt_palette (int index) |
| the RGB colour of palette entry 0 to 255: the 16 colours of xterm, the 6x6x6 cube and the grey ramp. | |
| int | vt_key (const vt_t *vt, vt_key_t key, int mods, char *out) |
| the bytes a key sends, as xterm sends them (the arrows follow DECCKM; with modifiers, ESC [ 1 ; m A). | |
| int | vt_text_key (const char *text, int mods, char *out) |
| the bytes typed text sends: Ctrl with a letter or one of []^_ and space gives the control character, Alt puts ESC in front. | |
| int | vt_mouse (const vt_t *vt, vt_mouse_t kind, int button, int x, int y, int mods, char *out) |
| a mouse report for the program, if its mode asks for this one. | |
| const char * | vt_paste_begin (const vt_t *vt) |
| what goes before and after pasted text: the bracketed paste marks when the program asked for them, else "". | |
| const char * | vt_paste_end (const vt_t *vt) |
libvt: a terminal emulator without a screen.
the bytes a program writes to its terminal go in (vt_write); a grid of cells comes out, with the scrollback, the cursor and the modes the program set. libvt also makes the bytes for keys, the mouse and paste, as the program asked for them (vt_key, vt_mouse, vt_paste_begin).
vt_t *vt = vt_new(80, 24, 10000); vt_write(vt, buf, n); // what the pty gave for (int y = 0; y < vt->rows; y++) if (vt_line_dirty(vt, y)) draw_line(vt_line(vt, y)); vt_clean(vt);
the escape sequences are those of xterm that full-screen programs use: VT100 and VT220 cursor and erase, scroll regions, insert and delete, SGR with 16, 256 and 24-bit colours, the alternate screen, bracketed paste, mouse reports (X10, button and any-event, SGR), cursor shapes, the DEC line drawing characters and the window title (OSC 0 and 2). TERM is xterm-256color.
not yet: wide characters (CJK, emoji) take one cell, combining marks take a cell of their own, and the lines are not wrapped again on a resize.
| #define VT_COLOR_DEFAULT 0u |
a colour of a cell: the default (the theme's text or background), one of the 256 palette colours, or a 24-bit colour.
| #define VT_COLOR_INDEX 0x01000000u |
| #define VT_COLOR_RGB 0x02000000u |
| #define VT_COLOR_KIND | ( | c | ) |
| #define VT_BOLD 0x0001u |
| #define VT_DIM 0x0002u |
| #define VT_ITALIC 0x0004u |
| #define VT_UNDERLINE 0x0008u |
| #define VT_BLINK 0x0010u |
| #define VT_INVERSE 0x0020u |
| #define VT_HIDDEN 0x0040u |
| #define VT_STRIKE 0x0080u |
| #define VT_MOD_SHIFT 0x01 |
| #define VT_MOD_ALT 0x02 |
| #define VT_MOD_CTRL 0x04 |
| typedef void(*) vt_reply_t(const char *data, size_t length, void *user) |
where the terminal sends its answers (the cursor position, the device attributes): to the program, through the pty.
| enum vt_cursor_shape_t |
| enum vt_mouse_mode_t |
| enum vt_key_t |
| enum vt_mouse_t |
| vt_t * vt_new | ( | int | cols, |
| int | rows, | ||
| int | scrollback ) |
a terminal of a size, with room for so many lines of scrollback.
| void vt_free | ( | vt_t * | vt | ) |
| void vt_set_reply | ( | vt_t * | vt, |
| vt_reply_t | reply, | ||
| void * | user ) |
where the answers go (without it, they are dropped).
the bytes the program wrote.
UTF-8 and escape sequences can be split between calls.
| void vt_resize | ( | vt_t * | vt, |
| int | cols, | ||
| int | rows ) |
a new size.
the lines keep their text (cut, or filled with empty cells); when the screen gets lower, the lines above the cursor go into the scrollback so the cursor stays on the screen.
a line of the screen (0 to rows - 1), or of the scrollback (-1 is the newest line, down to -vt_scrollback_lines).
NULL past the ends. a line of the scrollback can be narrower or wider than the screen.
| int vt_scrollback_lines | ( | const vt_t * | vt | ) |
the lines in the scrollback now
| void vt_clean | ( | vt_t * | vt | ) |
forget what changed: the app drew it
the text from (x0, y0) to (x1, y1), both included, as UTF-8; y as for vt_line.
lines end with "\n" unless they wrapped; the empty cells at the end of a line are left out.
| uint32_t vt_palette | ( | int | index | ) |
the RGB colour of palette entry 0 to 255: the 16 colours of xterm, the 6x6x6 cube and the grey ramp.
the app can use its own 16 colours.
the bytes a key sends, as xterm sends them (the arrows follow DECCKM; with modifiers, ESC [ 1 ; m A).
| out | room for 16 bytes. |
| int vt_text_key | ( | const char * | text, |
| int | mods, | ||
| char * | out ) |
the bytes typed text sends: Ctrl with a letter or one of []^_ and space gives the control character, Alt puts ESC in front.
| text | UTF-8, as the keyboard layout made it. |
| out | room for 16 bytes. |
| int vt_mouse | ( | const vt_t * | vt, |
| vt_mouse_t | kind, | ||
| int | button, | ||
| int | x, | ||
| int | y, | ||
| int | mods, | ||
| char * | out ) |
a mouse report for the program, if its mode asks for this one.
| button | 0 left, 1 middle, 2 right, -1 none (motion). |
| x,y | the cell, from 0. |
| out | room for 32 bytes. |
| const char * vt_paste_begin | ( | const vt_t * | vt | ) |
what goes before and after pasted text: the bracketed paste marks when the program asked for them, else "".
| const char * vt_paste_end | ( | const vt_t * | vt | ) |