namespace TERM_REC functions (conflict with curses.h)

This commit is contained in:
Ailin Nemui 2025-04-08 08:04:21 +02:00
parent 7bac5eb762
commit 382bde9ab3
3 changed files with 148 additions and 154 deletions

View File

@ -369,8 +369,8 @@ void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigne
if (!term_use_colors && bg > 0) if (!term_use_colors && bg > 0)
col |= ATTR_REVERSE; col |= ATTR_REVERSE;
set_normal = ((col & ATTR_RESETFG) && last_fg != COLOR_RESET) || set_normal = ((col & ATTR_RESETFG) && last_fg != COLOR_RESET) ||
((col & ATTR_RESETBG) && last_bg != COLOR_RESET); ((col & ATTR_RESETBG) && last_bg != COLOR_RESET);
if (((last_attrs & ATTR_BOLD) && (col & ATTR_BOLD) == 0) || if (((last_attrs & ATTR_BOLD) && (col & ATTR_BOLD) == 0) ||
((last_attrs & ATTR_REVERSE) && (col & ATTR_REVERSE) == 0) || ((last_attrs & ATTR_REVERSE) && (col & ATTR_REVERSE) == 0) ||
((last_attrs & ATTR_BLINK) && (col & ATTR_BLINK) == 0)) { ((last_attrs & ATTR_BLINK) && (col & ATTR_BLINK) == 0)) {
@ -381,19 +381,17 @@ void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigne
if (set_normal) { if (set_normal) {
last_fg = last_bg = COLOR_RESET; last_fg = last_bg = COLOR_RESET;
last_attrs = 0; last_attrs = 0;
terminfo_set_normal(); terminfo_set_normal();
} }
/* set foreground color */ /* set foreground color */
if (fg != last_fg && if (fg != last_fg && (fg != 0 || (col & ATTR_RESETFG) == 0)) {
(fg != 0 || (col & ATTR_RESETFG) == 0)) { if (term_use_colors) {
if (term_use_colors) {
last_fg = fg; last_fg = fg;
if (fg >> 8) if (fg >> 8)
termctl_set_color_24bit(0, termctl_set_color_24bit(0, last_fg == COLOR_BLACK24 ? 0 :
last_fg == COLOR_BLACK24 ? 0 last_fg >> 8);
: last_fg >> 8);
else else
terminfo_set_fg(last_fg); terminfo_set_fg(last_fg);
} }
@ -401,19 +399,17 @@ void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigne
/* set background color */ /* set background color */
if (window && window->term->TI_colors && if (window && window->term->TI_colors &&
(term_color256map[bg&0xff]&8) == window->term->TI_colors) (term_color256map[bg & 0xff] & 8) == window->term->TI_colors)
col |= ATTR_BLINK; col |= ATTR_BLINK;
if (col & ATTR_BLINK) if (col & ATTR_BLINK)
current_term->set_blink(current_term); current_term->tr_set_blink(current_term);
if (bg != last_bg && if (bg != last_bg && (bg != 0 || (col & ATTR_RESETBG) == 0)) {
(bg != 0 || (col & ATTR_RESETBG) == 0)) { if (term_use_colors) {
if (term_use_colors) {
last_bg = bg; last_bg = bg;
if (bg >> 8) if (bg >> 8)
termctl_set_color_24bit(1, termctl_set_color_24bit(1, last_bg == COLOR_BLACK24 ? 0 :
last_bg == COLOR_BLACK24 ? 0 last_bg >> 8);
: last_bg >> 8);
else else
terminfo_set_bg(last_bg); terminfo_set_bg(last_bg);
} }
@ -425,7 +421,7 @@ void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigne
/* bold */ /* bold */
if (window && window->term->TI_colors && if (window && window->term->TI_colors &&
(term_color256map[fg&0xff]&8) == window->term->TI_colors) (term_color256map[fg & 0xff] & 8) == window->term->TI_colors)
col |= ATTR_BOLD; col |= ATTR_BOLD;
if (col & ATTR_BOLD) if (col & ATTR_BOLD)
terminfo_set_bold(); terminfo_set_bold();
@ -445,7 +441,7 @@ void term_set_color2(TERM_WINDOW *window, int col, unsigned int fgcol24, unsigne
terminfo_set_italic(FALSE); terminfo_set_italic(FALSE);
/* update the new attribute settings whilst ignoring color values. */ /* update the new attribute settings whilst ignoring color values. */
last_attrs = col & ~( BG_MASK | FG_MASK ); last_attrs = col & ~(BG_MASK | FG_MASK);
} }
void term_move(TERM_WINDOW *window, int x, int y) void term_move(TERM_WINDOW *window, int x, int y)

View File

@ -172,20 +172,20 @@ static void _set_cursor_visible(TERM_REC *term, int set)
/* Scroll (change_scroll_region+parm_rindex+parm_index / csr+rin+indn) */ /* Scroll (change_scroll_region+parm_rindex+parm_index / csr+rin+indn) */
static void _scroll_region(TERM_REC *term, int y1, int y2, int count) static void _scroll_region(TERM_REC *term, int y1, int y2, int count)
{ {
/* setup the scrolling region to wanted area */ /* setup the scrolling region to wanted area */
scroll_region_setup(term, y1, y2); scroll_region_setup(term, y1, y2);
term->move(term, 0, y1); term->tr_move(term, 0, y1);
if (count > 0) { if (count > 0) {
term->move(term, 0, y2); term->tr_move(term, 0, y2);
tput(tparm(term->TI_indn, count, count, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_indn, count, count, 0, 0, 0, 0, 0, 0, 0));
} else if (count < 0) { } else if (count < 0) {
term->move(term, 0, y1); term->tr_move(term, 0, y1);
tput(tparm(term->TI_rin, -count, -count, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_rin, -count, -count, 0, 0, 0, 0, 0, 0, 0));
} }
/* reset the scrolling region to full screen */ /* reset the scrolling region to full screen */
scroll_region_setup(term, 0, term->height-1); scroll_region_setup(term, 0, term->height - 1);
} }
/* Scroll (change_scroll_region+scroll_reverse+scroll_forward / csr+ri+ind) */ /* Scroll (change_scroll_region+scroll_reverse+scroll_forward / csr+ri+ind) */
@ -193,21 +193,21 @@ static void _scroll_region_1(TERM_REC *term, int y1, int y2, int count)
{ {
int i; int i;
/* setup the scrolling region to wanted area */ /* setup the scrolling region to wanted area */
scroll_region_setup(term, y1, y2); scroll_region_setup(term, y1, y2);
if (count > 0) { if (count > 0) {
term->move(term, 0, y2); term->tr_move(term, 0, y2);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
tput(tparm(term->TI_ind, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_ind, 0, 0, 0, 0, 0, 0, 0, 0, 0));
} else if (count < 0) { } else if (count < 0) {
term->move(term, 0, y1); term->tr_move(term, 0, y1);
for (i = count; i < 0; i++) for (i = count; i < 0; i++)
tput(tparm(term->TI_ri, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_ri, 0, 0, 0, 0, 0, 0, 0, 0, 0));
} }
/* reset the scrolling region to full screen */ /* reset the scrolling region to full screen */
scroll_region_setup(term, 0, term->height-1); scroll_region_setup(term, 0, term->height - 1);
} }
/* Scroll (parm_insert_line+parm_delete_line / il+dl) */ /* Scroll (parm_insert_line+parm_delete_line / il+dl) */
@ -216,22 +216,22 @@ static void _scroll_line(TERM_REC *term, int y1, int y2, int count)
/* setup the scrolling region to wanted area - /* setup the scrolling region to wanted area -
this might not necessarily work with il/dl, but at least it this might not necessarily work with il/dl, but at least it
looks better if it does */ looks better if it does */
scroll_region_setup(term, y1, y2); scroll_region_setup(term, y1, y2);
if (count > 0) { if (count > 0) {
term->move(term, 0, y1); term->tr_move(term, 0, y1);
tput(tparm(term->TI_dl, count, count, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_dl, count, count, 0, 0, 0, 0, 0, 0, 0));
term->move(term, 0, y2-count+1); term->tr_move(term, 0, y2 - count + 1);
tput(tparm(term->TI_il, count, count, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_il, count, count, 0, 0, 0, 0, 0, 0, 0));
} else if (count < 0) { } else if (count < 0) {
term->move(term, 0, y2+count+1); term->tr_move(term, 0, y2 + count + 1);
tput(tparm(term->TI_dl, -count, -count, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_dl, -count, -count, 0, 0, 0, 0, 0, 0, 0));
term->move(term, 0, y1); term->tr_move(term, 0, y1);
tput(tparm(term->TI_il, -count, -count, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_il, -count, -count, 0, 0, 0, 0, 0, 0, 0));
} }
/* reset the scrolling region to full screen */ /* reset the scrolling region to full screen */
scroll_region_setup(term, 0, term->height-1); scroll_region_setup(term, 0, term->height - 1);
} }
/* Scroll (insert_line+delete_line / il1+dl1) */ /* Scroll (insert_line+delete_line / il1+dl1) */
@ -240,17 +240,17 @@ static void _scroll_line_1(TERM_REC *term, int y1, int y2, int count)
int i; int i;
if (count > 0) { if (count > 0) {
term->move(term, 0, y1); term->tr_move(term, 0, y1);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
tput(tparm(term->TI_dl1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_dl1, 0, 0, 0, 0, 0, 0, 0, 0, 0));
term->move(term, 0, y2-count+1); term->tr_move(term, 0, y2 - count + 1);
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
tput(tparm(term->TI_il1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_il1, 0, 0, 0, 0, 0, 0, 0, 0, 0));
} else if (count < 0) { } else if (count < 0) {
term->move(term, 0, y2+count+1); term->tr_move(term, 0, y2 + count + 1);
for (i = count; i < 0; i++) for (i = count; i < 0; i++)
tput(tparm(term->TI_dl1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_dl1, 0, 0, 0, 0, 0, 0, 0, 0, 0));
term->move(term, 0, y1); term->tr_move(term, 0, y1);
for (i = count; i < 0; i++) for (i = count; i < 0; i++)
tput(tparm(term->TI_il1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_il1, 0, 0, 0, 0, 0, 0, 0, 0, 0));
} }
@ -265,14 +265,14 @@ static void _clear_screen(TERM_REC *term)
/* Clear screen (clr_eos / ed) */ /* Clear screen (clr_eos / ed) */
static void _clear_eos(TERM_REC *term) static void _clear_eos(TERM_REC *term)
{ {
term->move(term, 0, 0); term->tr_move(term, 0, 0);
tput(tparm(term->TI_ed, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_ed, 0, 0, 0, 0, 0, 0, 0, 0, 0));
} }
/* Clear screen (parm_delete_line / dl) */ /* Clear screen (parm_delete_line / dl) */
static void _clear_del(TERM_REC *term) static void _clear_del(TERM_REC *term)
{ {
term->move(term, 0, 0); term->tr_move(term, 0, 0);
tput(tparm(term->TI_dl, term->height, term->height, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_dl, term->height, term->height, 0, 0, 0, 0, 0, 0, 0));
} }
@ -281,8 +281,8 @@ static void _clear_del_1(TERM_REC *term)
{ {
int i; int i;
term->move(term, 0, 0); term->tr_move(term, 0, 0);
for (i = 0; i < term->height; i++) for (i = 0; i < term->height; i++)
tput(tparm(term->TI_dl1, 0, 0, 0, 0, 0, 0, 0, 0, 0)); tput(tparm(term->TI_dl1, 0, 0, 0, 0, 0, 0, 0, 0, 0));
} }
@ -455,10 +455,7 @@ static void terminfo_colors_deinit(TERM_REC *term)
terminal capabilities don't contain color codes */ terminal capabilities don't contain color codes */
void terminfo_setup_colors(TERM_REC *term, int force) void terminfo_setup_colors(TERM_REC *term, int force)
{ {
static const char ansitab[16] = { static const char ansitab[16] = { 0, 4, 2, 6, 1, 5, 3, 7, 8, 12, 10, 14, 9, 13, 11, 15 };
0, 4, 2, 6, 1, 5, 3, 7,
8, 12, 10, 14, 9, 13, 11, 15
};
unsigned int i, color; unsigned int i, color;
terminfo_colors_deinit(term); terminfo_colors_deinit(term);
@ -466,16 +463,15 @@ void terminfo_setup_colors(TERM_REC *term, int force)
if (force && term->TI_setf == NULL && term->TI_setaf == NULL) if (force && term->TI_setf == NULL && term->TI_setaf == NULL)
term->TI_colors = 8; term->TI_colors = 8;
if ((term->TI_setf || term->TI_setaf || force) && if ((term->TI_setf || term->TI_setaf || force) && term->TI_colors > 0) {
term->TI_colors > 0) {
term->TI_fg = g_new0(char *, term->TI_colors); term->TI_fg = g_new0(char *, term->TI_colors);
term->TI_bg = g_new0(char *, term->TI_colors); term->TI_bg = g_new0(char *, term->TI_colors);
term->set_fg = _set_fg; term->tr_set_fg = _set_fg;
term->set_bg = _set_bg; term->tr_set_bg = _set_bg;
} else { } else {
/* no colors */ /* no colors */
term->TI_colors = 0; term->TI_colors = 0;
term->set_fg = term->set_bg = _ignore_parm; term->tr_set_fg = term->tr_set_bg = _ignore_parm;
} }
if (term->TI_setaf) { if (term->TI_setaf) {
@ -489,7 +485,7 @@ void terminfo_setup_colors(TERM_REC *term, int force)
term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0, 0, 0, 0, 0, 0, 0, 0)); term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0, 0, 0, 0, 0, 0, 0, 0));
} else if (force) { } else if (force) {
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
term->TI_fg[i] = g_strdup_printf("\033[%dm", 30+ansitab[i]); term->TI_fg[i] = g_strdup_printf("\033[%dm", 30 + ansitab[i]);
} }
if (term->TI_setab) { if (term->TI_setab) {
@ -503,7 +499,7 @@ void terminfo_setup_colors(TERM_REC *term, int force)
term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 0, 0, 0, 0, 0, 0, 0, 0)); term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 0, 0, 0, 0, 0, 0, 0, 0));
} else if (force) { } else if (force) {
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
term->TI_bg[i] = g_strdup_printf("\033[%dm", 40+ansitab[i]); term->TI_bg[i] = g_strdup_printf("\033[%dm", 40 + ansitab[i]);
} }
} }
@ -581,12 +577,12 @@ static int term_setup(TERM_REC *term)
{ {
GString *str; GString *str;
int err; int err;
char *term_env; char *term_env;
term_env = getenv("TERM"); term_env = getenv("TERM");
if (term_env == NULL) { if (term_env == NULL) {
fprintf(stderr, "TERM environment not set\n"); fprintf(stderr, "TERM environment not set\n");
return 0; return 0;
} }
if (setupterm(term_env, 1, &err) != 0) { if (setupterm(term_env, 1, &err) != 0) {
@ -594,98 +590,99 @@ static int term_setup(TERM_REC *term)
return 0; return 0;
} }
term_fill_capabilities(term); term_fill_capabilities(term);
/* Cursor movement */ /* Cursor movement */
if (term->TI_cup) if (term->TI_cup)
term->move = _move_cup; term->tr_move = _move_cup;
else if (term->TI_hpa && term->TI_vpa) else if (term->TI_hpa && term->TI_vpa)
term->move = _move_pa; term->tr_move = _move_pa;
else { else {
fprintf(stderr, "Terminal doesn't support cursor movement\n"); fprintf(stderr, "Terminal doesn't support cursor movement\n");
return 0; return 0;
} }
term->move_relative = _move_relative; term->tr_move_relative = _move_relative;
term->set_cursor_visible = term->TI_civis && term->TI_cnorm ? term->tr_set_cursor_visible =
_set_cursor_visible : _ignore_parm; term->TI_civis && term->TI_cnorm ? _set_cursor_visible : _ignore_parm;
/* Scrolling */ /* Scrolling */
if ((term->TI_csr || term->TI_wind) && term->TI_rin && term->TI_indn) if ((term->TI_csr || term->TI_wind) && term->TI_rin && term->TI_indn)
term->scroll = _scroll_region; term->tr_scroll = _scroll_region;
else if (term->TI_il && term->TI_dl) else if (term->TI_il && term->TI_dl)
term->scroll = _scroll_line; term->tr_scroll = _scroll_line;
else if ((term->TI_csr || term->TI_wind) && term->TI_ri && term->TI_ind) else if ((term->TI_csr || term->TI_wind) && term->TI_ri && term->TI_ind)
term->scroll = _scroll_region_1; term->tr_scroll = _scroll_region_1;
else if (term->scroll == NULL && (term->TI_il1 && term->TI_dl1)) else if (term->tr_scroll == NULL && (term->TI_il1 && term->TI_dl1))
term->scroll = _scroll_line_1; term->tr_scroll = _scroll_line_1;
else if (term->scroll == NULL) { else if (term->tr_scroll == NULL) {
fprintf(stderr, "Terminal doesn't support scrolling\n"); fprintf(stderr, "Terminal doesn't support scrolling\n");
return 0; return 0;
} }
/* Clearing screen */ /* Clearing screen */
if (term->TI_clear) if (term->TI_clear)
term->clear = _clear_screen; term->tr_clear = _clear_screen;
else if (term->TI_ed) else if (term->TI_ed)
term->clear = _clear_eos; term->tr_clear = _clear_eos;
else if (term->TI_dl) else if (term->TI_dl)
term->clear = _clear_del; term->tr_clear = _clear_del;
else if (term->TI_dl1) else if (term->TI_dl1)
term->clear = _clear_del_1; term->tr_clear = _clear_del_1;
else { else {
/* we could do this by line inserts as well, but don't /* we could do this by line inserts as well, but don't
bother - if some terminal has insert line it most probably bother - if some terminal has insert line it most probably
has delete line as well, if not a regular clear screen */ has delete line as well, if not a regular clear screen */
fprintf(stderr, "Terminal doesn't support clearing screen\n"); fprintf(stderr, "Terminal doesn't support clearing screen\n");
return 0; return 0;
} }
/* Clearing to end of line */ /* Clearing to end of line */
if (term->TI_el) if (term->TI_el)
term->clrtoeol = _clrtoeol; term->tr_clrtoeol = _clrtoeol;
else { else {
fprintf(stderr, "Terminal doesn't support clearing to end of line\n"); fprintf(stderr, "Terminal doesn't support clearing to end of line\n");
return 0; return 0;
} }
/* Repeating character */ /* Repeating character */
if (term->TI_rep) if (term->TI_rep)
term->repeat = _repeat; term->tr_repeat = _repeat;
else else
term->repeat = _repeat_manual; term->tr_repeat = _repeat_manual;
/* Bold, underline, standout, reverse, italics */ /* Bold, underline, standout, reverse, italics */
term->set_blink = term->TI_blink ? _set_blink : _ignore; term->tr_set_blink = term->TI_blink ? _set_blink : _ignore;
term->set_bold = term->TI_bold ? _set_bold : _ignore; term->tr_set_bold = term->TI_bold ? _set_bold : _ignore;
term->set_reverse = term->TI_rev ? _set_reverse : term->tr_set_reverse = term->TI_rev ? _set_reverse :
term->TI_smso ? _set_standout_on : _ignore; term->TI_smso ? _set_standout_on :
term->set_uline = term->TI_smul && term->TI_rmul ? _ignore;
_set_uline : _ignore_parm; term->tr_set_uline = term->TI_smul && term->TI_rmul ? _set_uline : _ignore_parm;
term->set_standout = term->TI_smso && term->TI_rmso ? term->tr_set_standout = term->TI_smso && term->TI_rmso ? _set_standout : _ignore_parm;
_set_standout : _ignore_parm; term->tr_set_italic = term->TI_sitm && term->TI_ritm ? _set_italic : _ignore_parm;
term->set_italic = term->TI_sitm && term->TI_ritm ?
_set_italic : _ignore_parm;
/* Create a string to set all attributes off */ /* Create a string to set all attributes off */
str = g_string_new(NULL); str = g_string_new(NULL);
if (term->TI_sgr0) if (term->TI_sgr0)
g_string_append(str, term->TI_sgr0); g_string_append(str, term->TI_sgr0);
if (term->TI_rmul && (term->TI_sgr0 == NULL || g_strcmp0(term->TI_rmul, term->TI_sgr0) != 0)) if (term->TI_rmul &&
(term->TI_sgr0 == NULL || g_strcmp0(term->TI_rmul, term->TI_sgr0) != 0))
g_string_append(str, term->TI_rmul); g_string_append(str, term->TI_rmul);
if (term->TI_rmso && (term->TI_sgr0 == NULL || g_strcmp0(term->TI_rmso, term->TI_sgr0) != 0)) if (term->TI_rmso &&
(term->TI_sgr0 == NULL || g_strcmp0(term->TI_rmso, term->TI_sgr0) != 0))
g_string_append(str, term->TI_rmso); g_string_append(str, term->TI_rmso);
if (term->TI_ritm && (term->TI_sgr0 == NULL || g_strcmp0(term->TI_ritm, term->TI_sgr0) != 0)) if (term->TI_ritm &&
(term->TI_sgr0 == NULL || g_strcmp0(term->TI_ritm, term->TI_sgr0) != 0))
g_string_append(str, term->TI_ritm); g_string_append(str, term->TI_ritm);
term->TI_normal = str->str; term->TI_normal = str->str;
g_string_free(str, FALSE); g_string_free(str, FALSE);
term->set_normal = _set_normal; term->tr_set_normal = _set_normal;
term->beep = term->TI_bel ? _beep : _ignore; term->tr_beep = term->TI_bel ? _beep : _ignore;
terminfo_setup_colors(term, FALSE); terminfo_setup_colors(term, FALSE);
terminfo_input_init0(term); terminfo_input_init0(term);
terminfo_cont(term); terminfo_cont(term);
return 1; return 1;
} }
void term_set_appkey_mode(int enable) void term_set_appkey_mode(int enable)
@ -730,14 +727,14 @@ void terminfo_core_deinit(TERM_REC *term)
TERM_REC *old_term; TERM_REC *old_term;
old_term = current_term; old_term = current_term;
current_term = term; current_term = term;
term->set_normal(term); term->tr_set_normal(term);
current_term = old_term; current_term = old_term;
terminfo_stop(term); terminfo_stop(term);
g_free(term->TI_normal); g_free(term->TI_normal);
terminfo_colors_deinit(term); terminfo_colors_deinit(term);
g_free(term); g_free(term);
} }

