Skip to content

Commit f3af54e

Browse files
committed
patch 8.0.1016: gnome terminal echoes t_RC
Problem: Gnome terminal echoes t_RC. Solution: Detect Gnome terminal by the version string. Add v: variables for all the term responses.
1 parent 97a80e4 commit f3af54e

5 files changed

Lines changed: 74 additions & 31 deletions

File tree

runtime/doc/eval.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,26 @@ v:termresponse The escape sequence returned by the terminal for the |t_RV|
19021902
always 95 or bigger). Pc is always zero.
19031903
{only when compiled with |+termresponse| feature}
19041904

1905+
*v:termblinkresp*
1906+
v:termblinkresp The escape sequence returned by the terminal for the |t_RC|
1907+
termcap entry. This is used to find out whether the terminal
1908+
cursor is blinking. This is used by |term_getcursor()|.
1909+
1910+
*v:termstyleresp*
1911+
v:termstyleresp The escape sequence returned by the terminal for the |t_RS|
1912+
termcap entry. This is used to find out what the shape of the
1913+
cursor is. This is used by |term_getcursor()|.
1914+
1915+
*v:termrgbresp*
1916+
v:termrgbresp The escape sequence returned by the terminal for the |t_RB|
1917+
termcap entry. This is used to find out what the terminal
1918+
background color is, see 'background'.
1919+
1920+
*v:termu7resp*
1921+
v:termu7resp The escape sequence returned by the terminal for the |t_u7|
1922+
termcap entry. This is used to find out what the terminal
1923+
does with ambiguous width characters, see 'ambiwidth'.
1924+
19051925
*v:testing* *testing-variable*
19061926
v:testing Must be set before using `test_garbagecollect_now()`.
19071927
Also, when set certain error messages won't be shown for 2

src/eval.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ static struct vimvar
187187
{VV_NAME("t_none", VAR_NUMBER), VV_RO},
188188
{VV_NAME("t_job", VAR_NUMBER), VV_RO},
189189
{VV_NAME("t_channel", VAR_NUMBER), VV_RO},
190+
{VV_NAME("termrgbresp", VAR_STRING), VV_RO},
191+
{VV_NAME("termu7resp", VAR_STRING), VV_RO},
192+
{VV_NAME("termstyleresp", VAR_STRING), VV_RO},
193+
{VV_NAME("termblinkresp", VAR_STRING), VV_RO},
190194
};
191195

192196
/* shorthand */

src/term.c

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,9 +1369,7 @@ static int need_gather = FALSE; /* need to fill termleader[] */
13691369
static char_u termleader[256 + 1]; /* for check_termcode() */
13701370
#ifdef FEAT_TERMRESPONSE
13711371
static int check_for_codes = FALSE; /* check for key code response */
1372-
# ifdef MACOS
1373-
static int is_terminal_app = FALSE; /* recognized Terminal.app */
1374-
# endif
1372+
static int is_not_xterm = FALSE; /* recognized not-really-xterm */
13751373
#endif
13761374

