Scroll to navigation

LIBTTY(3) termrec LIBTTY(3)

NAME

libtty - a library for handling vt100-like pseudo-terminals

SYNOPSIS

#include <tty.h>

Link with -ltty.

DESCRIPTION

Functions:

Creates a new vt100 terminal, of size sx×sy. If you want user input to be allowed to change that size, set resizable to non-zero.
Resizes the vt to nsx×nsy. This works even on terminals marked as non-resizable since that prevents only user input from resizing, not you.
Clears the screen and attributes.
Deallocates the vt and all its internal structures.
Writes len bytes into the terminal, parsing them as vt100 codes.
Does a printf into the terminal.
Allocates a new vt100 terminal, making it an exact copy of an existing one, including its internal state. Attached event callbacks are not copied.
Converts color values between modes: VT100_COLOR_OFF, VT100_COLOR_16, VT100_COLOR_256, VT100_COLOR_RGB.

Inside the terminal

You'll most likely be interested in the following fields of the structure:

scr is an array of character/attribute pairs, more exactly, each element is a struct "{ ucs ch; int attr; }". The array is a flat one of vt->sx*vt->sy elements, arranged row by row. A screen coordinate x,y is stored at x+y*vt->sy.

For other fields, please RTFS the header itself: tty.h

TTY event callbacks

Well, you have written some data to the terminal. Now you probably want to put it somewhere. What now? The tty structure has a number of event hooks that you can attach your functions to.

These hooks are callbacks inside the tty structure that you can set. The callback fields are:

it's a place to put your private data in
after a character has been written to the screen; the cursor advances by width which might be 1 (regular) or 2 (CJK "fullwidth")
after the cursor has moved
after a chunk of screen has been cleared

If an endpoint spills outside of the current line, it will go all the way to an end of screen.

If the cursor moves, you'll get a separate l_cursor, although it is already in place during the l_clear call.

after the region s1<=y<s2 is scrolled nl lines (nl<0 -> backwards, nl>0 -> forward).

There's no separare l_cursor event, cx and cy are already updated.

when a flag changes to v. Flags that are likely to be of interest to you are:
  • VT100_FLAG_CURSOR

    cursor visibility

  • VT100_FLAG_KPAD

    application keypad mode (more detailed codes for keypad arrow keys)

when a string command has been issued; most commands alter a color palette, but the most interesting one is 0: "set window title"
after the terminal has been resized
when a write chunk ends
upon a beep
before the terminal is destroyed

Vt-on-vt redirection

For the case when you want the output go to a real terminal, there are:

Attaches the FILE stream f to terminal vt. Usually, f will be stdout. Whenever the contents of vt changes, appropriate data will be written to the stream as well. If dump is non-zero, the current state will be drawn, otherwise, only subsequent changes will be shown.

The redirection will last until the terminal is destroyed by tty_free().

Tells libtty that the real terminal has been resized (for resizing the virtual one, please use tty_resize()).
Forces a full-screen redraw of the current contents of vt.

SEE ALSO

libttyrec(3)

2020-04-20 UNKNOWN