tui: 'guicursor' color

For now only supports valid hex colors (does not check for the validity
the hex color) when termguicolors is set, otherwise it won't attempt to
change the cursor color.
This commit is contained in:
Matthieu Coudron 2017-03-21 00:03:01 +01:00 committed by Justin M. Keyes
parent dd4a5fcbb6
commit 54bab0019b
4 changed files with 52 additions and 25 deletions

View File

@ -2802,7 +2802,8 @@ A jump table for the options with a short description can be found at |Q_op|.
the height of the cursor can be changed. This can be done by
specifying a block cursor, or a percentage for a vertical or
horizontal cursor.
For a console the 't_SI' and 't_EI' escape sequences are used.
For a console, shape is taken into account and color as well if
'termguicolors' is set. 't_SI' and 't_EI' are deprecated in neovim.
The option is a comma separated list of parts. Each part consist of a
mode-list and an argument-list:

View File

@ -48,9 +48,9 @@ static bool did_syntax_onoff = false;
struct hl_group {
char_u *sg_name; ///< highlight group name
char_u *sg_name_u; ///< uppercase of sg_name
int sg_attr; ///< Screen attr
int sg_attr; ///< Screen attr @see ATTR_ENTRY
int sg_link; ///< link to this highlight group ID
int sg_set; ///< combination of SG_* flags
int sg_set; ///< combination of flags in \ref SG_SET
scid_T sg_scriptID; ///< script in which the group was last set
// for terminal UIs
int sg_cterm; ///< "cterm=" highlighting attr
@ -59,6 +59,7 @@ struct hl_group {
int sg_cterm_bold; ///< bold attr was set for light color
// for RGB UIs
int sg_gui; ///< "gui=" highlighting attributes
///< (combination of \ref HL_ATTRIBUTES)
RgbValue sg_rgb_fg; ///< RGB foreground color
RgbValue sg_rgb_bg; ///< RGB background color
RgbValue sg_rgb_sp; ///< RGB special color
@ -67,9 +68,12 @@ struct hl_group {
uint8_t *sg_rgb_sp_name; ///< RGB special color name
};
/// \addtogroup SG_SET
/// @{
#define SG_CTERM 2 // cterm has been set
#define SG_GUI 4 // gui has been set
#define SG_LINK 8 // link has been set
/// @}
// highlight groups for 'highlight' option
static garray_T highlight_ga = GA_EMPTY_INIT_VALUE;
@ -6093,16 +6097,16 @@ int load_colors(char_u *name)
return retval;
}
/*
* Handle the ":highlight .." command.
* When using ":hi clear" this is called recursively for each group with
* "forceit" and "init" both TRUE.
*/
void
do_highlight (
/// Handle the ":highlight .." command.
/// When using ":hi clear" this is called recursively for each group with
/// "forceit" and "init" both TRUE.
/// @param init TRUE when called for initializing
void
do_highlight(
char_u *line,
int forceit,
int init /* TRUE when called for initializing */
int init
)
{
char_u *name_end;
@ -6704,12 +6708,10 @@ static garray_T attr_table = GA_EMPTY_INIT_VALUE;
#define ATTR_ENTRY(idx) ((attrentry_T *)attr_table.ga_data)[idx]
/*
* Return the attr number for a set of colors and font.
* Add a new entry to the term_attr_table, attr_table or gui_attr_table
* if the combination is new.
* Return 0 for error.
*/
/// Return the attr number for a set of colors and font.
/// Add a new entry to the term_attr_table, attr_table or gui_attr_table
/// if the combination is new.
/// @return 0 for error.
int get_attr_entry(attrentry_T *aep)
{
garray_T *table = &attr_table;
@ -6932,7 +6934,7 @@ static int highlight_list_arg(int id, int didh, int type, int iarg, char_u *sarg
/// Check whether highlight group has attribute
///
/// @param[in] id Highilght group to check.
/// @param[in] id Highlight group to check.
/// @param[in] flag Attribute to check.
/// @param[in] modec 'g' for GUI, 'c' for term.
///
@ -8245,7 +8247,14 @@ color_name_table_T color_name_table[] = {
{ NULL, 0 },
};
RgbValue name_to_color(uint8_t *name)
/// Translate to RgbValue if \p name is an hex value (e.g. #XXXXXX),
/// else look into color_name_table to translate a color name to its
/// hex value
///
/// @param[in] name string value to convert to RGB
/// return the hex value or -1 if could not find a correct value
RgbValue name_to_color(const uint8_t *name)
{
if (name[0] == '#' && isxdigit(name[1]) && isxdigit(name[2])

View File

@ -5,10 +5,11 @@
#include "nvim/buffer_defs.h"
/*
* Terminal highlighting attribute bits.
* Attributes above HL_ALL are used for syntax highlighting.
*/
/// Terminal highlighting attribute bits.
/// Attributes above HL_ALL are used for syntax highlighting.
/// \addtogroup HL_ATTRIBUTES
/// @{
#define HL_NORMAL 0x00
#define HL_INVERSE 0x01
#define HL_BOLD 0x02
@ -16,6 +17,7 @@
#define HL_UNDERLINE 0x08
#define HL_UNDERCURL 0x10
#define HL_STANDOUT 0x20
/// @}
#define HL_CONTAINED 0x01 /* not used on toplevel */
#define HL_TRANSP 0x02 /* has no highlighting */

View File

@ -78,6 +78,7 @@ typedef struct {
int enable_mouse, disable_mouse;
int enable_bracketed_paste, disable_bracketed_paste;
int set_rgb_foreground, set_rgb_background;
int set_cursor_color;
int enable_focus_reporting, disable_focus_reporting;
} unibi_ext;
} TUIData;
@ -132,6 +133,7 @@ static void terminfo_start(UI *ui)
data->showing_mode = 0;
data->unibi_ext.enable_mouse = -1;
data->unibi_ext.disable_mouse = -1;
data->unibi_ext.set_cursor_color = -1;
data->unibi_ext.enable_bracketed_paste = -1;
data->unibi_ext.disable_bracketed_paste = -1;
data->unibi_ext.enable_focus_reporting = -1;
@ -548,8 +550,12 @@ static void tui_set_cursor(UI *ui, MouseMode mode)
case SHAPE_HOR: shape = 3; break;
default: WLOG("Unknown shape value %d", shape); break;
}
printf(TMUX_WRAP("\x1b]50;CursorShape=%d;BlinkingCursorEnabled=%d\x07"),
shape, (c.blinkon !=0));
data->params[0].i = shape;
data->params[1].i = (c.blinkon ==0);
unibi_format(vars, vars + 26,
TMUX_WRAP("\x1b]50;CursorShape=%p1%d;BlinkingCursorEnabled=%p2%d\x07"),
data->params, out, ui, NULL, NULL);
} else if (!vte_version || atoi(vte_version) >= 3900) {
// Assume that the terminal supports DECSCUSR unless it is an
// old VTE based terminal. This should not get wrapped for tmux,
@ -566,6 +572,13 @@ static void tui_set_cursor(UI *ui, MouseMode mode)
unibi_format(vars, vars + 26, "\x1b[%p1%d q",
data->params, out, ui, NULL, NULL);
}
if (c.id != 0 && ui->rgb) {
int attr = syn_id2attr(c.id);
attrentry_T *aep = syn_cterm_attr2entry(attr);
data->params[0].i = aep->rgb_bg_color;
unibi_out(ui, data->unibi_ext.set_cursor_color);
}
}
/// Returns cursor mode from edit mode
@ -1004,6 +1017,8 @@ static void fix_terminfo(TUIData *data)
end:
// Fill some empty slots with common terminal strings
data->unibi_ext.set_cursor_color = (int)unibi_add_ext_str(
ut, NULL, "\033]12;#%p1%06x\007");
data->unibi_ext.enable_mouse = (int)unibi_add_ext_str(ut, NULL,
"\x1b[?1002h\x1b[?1006h");
data->unibi_ext.disable_mouse = (int)unibi_add_ext_str(ut, NULL,