Permalink
Browse files

patch 8.0.0918: cannot get terminal window cursor shape or attributes

Problem:    Cannot get terminal window cursor shape or attributes.
Solution:   Support cursor shape, attributes and color.
  • Loading branch information...
brammool committed Aug 12, 2017
1 parent 589b110 commit 3cd43ccccb03b2e68df9c8a344a87e51c007c656
Showing with 196 additions and 31 deletions.
  1. +15 −9 runtime/doc/eval.txt
  2. +3 −0 src/feature.h
  3. +2 −1 src/libvterm/include/vterm.h
  4. +5 −0 src/libvterm/src/state.c
  5. +1 −0 src/libvterm/src/vterm.c
  6. +3 −0 src/option.c
  7. +4 −1 src/proto/term.pro
  8. +1 −0 src/proto/ui.pro
  9. +56 −6 src/term.c
  10. +6 −0 src/term.h
  11. +90 −12 src/terminal.c
  12. +8 −2 src/ui.c
  13. +2 −0 src/version.c
View
@@ -7939,13 +7939,19 @@ term_getattr({attr}, {what}) *term_getattr()*
term_getcursor({buf}) *term_getcursor()*
Get the cursor position of terminal {buf}. Returns a list with
three numbers: [rows, cols, visible]. "rows" and "cols" are
one based, the first screen cell is row 1, column 1.
"visible" is one when the cursor is visible, zero when it is
hidden.
two numbers and a dictionary: [rows, cols, dict].
This is the cursor position of the terminal itself, not of the
Vim window.
"rows" and "cols" are one based, the first screen cell is row
1, column 1. This is the cursor position of the terminal
itself, not of the Vim window.
"dict" can have these members:
"visible" one when the cursor is visible, zero when it
is hidden.
"blink" one when the cursor is visible, zero when it
is hidden.
"shape" 1 for a block cursor, 2 for underline and 3
for a vertical bar.
{buf} must be the buffer number of a terminal window. If the
buffer does not exist or is not a terminal window, an empty
@@ -8035,7 +8041,7 @@ term_scrape({buf}, {row}) *term_scrape()*
"fg" foreground color as #rrggbb
"bg" background color as #rrggbb
"attr" attributes of the cell, use |term_getattr()|
to get the individual flags
to get the individual flags
"width" cell width: 1 or 2
{only available when compiled with the |+terminal| feature}
@@ -8075,7 +8081,7 @@ term_start({cmd}, {options}) *term_start()*
"term_rows" vertical size to use for the terminal,
instead of using 'termsize'
"term_cols" horizontal size to use for the terminal,
instead of using 'termsize'
instead of using 'termsize'
"vertical" split the window vertically
"curwin" use the current window, do not split the
window; fails if the current buffer
@@ -8165,7 +8171,7 @@ test_override({name}, {val}) *test_override()*
in a way that the test doesn't work properly.
When using: >
call test_override('starting', 1)
< The value of "starting" is saved. It is restored by: >
< The value of "starting" is saved. It is restored by: >
call test_override('starting', 0)
test_settime({expr}) *test_settime()*
View
@@ -1273,6 +1273,9 @@
#if !defined(FEAT_JOB_CHANNEL) && defined(FEAT_TERMINAL)
# undef FEAT_TERMINAL
#endif
#if defined(FEAT_TERMINAL) && !defined(CURSOR_SHAPE)
# define CURSOR_SHAPE
#endif
/*
* +signs Allow signs to be displayed to the left of text lines.
@@ -120,7 +120,8 @@ typedef enum {
VTERM_PROP_ICONNAME, /* string */
VTERM_PROP_REVERSE, /* bool */
VTERM_PROP_CURSORSHAPE, /* number */
VTERM_PROP_MOUSE /* number */
VTERM_PROP_MOUSE, /* number */
VTERM_PROP_CURSORCOLOR /* string */
} VTermProp;
enum {
View
@@ -1504,6 +1504,10 @@ static int on_osc(const char *command, size_t cmdlen, void *user)
settermprop_string(state, VTERM_PROP_TITLE, command + 2, cmdlen - 2);
return 1;
}
else if(strneq(command, "12;", 3)) {
settermprop_string(state, VTERM_PROP_CURSORCOLOR, command + 3, cmdlen - 3);
return 1;
}
else if(state->fallbacks && state->fallbacks->osc)
if((*state->fallbacks->osc)(command, cmdlen, state->fbdata))
return 1;
@@ -1819,6 +1823,7 @@ int vterm_state_set_termprop(VTermState *state, VTermProp prop, VTermValue *val)
switch(prop) {
case VTERM_PROP_TITLE:
case VTERM_PROP_ICONNAME:
case VTERM_PROP_CURSORCOLOR:
/* we don't store these, just transparently pass through */
return 1;
case VTERM_PROP_CURSORVISIBLE:
View
@@ -294,6 +294,7 @@ VTermValueType vterm_get_prop_type(VTermProp prop)
case VTERM_PROP_REVERSE: return VTERM_VALUETYPE_BOOL;
case VTERM_PROP_CURSORSHAPE: return VTERM_VALUETYPE_INT;
case VTERM_PROP_MOUSE: return VTERM_VALUETYPE_INT;
case VTERM_PROP_CURSORCOLOR: return VTERM_VALUETYPE_STRING;
}
return 0; /* UNREACHABLE */
}
View
@@ -3162,6 +3162,9 @@ static struct vimoption options[] =
p_term("t_EI", T_CEI)
p_term("t_fs", T_FS)
p_term("t_IE", T_CIE)
p_term("t_SC", T_CSC)
p_term("t_EC", T_CEC)
p_term("t_SH", T_CSH)
p_term("t_IS", T_CIS)
p_term("t_ke", T_KE)
p_term("t_ks", T_KS)
View
@@ -51,7 +51,10 @@ int mouse_model_popup(void);
void scroll_start(void);
void cursor_on(void);
void cursor_off(void);
void term_cursor_shape(void);
void term_cursor_mode(int forced);
void term_cursor_color(char_u *color);
void term_cursor_blink(int blink);
void term_cursor_shape(int shape, int blink);
void scroll_region_set(win_T *wp, int off);
void scroll_region_reset(void);
void clear_termcodes(void);
View
@@ -47,6 +47,7 @@ void trash_input_buf(void);
int read_from_input_buf(char_u *buf, long maxlen);
void fill_input_buf(int exit_on_error);
void read_error_exit(void);
void ui_cursor_shape_forced(int forced);
void ui_cursor_shape(void);
int check_col(int col);
int check_row(int row);
View
@@ -817,6 +817,14 @@ static struct builtin_term builtin_termcaps[] =
{(int)KS_MS, "y"},
{(int)KS_UT, "y"},
{(int)KS_LE, "\b"},
{(int)KS_VI, IF_EB("\033[?25l", ESC_STR "[?25l")},
{(int)KS_VE, IF_EB("\033[?25h", ESC_STR "[?25h")},
{(int)KS_VS, IF_EB("\033[?12h", ESC_STR "[?12h")},
# ifdef TERMINFO
{(int)KS_CSH, IF_EB("\033[%p1%d q", ESC_STR "[%p1%d q")},
# else
{(int)KS_CSH, IF_EB("\033[%d q", ESC_STR "[%d q")},
# endif
# ifdef TERMINFO
{(int)KS_CM, IF_EB("\033[%i%p1%d;%p2%dH",
ESC_STR "[%i%p1%d;%p2%dH")},
@@ -840,6 +848,8 @@ static struct builtin_term builtin_termcaps[] =
{(int)KS_CIE, "\007"},
{(int)KS_TS, IF_EB("\033]2;", ESC_STR "]2;")},
{(int)KS_FS, "\007"},
{(int)KS_CSC, IF_EB("\033]12;", ESC_STR "]12;")},
{(int)KS_CEC, "\007"},
# ifdef TERMINFO
{(int)KS_CWS, IF_EB("\033[8;%p1%d;%p2%dt",
ESC_STR "[8;%p1%d;%p2%dt")},
@@ -1142,6 +1152,8 @@ static struct builtin_term builtin_termcaps[] =
{(int)KS_TE, "[TE]"},
{(int)KS_CIS, "[CIS]"},
{(int)KS_CIE, "[CIE]"},
{(int)KS_CSC, "[CSC]"},
{(int)KS_CEC, "[CEC]"},
{(int)KS_TS, "[TS]"},
{(int)KS_FS, "[FS]"},
# ifdef TERMINFO
@@ -1569,6 +1581,7 @@ set_termname(char_u *term)
{KS_CAB,"AB"}, {KS_CAF,"AF"}, {KS_LE, "le"},
{KS_ND, "nd"}, {KS_OP, "op"}, {KS_CRV, "RV"},
{KS_CIS, "IS"}, {KS_CIE, "IE"},
{KS_CSC, "SC"}, {KS_CEC, "EC"},
{KS_TS, "ts"}, {KS_FS, "fs"},
{KS_CWP, "WP"}, {KS_CWS, "WS"},
{KS_CSI, "SI"}, {KS_CEI, "EI"},
@@ -2283,8 +2296,8 @@ term_is_8bit(char_u *name)
/*
* Translate terminal control chars from 7-bit to 8-bit:
* <Esc>[ -> CSI
* <Esc>] -> <M-C-]>
* <Esc>[ -> CSI <M_C_[>
* <Esc>] -> OSC <M-C-]>
* <Esc>O -> <M-C-O>
*/
static int
@@ -3655,7 +3668,7 @@ cursor_off(void)
* Set cursor shape to match Insert or Replace mode.
*/
void
term_cursor_shape(void)
term_cursor_mode(int forced)
{
static int showing_mode = NORMAL;
char_u *p;
@@ -3667,7 +3680,7 @@ term_cursor_shape(void)
if ((State & REPLACE) == REPLACE)
{
if (showing_mode != REPLACE)
if (forced || showing_mode != REPLACE)
{
if (*T_CSR != NUL)
p = T_CSR; /* Replace mode cursor */
@@ -3682,18 +3695,55 @@ term_cursor_shape(void)
}
else if (State & INSERT)
{
if (showing_mode != INSERT && *T_CSI != NUL)
if ((forced || showing_mode != INSERT) && *T_CSI != NUL)
{
out_str(T_CSI); /* Insert mode cursor */
showing_mode = INSERT;
}
}
else if (showing_mode != NORMAL)
else if (forced || showing_mode != NORMAL)
{
out_str(T_CEI); /* non-Insert mode cursor */
showing_mode = NORMAL;
}
}
# if defined(FEAT_TERMINAL) || defined(PROTO)
void
term_cursor_color(char_u *color)
{
if (*T_CSC != NUL)
{
out_str(T_CSC); /* set cursor color start */
out_str_nf(color);
out_str(T_CEC); /* set cursor color end */
out_flush();
}
}
void
term_cursor_blink(int blink)
{
if (blink)
out_str(T_VS);
else
out_str(T_VE);
out_flush();
}
/*
* "shape" == 1: block, "shape" == 2: underline, "shape" == 3: vertical bar
*/
void
term_cursor_shape(int shape, int blink)
{
if (*T_CSH != NUL)
{
OUT_STR(tgoto((char *)T_CSH, 0, shape * 2 - blink));
out_flush();
}
}
# endif
#endif
/*
View
@@ -40,6 +40,7 @@ enum SpecialKey
KS_VI, /* cursor invisible */
KS_VE, /* cursor visible */
KS_VS, /* cursor very visible */
KS_CSH, /* cursor shape */
KS_ME, /* normal mode */
KS_MR, /* reverse mode */
KS_MD, /* bold mode */
@@ -74,6 +75,8 @@ enum SpecialKey
KS_ND, /* cursor right */
KS_CIS, /* set icon text start */
KS_CIE, /* set icon text end */
KS_CSC, /* set cursor color start */
KS_CEC, /* set cursor color end */
KS_TS, /* set window title start (to status line)*/
KS_FS, /* set window title end (from status line) */
KS_CWP, /* set window position in pixels */
@@ -128,6 +131,7 @@ extern char_u *(term_strings[]); /* current terminal strings */
#define T_VI (TERM_STR(KS_VI)) /* cursor invisible */
#define T_VE (TERM_STR(KS_VE)) /* cursor visible */
#define T_VS (TERM_STR(KS_VS)) /* cursor very visible */
#define T_CSH (TERM_STR(KS_CSH)) /* cursor shape */
#define T_ME (TERM_STR(KS_ME)) /* normal mode */
#define T_MR (TERM_STR(KS_MR)) /* reverse mode */
#define T_MD (TERM_STR(KS_MD)) /* bold mode */
@@ -164,6 +168,8 @@ extern char_u *(term_strings[]); /* current terminal strings */
#define T_CIE (TERM_STR(KS_CIE)) /* set icon text end */
#define T_TS (TERM_STR(KS_TS)) /* set window title start */
#define T_FS (TERM_STR(KS_FS)) /* set window title end */
#define T_CSC (TERM_STR(KS_CSC)) /* set cursor color start */
#define T_CEC (TERM_STR(KS_CEC)) /* set cursor color end */
#define T_CWP (TERM_STR(KS_CWP)) /* set window position */
#define T_CGP (TERM_STR(KS_CGP)) /* get window position */
#define T_CWS (TERM_STR(KS_CWS)) /* window size */
Oops, something went wrong.

0 comments on commit 3cd43cc

Please sign in to comment.