diff options
author | Emanuele Giaquinta <exg@irssi.org> | 2008-01-25 11:20:40 +0000 |
---|---|---|
committer | exg <exg@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2008-01-25 11:20:40 +0000 |
commit | e13216adf785c3967519d71afc4659adb628f38c (patch) | |
tree | 3d19d3a87c4008556bf71f6eb89f81aa37d66c4f | |
parent | 3e5ad9767691e3f12cfa09716501d871a9b95157 (diff) | |
download | irssi-e13216adf785c3967519d71afc4659adb628f38c.zip |
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
-rw-r--r-- | src/fe-text/term-terminfo.c | 2 | ||||
-rw-r--r-- | src/fe-text/terminfo-core.c | 68 | ||||
-rw-r--r-- | src/fe-text/terminfo-core.h | 6 |
3 files changed, 40 insertions, 36 deletions
diff --git a/src/fe-text/term-terminfo.c b/src/fe-text/term-terminfo.c index 7e0ea686..4b8d7938 100644 --- a/src/fe-text/term-terminfo.c +++ b/src/fe-text/term-terminfo.c @@ -188,7 +188,7 @@ void term_resize_final(int width, int height) /* Returns TRUE if terminal has colors */ int term_has_colors(void) { - return current_term->has_colors; + return current_term->TI_colors > 0; } /* Force the colors on any way you can */ diff --git a/src/fe-text/terminfo-core.c b/src/fe-text/terminfo-core.c index 2d9db404..7c960215 100644 --- a/src/fe-text/terminfo-core.c +++ b/src/fe-text/terminfo-core.c @@ -89,6 +89,7 @@ static TERMINFO_REC tcaps[] = { { "rep", "rp", CAP_TYPE_STR, &temp_term.TI_rep }, /* Colors */ + { "colors", "Co", CAP_TYPE_INT, &temp_term.TI_colors }, { "sgr0", "me", CAP_TYPE_STR, &temp_term.TI_sgr0 }, { "smul", "us", CAP_TYPE_STR, &temp_term.TI_smul }, { "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 */ 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 */ 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 */ @@ -394,13 +395,13 @@ static void terminfo_colors_deinit(TERM_REC *term) int i; 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_bg[i]); } - memset(term->TI_fg, 0, sizeof(term->TI_fg)); - memset(term->TI_bg, 0, sizeof(term->TI_fg)); + g_free_and_null(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 */ void terminfo_setup_colors(TERM_REC *term, int force) { - static char ansitab[8] = { 0, 4, 2, 6, 1, 5, 3, 7 }; - const char *bold, *blink; - int i; + static const char ansitab[16] = { + 0, 4, 2, 6, 1, 5, 3, 7, + 8, 12, 10, 14, 9, 13, 11, 15 + }; + unsigned int i, color; 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) { - for (i = 0; i < 8; i++) - term->TI_fg[i] = g_strdup(tparm(term->TI_setaf, ansitab[i], 0)); + for (i = 0; i < term->TI_colors; i++) { + color = i < 16 ? ansitab[i] : i; + term->TI_fg[i] = g_strdup(tparm(term->TI_setaf, color, 0)); + } } 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)); } else if (force) { for (i = 0; i < 8; i++) @@ -427,32 +446,17 @@ void terminfo_setup_colors(TERM_REC *term, int force) } if (term->TI_setab) { - for (i = 0; i < 8; i++) - term->TI_bg[i] = g_strdup(tparm(term->TI_setab, ansitab[i], 0)); + for (i = 0; i < term->TI_colors; i++) { + color = i < 16 ? ansitab[i] : i; + term->TI_bg[i] = g_strdup(tparm(term->TI_setab, color, 0)); + } } 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)); } else if (force) { for (i = 0; i < 8; 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) diff --git a/src/fe-text/terminfo-core.h b/src/fe-text/terminfo-core.h index 9af1efda..34f7b70e 100644 --- a/src/fe-text/terminfo-core.h +++ b/src/fe-text/terminfo-core.h @@ -16,7 +16,7 @@ #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_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) typedef struct _TERM_REC TERM_REC; @@ -71,7 +71,7 @@ struct _TERM_REC { const char *TI_rep; /* 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_smul, *TI_rmul; /* underline 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; /* Colors - generated and dynamically allocated */ - char *TI_fg[16], *TI_bg[16], *TI_normal; + char **TI_fg, **TI_bg, *TI_normal; /* Beep */ char *TI_bel; |