The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
vt.c File Reference

libvt: the parser, the screens and the scrollback. More...

#include "vt.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Macros

#define PARAMS_MAX   16
#define OSC_MAX   512
#define PARAM_MAX   9999

Enumerations

enum  {
  GROUND , ESCAPE , ESCAPE_INTER , CSI ,
  CSI_IGNORE , OSC , OSC_ESCAPE , STRING ,
  STRING_ESCAPE
}
enum  { CHARSET_ASCII , CHARSET_GRAPHICS }

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 fn, 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)

Detailed Description

libvt: the parser, the screens and the scrollback.

the parser is a state machine after the DEC one (vt100.net): text, ESC, CSI with its parameters, OSC strings, and the strings it ignores (DCS, APC, PM, SOS). control characters act inside a sequence too.

a screen is an array of line pointers, so a scroll moves pointers and not cells. the lines that scroll off the top of the main screen go to the scrollback, a ring of lines.

Macro Definition Documentation

◆ PARAMS_MAX

#define PARAMS_MAX   16

◆ OSC_MAX

#define OSC_MAX   512

◆ PARAM_MAX

#define PARAM_MAX   9999

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GROUND 
ESCAPE 
ESCAPE_INTER 
CSI 
CSI_IGNORE 
OSC 
OSC_ESCAPE 
STRING 
STRING_ESCAPE 

◆ anonymous enum

anonymous enum
Enumerator
CHARSET_ASCII 
CHARSET_GRAPHICS 

Function Documentation

◆ vt_new()

vt_t * vt_new ( int cols,
int rows,
int scrollback )

a terminal of a size, with room for so many lines of scrollback.

◆ vt_free()

void vt_free ( vt_t * vt)

◆ vt_set_reply()

void vt_set_reply ( vt_t * vt,
vt_reply_t fn,
void * user )

where the answers go (without it, they are dropped).

◆ vt_write()

void vt_write ( vt_t * vt,
const void * data,
size_t length )

the bytes the program wrote.

UTF-8 and escape sequences can be split between calls.

◆ vt_resize()

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.

◆ vt_line()

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).

NULL past the ends. a line of the scrollback can be narrower or wider than the screen.

◆ vt_scrollback_lines()

int vt_scrollback_lines ( const vt_t * vt)

the lines in the scrollback now

◆ vt_line_dirty()

bool vt_line_dirty ( const vt_t * vt,
int y )

true if the screen line y changed since vt_clean

◆ vt_clean()

void vt_clean ( vt_t * vt)

forget what changed: the app drew it

◆ vt_text()

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.

lines end with "\n" unless they wrapped; the empty cells at the end of a line are left out.

Returns
the bytes it needed (it writes at most size - 1 and a 0).

◆ vt_palette()

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.

◆ vt_key()

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).

Parameters
outroom for 16 bytes.
Returns
the length (0: the key sends nothing).

◆ vt_text_key()

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.

Parameters
textUTF-8, as the keyboard layout made it.
outroom for 16 bytes.
Returns
the length.

◆ vt_mouse()

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.

Parameters
button0 left, 1 middle, 2 right, -1 none (motion).
x,ythe cell, from 0.
outroom for 32 bytes.
Returns
the length (0: nothing to send; the app can select instead).

◆ vt_paste_begin()

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 "".

◆ vt_paste_end()

const char * vt_paste_end ( const vt_t * vt)