logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

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

Description

Functions:ttytty_init(intsx,intsy,intresizable);
           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.

       inttty_resize(ttyvt,intnsx,intnsy);
           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.

       voidtty_reset(ttyvt);
           Clears the screen and attributes.

       voidtty_free(ttyvt);
           Deallocates the vt and all its internal structures.

       voidtty_write(ttyvt,constchar*buf,intlen);
           Writes len bytes into the terminal, parsing them as vt100 codes.

       voidtty_printf(ttyvt,constchar*fmt,...);
           Does a printf into the terminal.

       ttytty_copy(ttyvt);
           Allocates  a  new  vt100 terminal, making it an exact copy of an existing one, including its internal
           state.  Attached event callbacks are not copied.

       uint32_ttty_color_convert(uint32_tc,uint32_tto);
           Converts   color   values   between   modes:   VT100_COLOR_OFF,   VT100_COLOR_16,    VT100_COLOR_256,
           VT100_COLOR_RGB.

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

       tty {
       int sx,sy;             // screen size
       int cx,cy;             // cursor position
       attrchar *scr;         // screen buffer
       int attr;              // current attribute
       char *title;           // window title

       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.hTTYeventcallbacks
       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 eventhooks that you can attach your functions to.

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

       void*l_data;
           it's a place to put your private data in

       void(*l_char)(ttyvt,intx,inty,ucsch,intattr,intwidth);
           after  a  character  has  been  written  to the screen; the cursor advances by width which might be 1
           (regular) or 2 (CJK "fullwidth")

       void(*l_cursor)(ttyvt,intx,inty);
           after the cursor has moved

       void(*l_clear)(ttyvt,intx,inty,intlen);
           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.

       void(*l_scroll)(ttyvt,intnl);
           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.

       void(*l_flag)(ttyvt,intf,intv);
           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)

       void(*l_osc)(ttyvt,intcmd,constchar*str);
           when  a string command has been issued; most commands alter a color palette, but the most interesting
           one is 0: "set window title"

       void(*l_resize)(ttyvt,intsx,intsy);
           after the terminal has been resized

       void(*l_flush)(ttyvt);
           when a write chunk ends

       void(*l_bell)(ttyvt);
           upon a beep

       void(*l_free)(ttyvt);
           before the terminal is destroyed

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

       voidvtvt_attach(ttyvt,FILE*f,intdump);
           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().

       voidvtvt_resize(ttyvt,intsx,intsy);
           Tells libtty that the real terminal has been resized  (for  resizing  the  virtual  one,  please  use
           tty_resize()).

       voidvtvt_dump(ttyvt);
           Forces a full-screen redraw of the current contents of vt.

Name

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

See Also

libttyrec(3)

0.19                                               2024-04-01                                          LIBTTY(3)

Synopsis

#include<tty.h>

       Link with -ltty.

See Also