13771375
static struct builtin_term *
@@ -3506,13 +3504,10 @@ may_req_ambiguous_char_width(void)
35063504
/*
35073505
* Similar to requesting the version string: Request the terminal background
35083506
* color when it is the right moment.
3509-
* Also request the cursor shape, if possible.
35103507
*/
35113508
void
35123509
may_req_bg_color(void)
35133510
{
3514-
int did_one = FALSE;
3515-
35163511
if (can_get_termresponse() && starting == 0)
35173512
{
35183513
/* Only request background if t_RB is set and 'background' wasn't
@@ -3524,20 +3519,7 @@ may_req_bg_color(void)
35243519
LOG_TR("Sending BG request");
35253520
out_str(T_RBG);
35263521
rbg_status = STATUS_SENT;
3527-
did_one = TRUE;
3528-
}
3529-
3530-
/* Only request cursor blinking mode if t_RC is set. */
3531-
if (rbm_status == STATUS_GET && *T_CRC != NUL)
3532-
{
3533-
LOG_TR("Sending BC request");
3534-
out_str(T_CRC);
3535-
rbm_status = STATUS_SENT;
3536-
did_one = TRUE;
3537-
}
35383522

3539-
if (did_one)
3540-
{
35413523
/* check for the characters now, otherwise they might be eaten by
35423524
* get_keystroke() */
35433525
out_flush();
@@ -4505,6 +4487,9 @@ check_termcode(
45054487
key_name[0] = (int)KS_EXTRA;
45064488
key_name[1] = (int)KE_IGNORE;
45074489
slen = i + 1;
4490+
# ifdef FEAT_EVAL
4491+
set_vim_var_string(VV_TERMU7RESP, tp, slen);
4492+
# endif
45084493
}
45094494
else
45104495
#endif
@@ -4530,6 +4515,8 @@ check_termcode(
45304515

45314516
if (tp[1 + (tp[0] != CSI)] == '>' && semicols == 2)
45324517
{
4518+
int need_flush = FALSE;
4519+
45334520
/* Only set 'ttymouse' automatically if it was not set
45344521
* by the user already. */
45354522
if (!option_was_set((char_u *)"ttym"))
@@ -4566,43 +4553,60 @@ check_termcode(
45664553
may_adjust_color_count(256);
45674554
}
45684555

4556+
/* Detect terminals that set $TERM to something like
4557+
* "xterm-256colors" but are not fully xterm
4558+
* compatible. */
45694559
# ifdef MACOS
45704560
/* Mac Terminal.app sends 1;95;0 */
45714561
if (col == 95
45724562
&& STRNCMP(tp + extra - 2, "1;95;0c", 7) == 0)
4573-
{
4574-
/* Terminal.app sets $TERM to "xterm-256colors",
4575-
* but it's not fully xterm compatible. */
4576-
is_terminal_app = TRUE;
4577-
}
4563+
is_not_xterm = TRUE;
45784564
# endif
4565+
/* Gnome Terminal.app sends 1;4402;0, assuming any
4566+
* version number over 4000 is not an xterm. */
4567+
if (col >= 4000)
4568+
is_not_xterm = TRUE;
45794569

45804570
/* Only request the cursor style if t_SH and t_RS are
45814571
* set. Not for Terminal.app, it can't handle t_RS, it
45824572
* echoes the characters to the screen. */
45834573
if (rcs_status == STATUS_GET
4584-
# ifdef MACOS
4585-
&& !is_terminal_app
4586-
# endif
4574+
&& !is_not_xterm
45874575
&& *T_CSH != NUL
45884576
&& *T_CRS != NUL)
45894577
{
45904578
LOG_TR("Sending cursor style request");
45914579
out_str(T_CRS);
45924580
rcs_status = STATUS_SENT;
4593-
out_flush();
4581+
need_flush = TRUE;
45944582
}
4583+
4584+
/* Only request the cursor blink mode if t_RC set. Not
4585+
* for Gnome terminal, it can't handle t_RC, it
4586+
* echoes the characters to the screen. */
4587+
if (rbm_status == STATUS_GET
4588+
&& !is_not_xterm
4589+
&& *T_CRC != NUL)
4590+
{
4591+
LOG_TR("Sending cursor blink mode request");
4592+
out_str(T_CRC);
4593+
rbm_status = STATUS_SENT;
4594+
need_flush = TRUE;
4595+
}
4596+
4597+
if (need_flush)
4598+
out_flush();
45954599
}
4600+
slen = i + 1;
45964601
# ifdef FEAT_EVAL
4597-
set_vim_var_string(VV_TERMRESPONSE, tp, i + 1);
4602+
set_vim_var_string(VV_TERMRESPONSE, tp, slen);
45984603
# endif
45994604
# ifdef FEAT_AUTOCMD
46004605
apply_autocmds(EVENT_TERMRESPONSE,
46014606
NULL, NULL, FALSE, curbuf);
46024607
# endif
46034608
key_name[0] = (int)KS_EXTRA;
46044609
key_name[1] = (int)KE_IGNORE;
4605-
slen = i + 1;
46064610
}
46074611

46084612
/* Check blinking cursor from xterm:
@@ -4626,6 +4630,9 @@ check_termcode(
46264630
key_name[0] = (int)KS_EXTRA;
46274631
key_name[1] = (int)KE_IGNORE;
46284632
slen = i + 1;
4633+
# ifdef FEAT_EVAL
4634+
set_vim_var_string(VV_TERMBLINKRESP, tp, slen);
4635+
# endif
46294636
}
46304637

46314638
/*
@@ -4714,6 +4721,9 @@ check_termcode(
47144721
/* Sometimes the 0x07 is followed by 0x18, unclear
47154722
* when this happens. */
47164723
++slen;
4724+
# ifdef FEAT_EVAL
4725+
set_vim_var_string(VV_TERMRGBRESP, tp, slen);
4726+
# endif
47174727
break;
47184728
}
47194729
if (i == len)
@@ -4788,6 +4798,9 @@ check_termcode(
47884798
key_name[0] = (int)KS_EXTRA;
47894799
key_name[1] = (int)KE_IGNORE;
47904800
slen = i + 1 + (tp[i] == ESC);
4801+
# ifdef FEAT_EVAL
4802+
set_vim_var_string(VV_TERMSTYLERESP, tp, slen);
4803+
# endif
47914804
}
47924805
}
47934806

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,8 @@ static char *(features[]) =
769769

770770
static int included_patches[] =
771771
{ /* Add new patch number below this line */
772+
/**/
773+
1016,
772774
/**/
773775
1015,
774776
/**/

src/vim.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,11 @@ typedef int sock_T;
20122012
#define VV_TYPE_NONE 78
20132013
#define VV_TYPE_JOB 79
20142014
#define VV_TYPE_CHANNEL 80
2015-
#define VV_LEN 81 /* number of v: vars */
2015+
#define VV_TERMRGBRESP 81
2016+
#define VV_TERMU7RESP 82
2017+
#define VV_TERMSTYLERESP 83
2018+
#define VV_TERMBLINKRESP 84
2019+
#define VV_LEN 85 /* number of v: vars */
20162020

20172021
/* used for v_number in VAR_SPECIAL */
20182022
#define VVAL_FALSE 0L

0 commit comments

Comments
 (0)