From 690bcb6b32e9a3613c72431b643977a9cd71d9d8 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 10 Aug 2014 10:59:08 -0400 Subject: [PATCH 1/3] Force 256color escapes. --- configure.ac | 16 ++++++++++++++++ src/fe-text/terminfo-core.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 2a7bee0d..fc715efd 100644 --- a/configure.ac +++ b/configure.ac @@ -175,6 +175,15 @@ AC_ARG_ENABLE(true-color, fi, want_truecolor=no) +AC_ARG_ENABLE(force-256color, +[ --enable-force-256color Force using 256-color escapes], + if text x$enableval = xno ; then + want_force256color=no + else + want_force256color=yes + fi, + want_force256color=no) + dnl ** dnl ** SSL Library checks (OpenSSL) dnl ** @@ -669,6 +678,12 @@ else want_truecolor=no fi +if test "x$want_force256color" = "xyes" ; then + AC_DEFINE([HACK_FORCE_256COLOR], [], [force 256color escapes in terminal]) +else + want_force256color=no +fi + AC_CONFIG_FILES([ Makefile src/Makefile @@ -802,6 +817,7 @@ echo "Building with 64bit DCC support .. : $offt_64bit" echo "Building with garbage collector .. : $have_gc" echo "Building with DANE support ....... : $have_dane" echo "Building with true color support.. : $want_truecolor" +echo "Building with force 256color hack. : $want_force256color" echo echo "If there are any problems, read the INSTALL file." diff --git a/src/fe-text/terminfo-core.c b/src/fe-text/terminfo-core.c index d16987fe..8c97d0a5 100644 --- a/src/fe-text/terminfo-core.c +++ b/src/fe-text/terminfo-core.c @@ -451,7 +451,11 @@ void terminfo_setup_colors(TERM_REC *term, int force) terminfo_colors_deinit(term); if (force && term->TI_setf == NULL && term->TI_setaf == NULL) +#ifdef HACK_FORCE_256COLOR + term->TI_colors = 256; +#else term->TI_colors = 8; +#endif if ((term->TI_setf || term->TI_setaf || force) && term->TI_colors > 0) { @@ -464,8 +468,19 @@ void terminfo_setup_colors(TERM_REC *term, int force) term->TI_colors = 0; term->set_fg = term->set_bg = _ignore_parm; } - +#ifdef HACK_FORCE_256COLOR + /* force 256-color escapes for base colors also, lets you have bold + * font in konsole without bright + */ + if (force) { + for (i = 0; i < term->TI_colors; i++) { + color = i < 16 ? ansitab[i] : i; + term->TI_fg[i] = g_strdup_printf("\033[38;5;%dm", color); + } + } else if (term->TI_setaf) { +#else if (term->TI_setaf) { +#endif 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)); @@ -473,12 +488,24 @@ void terminfo_setup_colors(TERM_REC *term, int force) } else if (term->TI_setf) { for (i = 0; i < term->TI_colors; i++) term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0)); +#ifdef HACK_FORCE_256COLOR + } +#else } else if (force) { for (i = 0; i < 8; i++) term->TI_fg[i] = g_strdup_printf("\033[%dm", 30+ansitab[i]); } - +#endif +#ifdef HACK_FORCE_256COLOR + if (force) { + for (i = 0; i < term->TI_colors; i++) { + color = i < 16 ? ansitab[i] : i; + term->TI_bg[i] = g_strdup_printf("\033[48;5;%dm", color); + } + } else if (term->TI_setab) { +#else if (term->TI_setab) { +#endif 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)); @@ -486,10 +513,14 @@ void terminfo_setup_colors(TERM_REC *term, int force) } else if (term->TI_setb) { for (i = 0; i < term->TI_colors; i++) term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 0)); +#ifdef HACK_FORCE_256COLOR + } +#else } else if (force) { for (i = 0; i < 8; i++) term->TI_bg[i] = g_strdup_printf("\033[%dm", 40+ansitab[i]); } +#endif /* HACK_FORCE_256COLOR */ } static void terminfo_input_init(TERM_REC *term) From 9001a974691cd736010b5b5606240ae341aad1cf Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 10 Aug 2014 17:10:29 -0400 Subject: [PATCH 2/3] Switch from compile time to runtime setting. --- configure.ac | 16 ---------------- src/fe-text/term.c | 12 ++++++++++-- src/fe-text/terminfo-core.c | 33 +++++++-------------------------- 3 files changed, 17 insertions(+), 44 deletions(-) diff --git a/configure.ac b/configure.ac index fc715efd..2a7bee0d 100644 --- a/configure.ac +++ b/configure.ac @@ -175,15 +175,6 @@ AC_ARG_ENABLE(true-color, fi, want_truecolor=no) -AC_ARG_ENABLE(force-256color, -[ --enable-force-256color Force using 256-color escapes], - if text x$enableval = xno ; then - want_force256color=no - else - want_force256color=yes - fi, - want_force256color=no) - dnl ** dnl ** SSL Library checks (OpenSSL) dnl ** @@ -678,12 +669,6 @@ else want_truecolor=no fi -if test "x$want_force256color" = "xyes" ; then - AC_DEFINE([HACK_FORCE_256COLOR], [], [force 256color escapes in terminal]) -else - want_force256color=no -fi - AC_CONFIG_FILES([ Makefile src/Makefile @@ -817,7 +802,6 @@ echo "Building with 64bit DCC support .. : $offt_64bit" echo "Building with garbage collector .. : $have_gc" echo "Building with DANE support ....... : $have_dane" echo "Building with true color support.. : $want_truecolor" -echo "Building with force 256color hack. : $want_force256color" echo echo "If there are any problems, read the INSTALL file." diff --git a/src/fe-text/term.c b/src/fe-text/term.c index 4600f02e..03fd0ee1 100644 --- a/src/fe-text/term.c +++ b/src/fe-text/term.c @@ -130,6 +130,7 @@ static void read_settings(void) int old_colors = term_use_colors; int old_colors24 = term_use_colors24; int old_type = term_type; + int old_forced = force_colors; /* set terminal type */ str = settings_get_str("term_charset"); @@ -144,8 +145,14 @@ static void read_settings(void) term_set_input_type(term_type); /* change color stuff */ - if (force_colors != settings_get_bool("term_force_colors")) { + if (settings_get_bool("term_force_256colors")) { + force_colors = 256; + } + else if (force_colors != settings_get_bool("term_force_colors")) { force_colors = settings_get_bool("term_force_colors"); + } + + if (old_forced != force_colors) { term_force_colors(force_colors); } @@ -171,7 +178,8 @@ void term_common_init(void) #endif settings_add_bool("lookandfeel", "colors", TRUE); settings_add_bool("lookandfeel", "term_force_colors", FALSE); - settings_add_bool("lookandfeel", "mirc_blink_fix", FALSE); + settings_add_bool("lookandfeel", "mirc_blink_fix", FALSE); + settings_add_bool("lookandfeel", "term_force_256colors", FALSE); force_colors = FALSE; term_use_colors = term_has_colors() && settings_get_bool("colors"); diff --git a/src/fe-text/terminfo-core.c b/src/fe-text/terminfo-core.c index 8c97d0a5..c6e0f61c 100644 --- a/src/fe-text/terminfo-core.c +++ b/src/fe-text/terminfo-core.c @@ -449,13 +449,10 @@ void terminfo_setup_colors(TERM_REC *term, int force) unsigned int i, color; terminfo_colors_deinit(term); - - if (force && term->TI_setf == NULL && term->TI_setaf == NULL) -#ifdef HACK_FORCE_256COLOR + if (force == 256) term->TI_colors = 256; -#else + else if (force && term->TI_setf == NULL && term->TI_setaf == NULL) term->TI_colors = 8; -#endif if ((term->TI_setf || term->TI_setaf || force) && term->TI_colors > 0) { @@ -468,19 +465,15 @@ void terminfo_setup_colors(TERM_REC *term, int force) term->TI_colors = 0; term->set_fg = term->set_bg = _ignore_parm; } -#ifdef HACK_FORCE_256COLOR - /* force 256-color escapes for base colors also, lets you have bold - * font in konsole without bright - */ - if (force) { + if (force == 256) { + /* force 256-color escapes for base colors as well, lets you + * have bold font in konsole without bright. + */ for (i = 0; i < term->TI_colors; i++) { color = i < 16 ? ansitab[i] : i; term->TI_fg[i] = g_strdup_printf("\033[38;5;%dm", color); } } else if (term->TI_setaf) { -#else - if (term->TI_setaf) { -#endif 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)); @@ -488,24 +481,16 @@ void terminfo_setup_colors(TERM_REC *term, int force) } else if (term->TI_setf) { for (i = 0; i < term->TI_colors; i++) term->TI_fg[i] = g_strdup(tparm(term->TI_setf, i, 0)); -#ifdef HACK_FORCE_256COLOR - } -#else } else if (force) { for (i = 0; i < 8; i++) term->TI_fg[i] = g_strdup_printf("\033[%dm", 30+ansitab[i]); } -#endif -#ifdef HACK_FORCE_256COLOR - if (force) { + if (force == 256) { for (i = 0; i < term->TI_colors; i++) { color = i < 16 ? ansitab[i] : i; term->TI_bg[i] = g_strdup_printf("\033[48;5;%dm", color); } } else if (term->TI_setab) { -#else - if (term->TI_setab) { -#endif 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)); @@ -513,14 +498,10 @@ void terminfo_setup_colors(TERM_REC *term, int force) } else if (term->TI_setb) { for (i = 0; i < term->TI_colors; i++) term->TI_bg[i] = g_strdup(tparm(term->TI_setb, i, 0)); -#ifdef HACK_FORCE_256COLOR - } -#else } else if (force) { for (i = 0; i < 8; i++) term->TI_bg[i] = g_strdup_printf("\033[%dm", 40+ansitab[i]); } -#endif /* HACK_FORCE_256COLOR */ } static void terminfo_input_init(TERM_REC *term) From dd98b1c772819a6a2a71cbd0734de3042228cb76 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 10 Aug 2014 19:11:05 -0400 Subject: [PATCH 3/3] Restore term's colors setting when turning off force 256colors. --- src/fe-text/terminfo-core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fe-text/terminfo-core.c b/src/fe-text/terminfo-core.c index c6e0f61c..06637c82 100644 --- a/src/fe-text/terminfo-core.c +++ b/src/fe-text/terminfo-core.c @@ -453,6 +453,8 @@ void terminfo_setup_colors(TERM_REC *term, int force) term->TI_colors = 256; else if (force && term->TI_setf == NULL && term->TI_setaf == NULL) term->TI_colors = 8; + else /* if we turn off force we'll need to restore the real setting */ + term->TI_colors = term_getnum(tcaps[25]); if ((term->TI_setf || term->TI_setaf || force) && term->TI_colors > 0) {