Created
July 19, 2017 15:05
-
-
Save ttdoda/fdebb57f5a57c42e90fb9708aecfeffa to your computer and use it in GitHub Desktop.
VimでのDECRQMによる左右マージン利用自動判定
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/main.c b/src/main.c | |
index 268c256..04edcad 100644 | |
--- a/src/main.c | |
+++ b/src/main.c | |
@@ -825,6 +825,7 @@ vim_main2(void) | |
may_req_termresponse(); | |
may_req_bg_color(); | |
+ may_req_lrm_status(); | |
#endif | |
/* start in insert mode */ | |
diff --git a/src/option.c b/src/option.c | |
index 8e91fae..7226852 100644 | |
--- a/src/option.c | |
+++ b/src/option.c | |
@@ -3186,6 +3186,7 @@ static struct vimoption options[] = | |
p_term("t_op", T_OP) | |
p_term("t_RB", T_RBG) | |
p_term("t_RI", T_CRI) | |
+ p_term("t_RM", T_RVM) | |
p_term("t_RV", T_CRV) | |
p_term("t_Sb", T_CSB) | |
p_term("t_se", T_SE) | |
@@ -3194,6 +3195,7 @@ static struct vimoption options[] = | |
p_term("t_so", T_SO) | |
p_term("t_SR", T_CSR) | |
p_term("t_sr", T_SR) | |
+ p_term("t_SV", T_SVM) | |
p_term("t_te", T_TE) | |
p_term("t_ti", T_TI) | |
p_term("t_ts", T_TS) | |
@@ -3203,7 +3205,9 @@ static struct vimoption options[] = | |
p_term("t_ut", T_UT) | |
p_term("t_vb", T_VB) | |
p_term("t_ve", T_VE) | |
+ p_term("t_VE", T_VME) | |
p_term("t_vi", T_VI) | |
+ p_term("t_VS", T_VMS) | |
p_term("t_vs", T_VS) | |
p_term("t_WP", T_CWP) | |
p_term("t_GP", T_CGP) | |
diff --git a/src/term.c b/src/term.c | |
index 989d6b7..b9c0f84 100644 | |
--- a/src/term.c | |
+++ b/src/term.c | |
@@ -129,6 +129,11 @@ static int u7_status = U7_GET; | |
# define RBG_SENT 2 /* did send T_RBG, waiting for answer */ | |
# define RBG_GOT 3 /* received T_RBG response */ | |
static int rbg_status = RBG_GET; | |
+/* Request left-right margin status: */ | |
+# define RVM_GET 1 /* send T_RVM when switched to RAW mode */ | |
+# define RVM_SENT 2 /* did send T_RVM, waiting for answer */ | |
+# define RVM_GOT 3 /* received T_RVM response */ | |
+static int rvm_status = RVM_GET; | |
# endif | |
/* | |
@@ -853,6 +858,14 @@ static struct builtin_term builtin_termcaps[] = | |
# endif | |
{(int)KS_CRV, IF_EB("\033[>c", ESC_STR "[>c")}, | |
{(int)KS_RBG, IF_EB("\033]11;?\007", ESC_STR "]11;?\007")}, | |
+ {(int)KS_RVM, IF_EB("\033[?69$p", ESC_STR "[?69$p")}, | |
+ {(int)KS_VMS, IF_EB("\033[?69h", ESC_STR "[?69h")}, | |
+ {(int)KS_VME, IF_EB("\033[?69l", ESC_STR "[?69l")}, | |
+# ifdef TERMINFO | |
+ {(int)KS_SVM, IF_EB("\033[%i%p1%d;%p2%ds", ESC_STR "[%i%p1%d;%p2%ds")}, | |
+# else | |
+ {(int)KS_SVM, IF_EB("\033[%i%d;%ds", ESC_STR "[%i%d;%ds")}, | |
+# endif | |
{(int)KS_U7, IF_EB("\033[6n", ESC_STR "[6n")}, | |
# ifdef FEAT_TERMGUICOLORS | |
/* These are printf strings, not terminal codes. */ | |
@@ -1154,6 +1167,14 @@ static struct builtin_term builtin_termcaps[] = | |
{(int)KS_CRV, "[CRV]"}, | |
{(int)KS_U7, "[U7]"}, | |
{(int)KS_RBG, "[RBG]"}, | |
+ {(int)KS_RVM, "[RVM]"}, | |
+ {(int)KS_VMS, "[VMS]"}, | |
+ {(int)KS_VME, "[VME]"}, | |
+# ifdef TERMINFO | |
+ {(int)KS_SVM, "[%p1%dSVM%p2%d]"}, | |
+# else | |
+ {(int)KS_SVM, "[%dSVM%d]"}, | |
+# endif | |
{K_UP, "[KU]"}, | |
{K_DOWN, "[KD]"}, | |
{K_LEFT, "[KL]"}, | |
@@ -1544,7 +1565,8 @@ set_termname(char_u *term) | |
{KS_TS, "ts"}, {KS_FS, "fs"}, | |
{KS_CWP, "WP"}, {KS_CWS, "WS"}, | |
{KS_CSI, "SI"}, {KS_CEI, "EI"}, | |
- {KS_U7, "u7"}, {KS_RBG, "RB"}, | |
+ {KS_U7, "u7"}, {KS_RBG, "RB"}, {KS_RVM, "RM"}, | |
+ {KS_VMS, "VS"}, {KS_VME, "VE"}, {KS_SVM, "SV"}, | |
{KS_8F, "8f"}, {KS_8B, "8b"}, | |
{KS_CBE, "BE"}, {KS_CBD, "BD"}, | |
{KS_CPS, "PS"}, {KS_CPE, "PE"}, | |
@@ -3249,7 +3271,8 @@ settmode(int tmode) | |
* them. */ | |
if (tmode != TMODE_RAW && (crv_status == CRV_SENT | |
|| u7_status == U7_SENT | |
- || rbg_status == RBG_SENT)) | |
+ || rbg_status == RBG_SENT | |
+ || rvm_status == RVM_SENT)) | |
(void)vpeekc_nomap(); | |
check_for_codes_from_term(); | |
} | |
@@ -3315,9 +3338,9 @@ stoptermcap(void) | |
if (!gui.in_use && !gui.starting) | |
# endif | |
{ | |
- /* May need to discard T_CRV, T_U7 or T_RBG response. */ | |
+ /* May need to discard T_CRV, T_U7, T_RBG or T_RVM response. */ | |
if (crv_status == CRV_SENT || u7_status == U7_SENT | |
- || rbg_status == RBG_SENT) | |
+ || rbg_status == RBG_SENT || rvm_status == RVM_SENT) | |
{ | |
# ifdef UNIX | |
/* Give the terminal a chance to respond. */ | |
@@ -3446,6 +3469,31 @@ may_req_bg_color(void) | |
} | |
} | |
+/* | |
+ * | |
+ */ | |
+ void | |
+may_req_lrm_status(void) | |
+{ | |
+ if (rvm_status == RVM_GET | |
+ && can_get_termresponse() | |
+ && starting == 0 | |
+ && *T_RVM != NUL | |
+ && *T_VMS != NUL | |
+ && *T_VME != NUL | |
+ && *T_SVM != NUL | |
+ && !option_was_set((char_u *)"t_CV")) | |
+ { | |
+ LOG_TR("Sending RVM request"); | |
+ out_str(T_RVM); | |
+ rvm_status = RVM_SENT; | |
+ /* check for the characters now, otherwise they might be eaten by | |
+ * get_keystroke() */ | |
+ out_flush(); | |
+ (void)vpeekc_nomap(); | |
+ } | |
+} | |
+ | |
# ifdef DEBUG_TERMRESPONSE | |
static void | |
log_tr(char *msg) | |
@@ -4260,10 +4308,12 @@ check_termcode( | |
* ambiguous-width character state. | |
* | |
* - window position reply: <Esc>[3;{x};{y}t | |
+ * | |
+ * - left-right margin status reply: <Esc>[?69;{stat}$y | |
*/ | |
char_u *argp = tp[0] == ESC ? tp + 2 : tp + 1; | |
- if ((*T_CRV != NUL || *T_U7 != NUL || waiting_for_winpos) | |
+ if ((*T_CRV != NUL || *T_U7 != NUL || *T_RVM != NUL || waiting_for_winpos) | |
&& ((tp[0] == ESC && len >= 3 && tp[1] == '[') | |
|| (tp[0] == CSI && len >= 2)) | |
&& (VIM_ISDIGIT(*argp) || *argp == '>' || *argp == '?')) | |
@@ -4437,6 +4487,41 @@ check_termcode( | |
return -1; | |
} | |
} | |
+ | |
+ /* | |
+ * Check for left-right margin status response from the terminal: | |
+ * {lead}?69;{stat}$y | |
+ * | |
+ * {stat} can be from 0 to 4 | |
+ * 0: not supported | |
+ * 1: set | |
+ * 2: reset | |
+ * 3: always set | |
+ * 4: always reset (assumes not supported) | |
+ */ | |
+ else if (*T_RVM != NUL && i > 6 +(tp[0] != CSI) | |
+ && tp[i-1] == '$' && tp[i] == 'y' | |
+ && STRNCMP(tp + 1 + (tp[0] != CSI), "?69;", 4) == 0) | |
+ { | |
+ extra = atoi((char *)tp + extra); | |
+ if (extra >= 1 && extra <= 3) { | |
+ LOG_TR("Received RVM"); | |
+ rvm_status = RVM_GOT; | |
+ | |
+ if (*T_SVM != NUL) { | |
+ set_option_value((char_u *)"t_CV", 0L, T_SVM, 0); | |
+ } | |
+ | |
+ if (extra == 2 && *T_VMS != NUL) { | |
+ out_str(T_VMS); | |
+ } | |
+ } | |
+ | |
+ /* got finished code: consume it */ | |
+ key_name[0] = (int)KS_EXTRA; | |
+ key_name[1] = (int)KE_IGNORE; | |
+ slen = i + 1; | |
+ } | |
} | |
/* Check for background color response from the terminal: | |
diff --git a/src/term.h b/src/term.h | |
index be01cb5..435d7c0 100644 | |
--- a/src/term.h | |
+++ b/src/term.h | |
@@ -81,6 +81,10 @@ enum SpecialKey | |
KS_CWS, /* set window size in characters */ | |
KS_CRV, /* request version string */ | |
KS_RBG, /* request background color */ | |
+ KS_RVM, /* request left-right margin status */ | |
+ KS_VMS, /* start left-right margin mode */ | |
+ KS_VME, /* end left-right margin mode */ | |
+ KS_SVM, /* set left-right margin */ | |
KS_CSI, /* start insert mode (bar cursor) */ | |
KS_CEI, /* end insert mode (block cursor) */ | |
KS_CSR, /* start replace mode (underline cursor) */ | |
@@ -172,6 +176,10 @@ extern char_u *(term_strings[]); /* current terminal strings */ | |
#define T_CSR (TERM_STR(KS_CSR)) /* start replace mode */ | |
#define T_CRV (TERM_STR(KS_CRV)) /* request version string */ | |
#define T_RBG (TERM_STR(KS_RBG)) /* request background RGB */ | |
+#define T_RVM (TERM_STR(KS_RVM)) /* request left-right margin status */ | |
+#define T_VMS (TERM_STR(KS_VMS)) /* start left-right margin mode */ | |
+#define T_VME (TERM_STR(KS_VME)) /* end left-right margin mode */ | |
+#define T_SVM (TERM_STR(KS_SVM)) /* set left and right margin */ | |
#define T_OP (TERM_STR(KS_OP)) /* original color pair */ | |
#define T_U7 (TERM_STR(KS_U7)) /* request cursor position */ | |
#define T_8F (TERM_STR(KS_8F)) /* set foreground color (RGB) */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment