Skip to content

Instantly share code, notes, and snippets.

@saitoha
Created May 12, 2012 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saitoha/2665933 to your computer and use it in GitHub Desktop.
Save saitoha/2665933 to your computer and use it in GitHub Desktop.
vim、SGRパッチ適用後のDA2チェック部分のロジック
#ifdef FEAT_TERMRESPONSE
if (key_name[0] == NUL
/* URXVT mouse uses <ESC>[#;#;#M, but we are matching <ESC>[ */
|| key_name[0] == KS_URXVT_MOUSE
|| key_name[0] == KS_SGR_MOUSE)
{
/* Check for xterm version string: "<Esc>[>{x};{vers};{y}c". 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
* the escape sequence ends with a letter or one of "{|}~". */
if (*T_CRV != NUL && ((tp[0] == ESC && tp[1] == '[' && len >= 3)
|| (tp[0] == CSI && len >= 2)))
{
j = 0;
extra = 0;
for (i = 2 + (tp[0] != CSI); i < len
&& !(tp[i] >= '{' && tp[i] <= '~')
&& !ASCII_ISALPHA(tp[i]); ++i)
if (tp[i] == ';' && ++j == 1)
extra = atoi((char *)tp + i + 1);
if (i == len)
return -1; /* not enough characters */
/* eat it when at least one digit and ending in 'c' */
if (i > 2 + (tp[0] != CSI) && tp[i] == 'c')
{
crv_status = CRV_GOT;
/* If this code starts with CSI, you can bet that the
* terminal uses 8-bit codes. */
if (tp[0] == CSI)
switch_to_8bit();
/* 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 > 20000)
extra = 0;
if (tp[1 + (tp[0] != CSI)] == '>' && j == 2)
{
# ifdef TTYM_SGR
if (extra >= 277
# ifdef TTYM_URXVT
&& ttym_flags != TTYM_URXVT
# endif
)
set_option_value((char_u *)"ttym", 0L,
(char_u *)"sgr", 0);
else
# endif
/* if xterm version >= 95 use mouse dragging */
if (extra >= 95
# ifdef TTYM_URXVT
&& ttym_flags != TTYM_URXVT
# endif
)
set_option_value((char_u *)"ttym", 0L,
(char_u *)"xterm2", 0);
/* if xterm version >= 141 try to get termcap codes */
if (extra >= 141)
{
check_for_codes = TRUE;
need_gather = TRUE;
req_codes_from_term();
}
}
# ifdef FEAT_EVAL
set_vim_var_string(VV_TERMRESPONSE, tp, i + 1);
# endif
# ifdef FEAT_AUTOCMD
apply_autocmds(EVENT_TERMRESPONSE,
NULL, NULL, FALSE, curbuf);
# endif
key_name[0] = (int)KS_EXTRA;
key_name[1] = (int)KE_IGNORE;
slen = i + 1;
}
}
/* Check for '<Esc>P1+r<hex bytes><Esc>\'. A "0" instead of the
* "1" means an invalid request. */
else if (check_for_codes
&& ((tp[0] == ESC && tp[1] == 'P' && len >= 2)
|| tp[0] == DCS))
{
j = 1 + (tp[0] != DCS);
for (i = j; i < len; ++i)
if ((tp[i] == ESC && tp[i + 1] == '\\' && i + 1 < len)
|| tp[i] == STERM)
{
if (i - j >= 3 && tp[j + 1] == '+' && tp[j + 2] == 'r')
got_code_from_term(tp + j, i);
key_name[0] = (int)KS_EXTRA;
key_name[1] = (int)KE_IGNORE;
slen = i + 1 + (tp[i] == ESC);
break;
}
if (i == len)
return -1; /* not enough characters */
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment