libt3window
|
Data Structures | |
struct | t3_term_caps_t |
Data structure to store information about the capabilities of the terminal. More... | |
Macros | |
#define | T3_CHILD(_x) |
Define a child anchor point a relation (see t3_win_anchor_t). | |
#define | T3_GETCHILD(_x) |
Get a child anchor point from a relation (see t3_win_anchor_t). | |
#define | T3_GETPARENT(_x) |
Get a parent anchor point from a relation (see t3_win_anchor_t). | |
#define | T3_PARENT(_x) |
Define a parent anchor point for a relation (see t3_win_anchor_t). | |
#define | T3_UTF8_CONTROL_MASK |
Category mask for libunistring's uc_is_general_category_withtable for finding control characters. | |
Typedefs | |
typedef char | t3_bool |
A boolean type that does not clash with C++ or C99 bool. | |
Enumerations | |
enum | { t3_false , t3_true } |
Values for t3_bool , a boolean type that does not clash with C++ or C99 bool. More... | |
enum | t3_win_anchor_t |
Anchor points for defining relations between the positions of two windows. More... | |
Functions | |
t3_bool | t3_term_acs_available (int idx) |
Check if a character is available in the alternate character set (internal use mostly). More... | |
t3_bool | t3_term_can_draw (const char *str, size_t str_len) |
These are implemented in convert_output.c. More... | |
t3_attr_t | t3_term_combine_attrs (t3_attr_t a, t3_attr_t b) |
Combine attributes, with priority. More... | |
void | t3_term_deinit (void) |
Free all memory allocated by libt3window. More... | |
void | t3_term_disable_ansi_optimization (void) |
Disable the ANSI terminal control sequence optimization. More... | |
void | t3_term_get_caps_internal (t3_term_caps_t *caps, int version) |
Get the terminal capabilities. More... | |
const char * | t3_term_get_codeset (void) |
Get the string describing the current character set used by the library. More... | |
int | t3_term_get_keychar (int msec) |
Get a key char from stdin with timeout. More... | |
int | t3_term_get_modifiers_hack (void) |
Retrieve the state of the modifiers using terminal specific hacks. More... | |
t3_attr_t | t3_term_get_ncv (void) |
Get the set of non-color video attributes. More... | |
void | t3_term_get_size (int *height, int *width) |
Retrieve the terminal size. More... | |
void | t3_term_hide_cursor (void) |
Hide the cursor. More... | |
int | t3_term_init (int fd, const char *term) |
Initialize the terminal. More... | |
t3_bool | t3_term_putc (char c) |
Add a charater to the output buffer. More... | |
t3_bool | t3_term_putn (const char *s, size_t n) |
Add a string to the output buffer. More... | |
void | t3_term_putp (const char *str) |
Send a terminal control string to the terminal, with correct padding. More... | |
t3_bool | t3_term_puts (const char *s) |
Add a string to the output buffer. More... | |
void | t3_term_redraw (void) |
Redraw the entire terminal from scratch. | |
t3_bool | t3_term_resize (void) |
Handle resizing of the terminal. More... | |
void | t3_term_restore (void) |
Restore terminal state (de-initialize). | |
void | t3_term_set_attrs (t3_attr_t new_attrs) |
Set terminal drawing attributes. More... | |
void | t3_term_set_cursor (int y, int x) |
Move cursor. More... | |
void | t3_term_set_replacement_char (int c) |
Set the replacement character used for undrawable characters. More... | |
void | t3_term_set_user_callback (t3_attr_user_callback_t callback) |
Set callback for drawing characters with T3_ATTR_USER attribute. More... | |
void | t3_term_show_cursor (void) |
Show the cursor. More... | |
size_t | t3_term_strcwidth (const char *str) |
Calculate the cell width of a string. More... | |
size_t | t3_term_strncwidth (const char *str, size_t n) |
Calculate the cell width of a string. More... | |
int | t3_term_strnwidth (const char *str, size_t n) |
Calculate the cell width of a string. More... | |
int | t3_term_strwidth (const char *str) |
Calculate the cell width of a string. More... | |
int | t3_term_unget_keychar (int c) |
Push a char back for later retrieval with t3_term_get_keychar. More... | |
void | t3_term_update (void) |
Update the terminal, drawing all changes since last refresh. More... | |
void | t3_term_update_cursor (void) |
Update the cursor, not drawing anything. | |
uint32_t | t3_utf8_get (const char *src, size_t *size) |
Get the first codepoint represented by a UTF-8 string. More... | |
size_t | t3_utf8_put (uint32_t c, char *dst) |
Convert a codepoint to a UTF-8 string. More... | |
int | t3_utf8_wcwidth (uint32_t c) |
Get the width of a Unicode codepoint. More... | |
int | t3_utf8_wcwidth_ext (uint32_t c, int *state) |
Get the width of a Unicode codepoint, taking previous state into account. More... | |
Variables | |
int | t3_term_caps_t::cap_flags |
A bitmask of T3_TERM_CAP_* flags indicating capabilities of the terminal. | |
int | t3_term_caps_t::colors |
The maximum number of supported colors, or 0 if color is not supported. | |
t3_attr_t | t3_term_caps_t::highlights |
The supported attributes other then color attributes. More... | |
int | t3_term_caps_t::pairs |
The maximum number of color pairs that are supported by this terminal, or 0 if color is not supported. | |
Attributes | |
enum | { T3_ACS_TTEE , T3_ACS_RTEE , T3_ACS_LTEE , T3_ACS_BTEE , T3_ACS_ULCORNER , T3_ACS_URCORNER , T3_ACS_LLCORNER , T3_ACS_LRCORNER , T3_ACS_HLINE , T3_ACS_VLINE , T3_ACS_UARROW , T3_ACS_DARROW , T3_ACS_LARROW , T3_ACS_RARROW , T3_ACS_BOARD , T3_ACS_CKBOARD , T3_ACS_BULLET , T3_ACS_DIAMOND , T3_ACS_BLOCK } |
Alternate character set symbolic constants. More... | |
#define | T3_ATTR_USER |
Use callback for drawing the characters. More... | |
#define | T3_ATTR_UNDERLINE |
Draw characters with underlining. | |
#define | T3_ATTR_BOLD |
Draw characters with bold face/bright appearance. | |
#define | T3_ATTR_REVERSE |
Draw characters with reverse video. | |
#define | T3_ATTR_BLINK |
Draw characters blinking. | |
#define | T3_ATTR_DIM |
Draw characters with dim appearance. | |
#define | T3_ATTR_ACS |
Draw characters with alternate character set (for line drawing etc). | |
#define | T3_ATTR_FALLBACK_ACS |
Draw characters with fallback alternate character set (for line drawing etc). More... | |
#define | T3_ATTR_COLOR_SHIFT |
Bit number of the least significant color attribute bit. | |
#define | T3_ATTR_FG(x) |
Convert a color number to a foreground color attribute. | |
#define | T3_ATTR_BG(x) |
Convert a color number to a background color attribute. | |
#define | T3_ATTR_FG_MASK |
Bitmask to leave only the foreground color in a t3_attr_t value. | |
#define | T3_ATTR_BG_MASK |
Bitmask to leave only the background color in a t3_attr_t value. | |
#define | T3_ATTR_FG_UNSPEC |
Foreground color unspecified. | |
#define | T3_ATTR_FG_DEFAULT |
Foreground color default. | |
#define | T3_ATTR_FG_BLACK |
Foreground color black. | |
#define | T3_ATTR_FG_RED |
Foreground color red. | |
#define | T3_ATTR_FG_GREEN |
Foreground color green. | |
#define | T3_ATTR_FG_YELLOW |
Foreground color yellow. | |
#define | T3_ATTR_FG_BLUE |
Foreground color blue. | |
#define | T3_ATTR_FG_MAGENTA |
Foreground color magenta. | |
#define | T3_ATTR_FG_CYAN |
Foreground color cyan. | |
#define | T3_ATTR_FG_WHITE |
Foreground color white. | |
#define | T3_ATTR_BG_UNSPEC |
Background color unspecified. | |
#define | T3_ATTR_BG_DEFAULT |
Background color default. | |
#define | T3_ATTR_BG_BLACK |
Background color black. | |
#define | T3_ATTR_BG_RED |
Background color red. | |
#define | T3_ATTR_BG_GREEN |
Background color green. | |
#define | T3_ATTR_BG_YELLOW |
Background color yellow. | |
#define | T3_ATTR_BG_BLUE |
Background color blue. | |
#define | T3_ATTR_BG_MAGENTA |
Background color magenta. | |
#define | T3_ATTR_BG_CYAN |
Background color cyan. | |
#define | T3_ATTR_BG_WHITE |
Background color white. | |
#define | T3_ATTR_UNDERLINE_SET |
Draw characters with underlining. | |
#define | T3_ATTR_BOLD_SET |
Draw characters with bold face/bright appearance. | |
#define | T3_ATTR_REVERSE_SET |
Draw characters with reverse video. | |
#define | T3_ATTR_BLINK_SET |
Draw characters blinking. | |
#define | T3_ATTR_DIM_SET |
Draw characters with dim appearance. | |
#define | T3_ATTR_SET_MASK |
#define | T3_TERM_KEY_CTRL |
#define | T3_TERM_KEY_META |
#define | T3_TERM_KEY_SHIFT |
Version information | |
typedef long | t3_attr_t |
Type to hold attributes used for terminal display. More... | |
typedef void(* | t3_attr_user_callback_t) (const char *str, int length, int width, t3_attr_t attr) |
User callback type. More... | |
long | t3_window_get_version (void) |
Get the value of T3_WINDOW_VERSION corresponding to the actually used library. More... | |
#define | T3_WINDOW_VERSION |
The version of libt3window encoded as a single integer. More... | |
#define | T3_TERM_CAP_FG |
Terminal capability flag: terminal can set foreground. | |
#define | T3_TERM_CAP_BG |
Terminal capability flag: terminal can set foreground. | |
#define | T3_TERM_CAP_CP |
Terminal capability flag: terminal uses color pairs for setting color. | |
Error codes (libt3window specific) | |
const char * | t3_window_strerror (int error) |
Get a string description for an error code. More... | |
#define | T3_ERR_NOT_A_TTY |
Error code: the file descriptor is not a terminal. | |
#define | T3_ERR_TIMEOUT |
Error code: a timeout occured. | |
#define | T3_ERR_NO_SIZE_INFO |
Error code: could not retrieve information about the size of the terminal window. | |
#define | T3_ERR_NONPRINT |
Error code: input contains non-printable characters. | |
#define | T3_ERR_CHARSET_ERROR |
Error code: could not open character-set conversion. | |
#define | T3_WARN_UPDATE_TERMINAL |
Error code: terminal feature detection has finished and the terminal should be updated. | |
Error codes (T3 generic) | |
#define | T3_ERR_SUCCESS |
Error code: success. | |
#define | T3_ERR_ERRNO |
Error code: see errno . | |
#define | T3_ERR_EOF |
Error code: end of file reached. | |
#define | T3_ERR_UNKNOWN |
Error code: unkown error. | |
#define | T3_ERR_BAD_ARG |
Error code: bad argument. | |
#define | T3_ERR_OUT_OF_MEMORY |
Error code: out of memory. | |
#define | T3_ERR_TERMINFODB_NOT_FOUND |
Error code: no information found for the terminal in the terminfo database. | |
#define | T3_ERR_HARDCOPY_TERMINAL |
Error code: the file descriptor is a hard-copy terminal. | |
#define | T3_ERR_TERMINAL_TOO_LIMITED |
Error code: terminal provides too limited possibilities for the library to function. | |
#define | T3_ERR_NO_TERM |
Error code: no terminal given and TERM environment variable not set. | |
#define | T3_ERR_INTERNAL |
Error code: internal error in the library. | |
#define | T3_WARN_MIN |
Warning code: the smallest value returned as warning. | |
#define T3_ATTR_FALLBACK_ACS |
Draw characters with fallback alternate character set (for line drawing etc).
This attribute will result if the terminal can not combine color video with drawing characters with the alternate character set. This attribute should not be used directly.
#define T3_ATTR_USER |
Use callback for drawing the characters.
When T3_ATTR_USER is set all other attribute bits are ignored. These can be used by the callback to determine the drawing style. The callback is set with t3_term_set_user_callback. Note that the callback is responsible for outputing the characters as well (using t3_term_putc).
#define T3_WINDOW_VERSION |
The version of libt3window encoded as a single integer.
The least significant 8 bits represent the patch level. The second 8 bits represent the minor version. The third 8 bits represent the major version.
At runtime, the value of T3_WINDOW_VERSION can be retrieved by calling ::t3_window_get_version.
Type to hold attributes used for terminal display.
The value of a t3_attr_t should be a bitwise or of T3_ATTR_* attribute values. When the terminal only supports setting colors by color pair, the T3_ATTR_FG macro can be used to specify the color pair to activate.
typedef void(* t3_attr_user_callback_t) (const char *str, int length, int width, t3_attr_t attr) |
User callback type.
The user callback is passed a pointer to the characters that are is marked with T3_ATTR_USER, the length of the string, the width of the string in display cells and the attributes they are drawn with.
anonymous enum |
Alternate character set symbolic constants.
anonymous enum |
enum t3_win_anchor_t |
Anchor points for defining relations between the positions of two windows.
The anchor points can be used to define the relative positioning of two windows. For example, using T3_PARENT(T3_ANCHOR_TOPRIGHT) | T3_CHILD(T3_ANCHOR_TOPLEFT) allows positioning of one window left of another.
t3_bool t3_term_acs_available | ( | int | idx | ) |
Check if a character is available in the alternate character set (internal use mostly).
idx | The character to check. |
Characters for which an alternate character is generally available are documented in terminfo(5), but most are encoded in T3_ACS_* constants.
t3_bool t3_term_can_draw | ( | const char * | str, |
size_t | str_len | ||
) |
These are implemented in convert_output.c.
These are implemented in convert_output.c.
str | The UTF-8 string representing the character to be displayed. |
str_len | The length of str. |
Note that str may contain combining characters, which will only be drawn correctly if a precomposed character is available or the terminal supports them. And even if the terminal supports combining characters they may not be correctly rendered, depending on the combination of combining marks.
Moreover, the font the terminal is using may not have a glyph available for the requested character. Therefore, if this function determines that the character can be drawn, it may still not be correctly represented on screen.
Combine attributes, with priority.
a | The first set of attributes to combine (priority). |
b | The second set of attributes to combine (no priority). |
This function combines a
and b
, with the color attributes from a
overriding the color attributes from b
if both specify colors. Note that if b
has an attribute that was explicitly set (indicated by the corresponding _SET
value), and a
does not have the corresponding _SET
bit, the value of b
will be taken. The background is that this allows distinction between "the default should be used" (without the _SET
bit) and "this bit is
explicitly cleared" (with the _SET
bit).
void t3_term_deinit | ( | void | ) |
Free all memory allocated by libt3window.
This function releases all memory allocated by libt3window, and allows libt3window to be initialized for a new terminal.
void t3_term_disable_ansi_optimization | ( | void | ) |
Disable the ANSI terminal control sequence optimization.
T3WINDOW_OPTS=ansi=off
. void t3_term_get_caps_internal | ( | t3_term_caps_t * | caps, |
int | version | ||
) |
Get the terminal capabilities.
caps | The location to store the capabilities. |
version | The version of the library used when compiling (should be T3_WINDOW_VERSION). |
This function can be used to obtain the supported video attributes and other information about the capabilities of the terminal. To allow different ABI versions to live together, the version number of the library used when compiling the call to this function must be passed.
const char* t3_term_get_codeset | ( | void | ) |
Get the string describing the current character set used by the library.
The reason this function is provided, is that although the library initially will use the result of transcript_get_codeset
, the terminal-capabilities detection may result in a different character set being used. After receiving T3_WARN_UPDATE_TERMINAL from t3_term_get_keychar, this routine may return a different value.
int t3_term_get_keychar | ( | int | msec | ) |
Get a key char
from stdin with timeout.
msec | The timeout in miliseconds, or a value <= 0 for indefinite wait. |
>=0 | A char read from stdin. |
T3_ERR_ERRNO | on error, with errno set to the error. |
T3_ERR_EOF | on end of file. |
T3_ERR_TIMEOUT | if there was no character to read within the specified timeout. |
T3_WARN_UPDATE_TERMINAL | if the terminal-feature detection has finished and requires that the terminal is updated. Note: this is not an error, but a signal to update the terminal. To check for errors, use: t3_term_get_keychar(msec) < T3_WARN_MIN
#define T3_WARN_MIN Warning code: the smallest value returned as warning. Definition: window_errors.h:51 int t3_term_get_keychar(int msec) Get a key char from stdin with timeout. Definition: input.c:253 |
int t3_term_get_modifiers_hack | ( | void | ) |
Retrieve the state of the modifiers using terminal specific hacks.
This function can be used to retrieve the modifier state from the terminal, if the terminal provides a method for querying the corrent modifier state. One example of such a terminal is the linux console. Using this function is basically a hack to get at state that is not encoded in the key sequence, and is not the prefered way of accessing this data. For some terminals this is however the only way to get at this data.
t3_attr_t t3_term_get_ncv | ( | void | ) |
Get the set of non-color video attributes.
Non-color video attributes are attributes that can not be combined with the color attributes. It is unspecified what will happen when the are combined.
void t3_term_get_size | ( | int * | height, |
int * | width | ||
) |
Retrieve the terminal size.
height | The location to store the terminal height in lines. |
width | The location to store the terminal height in columns. |
Neither height
nor width
may be NULL
.
void t3_term_hide_cursor | ( | void | ) |
Hide the cursor.
Instructs the terminal to make the cursor invisible. If the terminal does not provide the required functionality, the cursor is moved to the bottom right.
int t3_term_init | ( | int | fd, |
const char * | term | ||
) |
Initialize the terminal.
fd | The file descriptor of the terminal or -1 for default. |
term | The name of the terminal, or NULL to use the TERM environment variable. |
This function depends on the correct setting of the LC_CTYPE
property by the setlocale
function. Therefore, the setlocale
function should be called before this function.
If standard input/output should be used as the terminal, -1 should be passed. When calling t3_term_init multiple times (necessary when t3_term_restore was called), only the first successful call will inspect the fd
and term
parameters.
The terminal is initialized to raw mode such that echo is disabled (characters typed are not shown), control characters are passed to the program (i.e. ctrl-c will result in a character rather than a TERM signal) and generally all characters typed are passed to the program immediately and with a minimum of pre-processing.
t3_bool t3_term_putc | ( | char | c | ) |
Add a charater to the output buffer.
c | The character to add. |
The character passed as c
is a single char
, not a unicode codepoint. This function should not be used outside the callback set with t3_term_set_user_callback.
t3_bool t3_term_putn | ( | const char * | s, |
size_t | n | ||
) |
Add a string to the output buffer.
s | The string to add. |
n | The length of s . |
This function should not be used outside the callback set with t3_term_set_user_callback.
void t3_term_putp | ( | const char * | str | ) |
Send a terminal control string to the terminal, with correct padding.
t3_bool t3_term_puts | ( | const char * | s | ) |
Add a string to the output buffer.
s | The string to add. |
This function should not be used outside the callback set with t3_term_set_user_callback.
t3_bool t3_term_resize | ( | void | ) |
Handle resizing of the terminal.
Should be called after a SIGWINCH
. Retrieves the size of the terminal and resizes the backing structures. After calling t3_term_resize, t3_term_get_size can be called to retrieve the new terminal size.
void t3_term_set_attrs | ( | t3_attr_t | new_attrs | ) |
Set terminal drawing attributes.
new_attrs | The new attributes that should be used for subsequent character display. |
void t3_term_set_cursor | ( | int | y, |
int | x | ||
) |
Move cursor.
y | The terminal line to move the cursor to. |
x | The terminal column to move the cursor to. |
If the cursor is invisible the new position is recorded, but not actually moved yet. Moving the cursor takes effect immediately.
void t3_term_set_replacement_char | ( | int | c | ) |
Set the replacement character used for undrawable characters.
c | The character to draw when an undrawable characters is encountered. |
The default character is the question mark ('?'). The character must be a Unicode character representable in the current character set. For terminals capable of Unicode output the Replacement Character is used (codepoint FFFD).
void t3_term_set_user_callback | ( | t3_attr_user_callback_t | callback | ) |
Set callback for drawing characters with T3_ATTR_USER attribute.
callback | The function to call for drawing. |
void t3_term_show_cursor | ( | void | ) |
Show the cursor.
Instructs the terminal to make the cursor visible.
size_t t3_term_strcwidth | ( | const char * | str | ) |
Calculate the cell width of a string.
str | The string to calculate the width of. |
Using strlen
on a string will not give one the correct width of a UTF-8 string on the terminal screen. This function is provided to calculate that value.
size_t t3_term_strncwidth | ( | const char * | str, |
size_t | n | ||
) |
Calculate the cell width of a string.
str | The string to calculate the width of. |
n | The length of str . |
Using strlen
on a string will not give one the correct width of a UTF-8 string on the terminal screen. This function is provided to calculate that value.
int t3_term_strnwidth | ( | const char * | str, |
size_t | n | ||
) |
Calculate the cell width of a string.
int t3_term_strwidth | ( | const char * | str | ) |
Calculate the cell width of a string.
int t3_term_unget_keychar | ( | int | c | ) |
Push a char
back for later retrieval with t3_term_get_keychar.
c | The char to push back. |
char
pushed back or T3_ERR_BAD_ARG.Only a char
just read from stdin with t3_term_get_keychar can be pushed back.
void t3_term_update | ( | void | ) |
Update the terminal, drawing all changes since last refresh.
After changing window contents, this function should be called to make those changes visible on the terminal. The refresh is not done automatically to allow programs to bunch many separate updates. Generally this is called right before t3_term_get_keychar.
uint32_t t3_utf8_get | ( | const char * | src, |
size_t * | size | ||
) |
Get the first codepoint represented by a UTF-8 string.
src | The UTF-8 string to parse. |
size | The location to store the number of bytes in the first codepoint, which should contain the number of bytes in src on entry (may be NULL ). |
src
or FFFD
if an invalid codepoint is encountered. size_t t3_utf8_put | ( | uint32_t | c, |
char * | dst | ||
) |
Convert a codepoint to a UTF-8 string.
c | The codepoint to convert. |
dst | The location to store the result. |
dst
.If an invalid codepoint is passed in c
, the replacement character (FFFD
) is stored instead
int t3_utf8_wcwidth | ( | uint32_t | c | ) |
Get the width of a Unicode codepoint.
This function returns the width of a codepoint as a terminal would print it. This is mostly similar to the result of wcwidth, with the exception of some characters where terminals actually use a different value.
int t3_utf8_wcwidth_ext | ( | uint32_t | c, |
int * | state | ||
) |
Get the width of a Unicode codepoint, taking previous state into account.
Like t3_utf8_wcwidth, but with the added possibility to track the state of conjoining Jamo, which modifies the width of some characters.
state
should be initialized with 0.
long t3_window_get_version | ( | void | ) |
Get the value of T3_WINDOW_VERSION corresponding to the actually used library.
This function can be useful to determine at runtime what version of the library was linked to the program. Although currently there are no known uses for this information, future library additions may prompt library users to want to operate differently depending on the available features.
const char* t3_window_strerror | ( | int | error | ) |
Get a string description for an error code.
error | The error code returned by a function in libt3window. |
t3_attr_t t3_term_caps_t::highlights |
The supported attributes other then color attributes.
This is a bitmask of T3_ATTR_* flags.