View File

@ -3,48 +3,49 @@
#include <termios.h> #include <termios.h>
#define terminfo_move(x, y) current_term->move(current_term, x, y) #define terminfo_move(x, y) current_term->tr_move(current_term, x, y)
#define terminfo_move_relative(oldx, oldy, x, y) current_term->move_relative(current_term, oldx, oldy, x, y) #define terminfo_move_relative(oldx, oldy, x, y) \
#define terminfo_set_cursor_visible(set) current_term->set_cursor_visible(current_term, set) current_term->tr_move_relative(current_term, oldx, oldy, x, y)
#define terminfo_scroll(y1, y2, count) current_term->scroll(current_term, y1, y2, count) #define terminfo_set_cursor_visible(set) current_term->tr_set_cursor_visible(current_term, set)
#define terminfo_clear() current_term->clear(current_term) #define terminfo_scroll(y1, y2, count) current_term->tr_scroll(current_term, y1, y2, count)
#define terminfo_clrtoeol() current_term->clrtoeol(current_term) #define terminfo_clear() current_term->tr_clear(current_term)
#define terminfo_repeat(chr, count) current_term->repeat(current_term, chr, count) #define terminfo_clrtoeol() current_term->tr_clrtoeol(current_term)
#define terminfo_set_fg(color) current_term->set_fg(current_term, color) #define terminfo_repeat(chr, count) current_term->tr_repeat(current_term, chr, count)
#define terminfo_set_bg(color) current_term->set_bg(current_term, color) #define terminfo_set_fg(color) current_term->tr_set_fg(current_term, color)
#define terminfo_set_normal() current_term->set_normal(current_term) #define terminfo_set_bg(color) current_term->tr_set_bg(current_term, color)
#define terminfo_set_bold() current_term->set_bold(current_term) #define terminfo_set_normal() current_term->tr_set_normal(current_term)
#define terminfo_set_uline(set) current_term->set_uline(current_term, set) #define terminfo_set_bold() current_term->tr_set_bold(current_term)
#define terminfo_set_standout(set) current_term->set_standout(current_term, set) #define terminfo_set_uline(set) current_term->tr_set_uline(current_term, set)
#define terminfo_set_reverse() current_term->set_reverse(current_term) #define terminfo_set_standout(set) current_term->tr_set_standout(current_term, set)
#define terminfo_set_italic(set) current_term->set_italic(current_term, set) #define terminfo_set_reverse() current_term->tr_set_reverse(current_term)
#define terminfo_set_italic(set) current_term->tr_set_italic(current_term, set)
#define terminfo_is_colors_set(term) (term->TI_fg != NULL) #define terminfo_is_colors_set(term) (term->TI_fg != NULL)
#define terminfo_beep(term) current_term->beep(current_term) #define terminfo_beep(term) current_term->tr_beep(current_term)
typedef struct _TERM_REC TERM_REC; typedef struct _TERM_REC TERM_REC;
struct _TERM_REC { struct _TERM_REC {
/* Functions */ /* Functions */
void (*move)(TERM_REC *term, int x, int y); void (*tr_move)(TERM_REC *term, int x, int y);
void (*move_relative)(TERM_REC *term, int oldx, int oldy, int x, int y); void (*tr_move_relative)(TERM_REC *term, int oldx, int oldy, int x, int y);
void (*set_cursor_visible)(TERM_REC *term, int set); void (*tr_set_cursor_visible)(TERM_REC *term, int set);
void (*scroll)(TERM_REC *term, int y1, int y2, int count); void (*tr_scroll)(TERM_REC *term, int y1, int y2, int count);
void (*clear)(TERM_REC *term); void (*tr_clear)(TERM_REC *term);
void (*clrtoeol)(TERM_REC *term); void (*tr_clrtoeol)(TERM_REC *term);
void (*repeat)(TERM_REC *term, char chr, int count); void (*tr_repeat)(TERM_REC *term, char chr, int count);
void (*set_fg)(TERM_REC *term, int color); void (*tr_set_fg)(TERM_REC *term, int color);
void (*set_bg)(TERM_REC *term, int color); void (*tr_set_bg)(TERM_REC *term, int color);
void (*set_normal)(TERM_REC *term); void (*tr_set_normal)(TERM_REC *term);
void (*set_blink)(TERM_REC *term); void (*tr_set_blink)(TERM_REC *term);
void (*set_bold)(TERM_REC *term); void (*tr_set_bold)(TERM_REC *term);
void (*set_reverse)(TERM_REC *term); void (*tr_set_reverse)(TERM_REC *term);
void (*set_uline)(TERM_REC *term, int set); void (*tr_set_uline)(TERM_REC *term, int set);
void (*set_standout)(TERM_REC *term, int set); void (*tr_set_standout)(TERM_REC *term, int set);
void (*set_italic)(TERM_REC *term, int set); void (*tr_set_italic)(TERM_REC *term, int set);
void (*beep)(TERM_REC *term); void (*tr_beep)(TERM_REC *term);
#ifndef HAVE_TERMINFO #ifndef HAVE_TERMINFO
char buffer1[1024], buffer2[1024]; char buffer1[1024], buffer2[1024];
@ -52,13 +53,13 @@ struct _TERM_REC {
FILE *in, *out; FILE *in, *out;
struct termios tio, old_tio; struct termios tio, old_tio;
/* Terminal size */ /* Terminal size */
int width, height; int width, height;
/* Cursor movement */ /* Cursor movement */
const char *TI_smcup, *TI_rmcup, *TI_cup; const char *TI_smcup, *TI_rmcup, *TI_cup;
const char *TI_hpa, *TI_vpa, *TI_cub1, *TI_cuf1; const char *TI_hpa, *TI_vpa, *TI_cub1, *TI_cuf1;
const char *TI_civis, *TI_cnorm; const char *TI_civis, *TI_cnorm;
/* Scrolling */ /* Scrolling */
const char *TI_csr, *TI_wind; const char *TI_csr, *TI_wind;
@ -68,26 +69,26 @@ struct _TERM_REC {
/* Clearing screen */ /* Clearing screen */
const char *TI_clear, *TI_ed; /* + *TI_dl, *TI_dl1; */ const char *TI_clear, *TI_ed; /* + *TI_dl, *TI_dl1; */
/* Clearing to end of line */ /* Clearing to end of line */
const char *TI_el; const char *TI_el;
/* Repeating character */ /* Repeating character */
const char *TI_rep; const char *TI_rep;
/* Colors */ /* Colors */
int TI_colors; /* numbers of colors in TI_fg[] and TI_bg[] */ int TI_colors; /* numbers of colors in TI_fg[] and TI_bg[] */
const char *TI_sgr0; /* turn off all attributes */ const char *TI_sgr0; /* turn off all attributes */
const char *TI_smul, *TI_rmul; /* underline on/off */ const char *TI_smul, *TI_rmul; /* underline on/off */
const char *TI_smso, *TI_rmso; /* standout on/off */ const char *TI_smso, *TI_rmso; /* standout on/off */
const char *TI_sitm, *TI_ritm; /* italic on/off */ const char *TI_sitm, *TI_ritm; /* italic on/off */
const char *TI_bold, *TI_blink, *TI_rev; const char *TI_bold, *TI_blink, *TI_rev;
const char *TI_setaf, *TI_setab, *TI_setf, *TI_setb; const char *TI_setaf, *TI_setab, *TI_setf, *TI_setb;
/* Colors - generated and dynamically allocated */ /* Colors - generated and dynamically allocated */
char **TI_fg, **TI_bg, *TI_normal; char **TI_fg, **TI_bg, *TI_normal;
/* Beep */ /* Beep */
char *TI_bel; char *TI_bel;
/* Keyboard-transmit mode */ /* Keyboard-transmit mode */
const char *TI_smkx; const char *TI_smkx;