diff options
author | Bram Moolenaar <Bram@vim.org> | 2017-07-22 20:33:05 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2017-07-22 20:33:05 +0200 |
commit | b7a8dfeb49784145fe133496ce38703d236e4fbe (patch) | |
tree | f977848f29234d713c554fb2a184ee0b91be949d /src | |
parent | e173fd09720a346fbaa340003d31a4329283a805 (diff) | |
download | vim-b7a8dfeb49784145fe133496ce38703d236e4fbe.zip |
patch 8.0.0748: running Vim in terminal window doesn't use the right colors
Problem: When running Vim in a terminal window it does not detect the right
number of colors available.
Solution: Detect the version string that libvterm returns. Pass the number
of colors in $COLORS.
Diffstat (limited to 'src')
-rw-r--r-- | src/os_unix.c | 10 | ||||
-rw-r--r-- | src/term.c | 93 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 72 insertions, 33 deletions
diff --git a/src/os_unix.c b/src/os_unix.c index bbc74c7f7..4caf38bb4 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -4063,7 +4063,13 @@ set_child_environment(long rows, long columns, char *term) static char envbuf_Rows[20]; static char envbuf_Lines[20]; static char envbuf_Columns[20]; + static char envbuf_Colors[20]; # endif + long colors = +# ifdef FEAT_GUI + gui.in_use ? 256*256*256 : +# endif + t_colors; /* Simulate to have a dumb terminal (for now) */ # ifdef HAVE_SETENV @@ -4074,6 +4080,8 @@ set_child_environment(long rows, long columns, char *term) setenv("LINES", (char *)envbuf, 1); sprintf((char *)envbuf, "%ld", columns); setenv("COLUMNS", (char *)envbuf, 1); + sprintf((char *)envbuf, "%ld", colors); + setenv("COLORS", (char *)envbuf, 1); # else /* * Putenv does not copy the string, it has to remain valid. @@ -4088,6 +4096,8 @@ set_child_environment(long rows, long columns, char *term) vim_snprintf(envbuf_Columns, sizeof(envbuf_Columns), "COLUMNS=%ld", columns); putenv(envbuf_Columns); + vim_snprintf(envbuf_Colors, sizeof(envbuf_Colors), "COLORS=%ld", colors); + putenv(envbuf_Colors); # endif } diff --git a/src/term.c b/src/term.c index 989d6b7af..98be10f18 100644 --- a/src/term.c +++ b/src/term.c @@ -1428,8 +1428,6 @@ parse_builtin_tcap(char_u *term) } } #if defined(HAVE_TGETENT) || defined(FEAT_TERMRESPONSE) -static void set_color_count(int nr); - /* * Set number of colors. * Store it as a number in t_colors. @@ -1447,6 +1445,35 @@ set_color_count(int nr) *nr_colors = NUL; set_string_option_direct((char_u *)"t_Co", -1, nr_colors, OPT_FREE, 0); } + +/* + * Set the color count to "val" and redraw if it changed. + */ + static void +may_adjust_color_count(int val) +{ + if (val != t_colors) + { + /* Nr of colors changed, initialize highlighting and + * redraw everything. This causes a redraw, which usually + * clears the message. Try keeping the message if it + * might work. */ + set_keep_msg_from_hist(); + set_color_count(val); + init_highlight(TRUE, FALSE); +# ifdef DEBUG_TERMRESPONSE + { + char buf[100]; + int r = redraw_asap(CLEAR); + + sprintf(buf, "Received t_Co, redraw_asap(): %d", r); + log_tr(buf); + } +# else + redraw_asap(CLEAR); +# endif + } +} #endif #ifdef HAVE_TGETENT @@ -2713,9 +2740,9 @@ term_get_winpos(int *x, int *y) # endif void -term_set_winsize(int width, int height) +term_set_winsize(int height, int width) { - OUT_STR(tgoto((char *)T_CWS, height, width)); + OUT_STR(tgoto((char *)T_CWS, width, height)); } #endif @@ -2823,6 +2850,8 @@ term_settitle(char_u *title) void ttest(int pairs) { + char_u *env_colors; + check_options(); /* make sure no options are NULL */ /* @@ -2909,8 +2938,16 @@ ttest(int pairs) } need_gather = TRUE; - /* Set t_colors to the value of t_Co. */ + /* Set t_colors to the value of $COLORS or t_Co. */ t_colors = atoi((char *)T_CCO); + env_colors = mch_getenv((char_u *)"COLORS"); + if (env_colors != NULL && isdigit(*env_colors)) + { + int colors = atoi((char *)env_colors); + + if (colors != t_colors) + set_color_count(colors); + } } #if (defined(FEAT_GUI) && (defined(FEAT_MENU) || !defined(USE_ON_FLY_SCROLL))) \ @@ -4250,6 +4287,7 @@ check_termcode( * "<Esc>[" or CSI: * * - Xterm version string: <Esc>[>{x};{vers};{y}c + * Libvterm returns {x} == 0, {vers} == 100, {y} == 0. * Also eat other possible responses to t_RV, rxvt returns * "<Esc>[?1;2c". Also accept CSI instead of <Esc>[. * mrxvt has been reported to have "+" in the version. Assume @@ -4359,10 +4397,8 @@ check_termcode( /* rxvt sends its version number: "20703" is 2.7.3. * Ignore it for when the user has set 'term' to xterm, * even though it's an rxvt. */ - if (extra > 0) - extra = atoi((char *)tp + extra); - if (extra > 20000) - extra = 0; + if (col > 20000) + col = 0; if (tp[1 + (tp[0] != CSI)] == '>' && j == 2) { @@ -4371,25 +4407,36 @@ check_termcode( if (!option_was_set((char_u *)"ttym")) { # ifdef TTYM_SGR - if (extra >= 277) + if (col >= 277) set_option_value((char_u *)"ttym", 0L, (char_u *)"sgr", 0); else # endif /* if xterm version >= 95 use mouse dragging */ - if (extra >= 95) + if (col >= 95) set_option_value((char_u *)"ttym", 0L, (char_u *)"xterm2", 0); } /* if xterm version >= 141 try to get termcap codes */ - if (extra >= 141) + if (col >= 141) { LOG_TR("Enable checking for XT codes"); check_for_codes = TRUE; need_gather = TRUE; req_codes_from_term(); } + + /* libvterm sends 0;100;0 */ + if (col == 100 + && STRNCMP(tp + extra - 2, ">0;100;0c", 9) == 0) + { + /* If run from Vim $COLORS is set to the number of + * colors the terminal supports. Otherwise assume + * 256, libvterm supports even more. */ + if (mch_getenv((char_u *)"COLORS") == NULL) + may_adjust_color_count(256); + } } # ifdef FEAT_EVAL set_vim_var_string(VV_TERMRESPONSE, tp, i + 1); @@ -5993,27 +6040,7 @@ got_code_from_term(char_u *code, int len) { /* Color count is not a key code. */ i = atoi((char *)str); - if (i != t_colors) - { - /* Nr of colors changed, initialize highlighting and - * redraw everything. This causes a redraw, which usually - * clears the message. Try keeping the message if it - * might work. */ - set_keep_msg_from_hist(); - set_color_count(i); - init_highlight(TRUE, FALSE); -#ifdef DEBUG_TERMRESPONSE - { - char buf[100]; - int r = redraw_asap(CLEAR); - - sprintf(buf, "Received t_Co, redraw_asap(): %d", r); - log_tr(buf); - } -#else - redraw_asap(CLEAR); -#endif - } + may_adjust_color_count(i); } else { diff --git a/src/version.c b/src/version.c index 79e503fe5..0564b8ff4 100644 --- a/src/version.c +++ b/src/version.c @@ -770,6 +770,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 748, +/**/ 747, /**/ 746, |