Update the terminfo backend to query the 'colors' capability and support more

than 16 colors (sync from icecap).


git-svn-id: http://svn.irssi.org/repos/irssi/trunk@4687 dbcabf3a-b0e7-0310-adc4-f8d773084564
This commit is contained in:
Emanuele Giaquinta 2008-01-25 11:20:40 +00:00 committed by exg
parent 3e5ad97676
commit e13216adf7
3 changed files with 40 additions and 36 deletions

View File

@ -188,7 +188,7 @@ void term_resize_final(int width, int height)
/* Returns TRUE if terminal has colors */ /* Returns TRUE if terminal has colors */
int term_has_colors(void) int term_has_colors(void)
{ {
return current_term->has_colors; return current_term->TI_colors > 0;
} }
/* Force the colors on any way you can */ /* Force the colors on any way you can */

View File

@ -89,6 +89,7 @@ static TERMINFO_REC tcaps[] = {
{ "rep", "rp", CAP_TYPE_STR, &temp_term.TI_rep }, { "rep", "rp", CAP_TYPE_STR, &temp_term.TI_rep },
/* Colors */ /* Colors */
{ "colors", "Co", CAP_TYPE_INT, &temp_term.TI_colors },
{ "sgr0", "me", CAP_TYPE_STR, &temp_term.TI_sgr0 }, { "sgr0", "me", CAP_TYPE_STR, &temp_term.TI_sgr0 },
{ "smul", "us", CAP_TYPE_STR, &temp_term.TI_smul }, { "smul", "us", CAP_TYPE_STR, &temp_term.TI_smul },
{ "rmul", "ue", CAP_TYPE_STR, &temp_term.TI_rmul }, { "rmul", "ue", CAP_TYPE_STR, &temp_term.TI_rmul },
@ -334,13 +335,13 @@ static void _set_standout(TERM_REC *term, int set)
/* Change foreground color */ /* Change foreground color */
static void _set_fg(TERM_REC *term, int color) static void _set_fg(TERM_REC *term, int color)
{ {
tput(tparm(term->TI_fg[color & 0x0f])); tput(tparm(term->TI_fg[color % term->TI_colors]));
} }
/* Change background color */ /* Change background color */
static void _set_bg(TERM_REC *term, int color) static void _set_bg(TERM_REC *term, int color)
{ {
tput(tparm(term->TI_bg[color & 0x0f])); tput(tparm(term->TI_bg[color % term->TI_colors]));
} }
/* Beep */ /* Beep */
@ -394,13 +395,13 @@ static void terminfo_colors_deinit(TERM_REC *term)
int i; int i;
if (terminfo_is_colors_set(term)) { if (terminfo_is_colors_set(term)) {
for (i = 0; i < 16; i++) { for (i = 0; i < term->TI_colors; i++) {
g_free(term->TI_fg[i]); g_free(term->TI_fg[i]);
g_free(term->TI_bg[i]); g_free(term->TI_bg[i]);
} }
memset(term->TI_fg, 0, sizeof(term->TI_fg)); g_free_and_null(term->TI_fg);
memset(term->TI_bg, 0, sizeof(term->TI_fg)); g_free_and_null(term->TI_bg);
} }
} }
@ -408,18 +409,36 @@ 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 char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; static const char ansitab[16] = {
const char *bold, *blink; 0, 4, 2, 6, 1, 5, 3, 7,
int i; 8, 12, 10, 14, 9, 13, 11, 15
};
unsigned int i, color;
terminfo_colors_deinit(term); terminfo_colors_deinit(term);
term->has_colors = term->TI_setf || term->TI_setaf;
if (force && term->TI_setf == NULL && term->TI_setaf == NULL)
term->TI_colors = 8;
if ((term->TI_setf || term->TI_setaf || force) &&
term->TI_colors > 0) {
term->TI_fg = g_new0(char *, term->TI_colors);
term->TI_bg = g_new0(char *, term->TI_colors);
term->set_fg = _set_fg;
term->set_bg = _set_bg;
} else {
/* no colors */
term->TI_colors = 0;
term->set_fg = term->set_bg = _ignore_parm;
}
if (term->TI_setaf) { if (term->TI_setaf) {
for (i = 0; i < 8; i++) for (i = 0; i < term->TI_colors; i++) {
term->TI_fg[i] = g_strdup(tparm(term->TI_setaf, ansitab[i], 0)); color = i < 16 ? ansitab[i] : i;
term->TI_fg[i] = g_strdup(tparm(term->TI_setaf, color, 0));
}
} else if (term->TI_setf) { } else if (term->TI_setf) {
for (i = 0; i < 8; i++) for (i = 0; i < term->TI_colors; i++)
term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0)); term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0));
} else if (force) { } else if (force) {
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
@ -427,32 +446,17 @@ void terminfo_setup_colors(TERM_REC *term, int force)
} }
if (term->TI_setab) { if (term->TI_setab) {
for (i = 0; i < 8; i++) for (i = 0; i < term->TI_colors; i++) {
term->TI_bg[i] = g_strdup(tparm(term->TI_setab, ansitab[i], 0)); color = i < 16 ? ansitab[i] : i;
term->TI_bg[i] = g_strdup(tparm(term->TI_setab, color, 0));
}
} else if (term->TI_setb) { } else if (term->TI_setb) {
for (i = 0; i < 8; i++) for (i = 0; i < term->TI_colors; i++)
term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 0)); term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 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]);
} }
if (term->TI_setf || term->TI_setaf || force) {
term->set_fg = _set_fg;
term->set_bg = _set_bg;
/* bold fg, blink bg */
bold = term->TI_bold ? term->TI_bold : "";
for (i = 0; i < 8; i++)
term->TI_fg[i+8] = g_strconcat(bold, term->TI_fg[i], NULL);
blink = term->TI_blink ? term->TI_blink : "";
for (i = 0; i < 8; i++)
term->TI_bg[i+8] = g_strconcat(blink, term->TI_bg[i], NULL);
} else {
/* no colors */
term->set_fg = term->set_bg = _ignore_parm;
}
} }
static void terminfo_input_init(TERM_REC *term) static void terminfo_input_init(TERM_REC *term)

View File

@ -16,7 +16,7 @@
#define terminfo_set_bold() current_term->set_bold(current_term) #define terminfo_set_bold() current_term->set_bold(current_term)
#define terminfo_set_uline(set) current_term->set_uline(current_term, set) #define terminfo_set_uline(set) current_term->set_uline(current_term, set)
#define terminfo_set_standout(set) current_term->set_standout(current_term, set) #define terminfo_set_standout(set) current_term->set_standout(current_term, set)
#define terminfo_is_colors_set(term) (term->TI_fg[0] != 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->beep(current_term)
typedef struct _TERM_REC TERM_REC; typedef struct _TERM_REC TERM_REC;
@ -71,7 +71,7 @@ struct _TERM_REC {
const char *TI_rep; const char *TI_rep;
/* Colors */ /* Colors */
int has_colors; 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 */
@ -79,7 +79,7 @@ struct _TERM_REC {
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[16], *TI_bg[16], *TI_normal; char **TI_fg, **TI_bg, *TI_normal;
/* Beep */ /* Beep */
char *TI_bel; char *TI_bel;