comparison src/term.c @ 11731:d06f3576823a v8.0.0748

patch 8.0.0748: running Vim in terminal window doesn't use the right colors commit https://github.com/vim/vim/commit/b7a8dfeb49784145fe133496ce38703d236e4fbe Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 22 20:33:05 2017 +0200 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.
author Christian Brabandt <cb@256bit.org>
date Sat, 22 Jul 2017 20:45:04 +0200
parents 568ea579d20e
children 5c69c6d9e2eb
comparison
equal deleted inserted replaced
11730:a9cdc89f3ded 11731:d06f3576823a
1426 add_termcode(name, (char_u *)p->bt_string, term_8bit); 1426 add_termcode(name, (char_u *)p->bt_string, term_8bit);
1427 } 1427 }
1428 } 1428 }
1429 } 1429 }
1430 #if defined(HAVE_TGETENT) || defined(FEAT_TERMRESPONSE) 1430 #if defined(HAVE_TGETENT) || defined(FEAT_TERMRESPONSE)
1431 static void set_color_count(int nr);
1432
1433 /* 1431 /*
1434 * Set number of colors. 1432 * Set number of colors.
1435 * Store it as a number in t_colors. 1433 * Store it as a number in t_colors.
1436 * Store it as a string in T_CCO (using nr_colors[]). 1434 * Store it as a string in T_CCO (using nr_colors[]).
1437 */ 1435 */
1444 if (t_colors > 1) 1442 if (t_colors > 1)
1445 sprintf((char *)nr_colors, "%d", t_colors); 1443 sprintf((char *)nr_colors, "%d", t_colors);
1446 else 1444 else
1447 *nr_colors = NUL; 1445 *nr_colors = NUL;
1448 set_string_option_direct((char_u *)"t_Co", -1, nr_colors, OPT_FREE, 0); 1446 set_string_option_direct((char_u *)"t_Co", -1, nr_colors, OPT_FREE, 0);
1447 }
1448
1449 /*
1450 * Set the color count to "val" and redraw if it changed.
1451 */
1452 static void
1453 may_adjust_color_count(int val)
1454 {
1455 if (val != t_colors)
1456 {
1457 /* Nr of colors changed, initialize highlighting and
1458 * redraw everything. This causes a redraw, which usually
1459 * clears the message. Try keeping the message if it
1460 * might work. */
1461 set_keep_msg_from_hist();
1462 set_color_count(val);
1463 init_highlight(TRUE, FALSE);
1464 # ifdef DEBUG_TERMRESPONSE
1465 {
1466 char buf[100];
1467 int r = redraw_asap(CLEAR);
1468
1469 sprintf(buf, "Received t_Co, redraw_asap(): %d", r);
1470 log_tr(buf);
1471 }
1472 # else
1473 redraw_asap(CLEAR);
1474 # endif
1475 }
1449 } 1476 }
1450 #endif 1477 #endif
1451 1478
1452 #ifdef HAVE_TGETENT 1479 #ifdef HAVE_TGETENT
1453 static char *(key_names[]) = 1480 static char *(key_names[]) =
2711 return FALSE; 2738 return FALSE;
2712 } 2739 }
2713 # endif 2740 # endif
2714 2741
2715 void 2742 void
2716 term_set_winsize(int width, int height) 2743 term_set_winsize(int height, int width)
2717 { 2744 {
2718 OUT_STR(tgoto((char *)T_CWS, height, width)); 2745 OUT_STR(tgoto((char *)T_CWS, width, height));
2719 } 2746 }
2720 #endif 2747 #endif
2721 2748
2722 void 2749 void
2723 term_fg_color(int n) 2750 term_fg_color(int n)
2821 * Replace all entries that are NULL by empty_option 2848 * Replace all entries that are NULL by empty_option
2822 */ 2849 */
2823 void 2850 void
2824 ttest(int pairs) 2851 ttest(int pairs)
2825 { 2852 {
2853 char_u *env_colors;
2854
2826 check_options(); /* make sure no options are NULL */ 2855 check_options(); /* make sure no options are NULL */
2827 2856
2828 /* 2857 /*
2829 * MUST have "cm": cursor motion. 2858 * MUST have "cm": cursor motion.
2830 */ 2859 */
2907 /* Set 'weirdinvert' according to value of 't_xs' */ 2936 /* Set 'weirdinvert' according to value of 't_xs' */
2908 p_wiv = (*T_XS != NUL); 2937 p_wiv = (*T_XS != NUL);
2909 } 2938 }
2910 need_gather = TRUE; 2939 need_gather = TRUE;
2911 2940
2912 /* Set t_colors to the value of t_Co. */ 2941 /* Set t_colors to the value of $COLORS or t_Co. */
2913 t_colors = atoi((char *)T_CCO); 2942 t_colors = atoi((char *)T_CCO);
2943 env_colors = mch_getenv((char_u *)"COLORS");
2944 if (env_colors != NULL && isdigit(*env_colors))
2945 {
2946 int colors = atoi((char *)env_colors);
2947
2948 if (colors != t_colors)
2949 set_color_count(colors);
2950 }
2914 } 2951 }
2915 2952
2916 #if (defined(FEAT_GUI) && (defined(FEAT_MENU) || !defined(USE_ON_FLY_SCROLL))) \ 2953 #if (defined(FEAT_GUI) && (defined(FEAT_MENU) || !defined(USE_ON_FLY_SCROLL))) \
2917 || defined(PROTO) 2954 || defined(PROTO)
2918 /* 2955 /*
4248 { 4285 {
4249 /* Check for some responses from the terminal starting with 4286 /* Check for some responses from the terminal starting with
4250 * "<Esc>[" or CSI: 4287 * "<Esc>[" or CSI:
4251 * 4288 *
4252 * - Xterm version string: <Esc>[>{x};{vers};{y}c 4289 * - Xterm version string: <Esc>[>{x};{vers};{y}c
4290 * Libvterm returns {x} == 0, {vers} == 100, {y} == 0.
4253 * Also eat other possible responses to t_RV, rxvt returns 4291 * Also eat other possible responses to t_RV, rxvt returns
4254 * "<Esc>[?1;2c". Also accept CSI instead of <Esc>[. 4292 * "<Esc>[?1;2c". Also accept CSI instead of <Esc>[.
4255 * mrxvt has been reported to have "+" in the version. Assume 4293 * mrxvt has been reported to have "+" in the version. Assume
4256 * the escape sequence ends with a letter or one of "{|}~". 4294 * the escape sequence ends with a letter or one of "{|}~".
4257 * 4295 *
4357 switch_to_8bit(); 4395 switch_to_8bit();
4358 4396
4359 /* rxvt sends its version number: "20703" is 2.7.3. 4397 /* rxvt sends its version number: "20703" is 2.7.3.
4360 * Ignore it for when the user has set 'term' to xterm, 4398 * Ignore it for when the user has set 'term' to xterm,
4361 * even though it's an rxvt. */ 4399 * even though it's an rxvt. */
4362 if (extra > 0) 4400 if (col > 20000)
4363 extra = atoi((char *)tp + extra); 4401 col = 0;
4364 if (extra > 20000)
4365 extra = 0;
4366 4402
4367 if (tp[1 + (tp[0] != CSI)] == '>' && j == 2) 4403 if (tp[1 + (tp[0] != CSI)] == '>' && j == 2)
4368 { 4404 {
4369 /* Only set 'ttymouse' automatically if it was not set 4405 /* Only set 'ttymouse' automatically if it was not set
4370 * by the user already. */ 4406 * by the user already. */
4371 if (!option_was_set((char_u *)"ttym")) 4407 if (!option_was_set((char_u *)"ttym"))
4372 { 4408 {
4373 # ifdef TTYM_SGR 4409 # ifdef TTYM_SGR
4374 if (extra >= 277) 4410 if (col >= 277)
4375 set_option_value((char_u *)"ttym", 0L, 4411 set_option_value((char_u *)"ttym", 0L,
4376 (char_u *)"sgr", 0); 4412 (char_u *)"sgr", 0);
4377 else 4413 else
4378 # endif 4414 # endif
4379 /* if xterm version >= 95 use mouse dragging */ 4415 /* if xterm version >= 95 use mouse dragging */
4380 if (extra >= 95) 4416 if (col >= 95)
4381 set_option_value((char_u *)"ttym", 0L, 4417 set_option_value((char_u *)"ttym", 0L,
4382 (char_u *)"xterm2", 0); 4418 (char_u *)"xterm2", 0);
4383 } 4419 }
4384 4420
4385 /* if xterm version >= 141 try to get termcap codes */ 4421 /* if xterm version >= 141 try to get termcap codes */
4386 if (extra >= 141) 4422 if (col >= 141)
4387 { 4423 {
4388 LOG_TR("Enable checking for XT codes"); 4424 LOG_TR("Enable checking for XT codes");
4389 check_for_codes = TRUE; 4425 check_for_codes = TRUE;
4390 need_gather = TRUE; 4426 need_gather = TRUE;
4391 req_codes_from_term(); 4427 req_codes_from_term();
4428 }
4429
4430 /* libvterm sends 0;100;0 */
4431 if (col == 100
4432 && STRNCMP(tp + extra - 2, ">0;100;0c", 9) == 0)
4433 {
4434 /* If run from Vim $COLORS is set to the number of
4435 * colors the terminal supports. Otherwise assume
4436 * 256, libvterm supports even more. */
4437 if (mch_getenv((char_u *)"COLORS") == NULL)
4438 may_adjust_color_count(256);
4392 } 4439 }
4393 } 4440 }
4394 # ifdef FEAT_EVAL 4441 # ifdef FEAT_EVAL
4395 set_vim_var_string(VV_TERMRESPONSE, tp, i + 1); 4442 set_vim_var_string(VV_TERMRESPONSE, tp, i + 1);
4396 # endif 4443 # endif
5991 str[j] = NUL; 6038 str[j] = NUL;
5992 if (name[0] == 'C' && name[1] == 'o') 6039 if (name[0] == 'C' && name[1] == 'o')
5993 { 6040 {
5994 /* Color count is not a key code. */ 6041 /* Color count is not a key code. */
5995 i = atoi((char *)str); 6042 i = atoi((char *)str);
5996 if (i != t_colors) 6043 may_adjust_color_count(i);
5997 {
5998 /* Nr of colors changed, initialize highlighting and
5999 * redraw everything. This causes a redraw, which usually
6000 * clears the message. Try keeping the message if it
6001 * might work. */
6002 set_keep_msg_from_hist();
6003 set_color_count(i);
6004 init_highlight(TRUE, FALSE);
6005 #ifdef DEBUG_TERMRESPONSE
6006 {
6007 char buf[100];
6008 int r = redraw_asap(CLEAR);
6009
6010 sprintf(buf, "Received t_Co, redraw_asap(): %d", r);
6011 log_tr(buf);
6012 }
6013 #else
6014 redraw_asap(CLEAR);
6015 #endif
6016 }
6017 } 6044 }
6018 else 6045 else
6019 { 6046 {
6020 /* First delete any existing entry with the same code. */ 6047 /* First delete any existing entry with the same code. */
6021 i = find_term_bykeys(str); 6048 i = find_term_bykeys(str);