Merge pull request #2374 from mhinz/hl-group-termcursor

[RDY] Add new highlight groups TermCursor and TermCursorNC
This commit is contained in:
Scott Prager 2015-04-09 11:14:22 -04:00
commit 4a7364c807
12 changed files with 49 additions and 74 deletions

View File

@ -99,16 +99,13 @@ variables (set via the |TermOpen| autocmd):
- `{g,b}:terminal_color_$NUM`: The terminal color palette, where `$NUM` is the - `{g,b}:terminal_color_$NUM`: The terminal color palette, where `$NUM` is the
color index, between 0 and 255 inclusive. This only affects UIs with RGB color index, between 0 and 255 inclusive. This only affects UIs with RGB
capabilities; for normal terminals the color index is simply forwarded. capabilities; for normal terminals the color index is simply forwarded.
- `{g,b}:terminal_focused_cursor_highlight`: Highlight group applied to the
cursor in a focused terminal. The default equivalent to having a group with
`cterm=reverse` `gui=reverse``.
- `{g,b}:terminal_unfocused_cursor_highlight`: Highlight group applied to the
cursor in an unfocused terminal. The default equivalent to having a group with
`ctermbg=11` `guibg=#fce94f``.
The configuration variables are only processed when the terminal starts, which The configuration variables are only processed when the terminal starts, which
is why it needs to be done with the |TermOpen| autocmd or setting global is why it needs to be done with the |TermOpen| autocmd or setting global
variables before the terminal is started. variables before the terminal is started.
The terminal cursor can be highlighted via |hl-TermCursor| and
|hl-TermCursorNC|.
============================================================================== ==============================================================================
vim:tw=78:ts=8:noet:ft=help:norl: vim:tw=78:ts=8:noet:ft=help:norl:

View File

@ -3651,17 +3651,19 @@ A jump table for the options with a short description can be found at |Q_op|.
*'highlight'* *'hl'* *'highlight'* *'hl'*
'highlight' 'hl' string (default (as a single string): 'highlight' 'hl' string (default (as a single string):
"8:SpecialKey,~:EndOfBuffer,@:NonText,i "8:SpecialKey,~:EndOfBuffer,z:TermCursor,
d:Directory,e:ErrorMsg,i:IncSearch, Z:TermCursorNC,@:NonText,d:Directory,
l:Search,m:MoreMsg,M:ModeMsg,n:LineNr, e:ErrorMsg,i:IncSearch,l:Search,
m:MoreMsg,M:ModeMsg,n:LineNr,
N:CursorLineNr,r:Question,s:StatusLine, N:CursorLineNr,r:Question,s:StatusLine,
S:StatusLineNC,c:VertSplit,t:Title, S:StatusLineNC,c:VertSplit,t:Title,
v:Visual,w:WarningMsg,W:WildMenu,f:Folded, v:Visual,w:WarningMsg,W:WildMenu,
F:FoldColumn,A:DiffAdd,C:DiffChange, f:Folded,F:FoldColumn,A:DiffAdd,
D:DiffDelete,T:DiffText,>:SignColumn, C:DiffChange,D:DiffDelete,T:DiffText,
B:SpellBad,P:SpellCap,R:SpellRare, >:SignColumn,B:SpellBad,P:SpellCap,
L:SpellLocal,-:Conceal,+:Pmenu,=:PmenuSel, R:SpellRare,L:SpellLocal,-:Conceal,
x:PmenuSbar,X:PmenuThumb") +:Pmenu,=:PmenuSel,x:PmenuSbar,
X:PmenuThumb")
global global
{not in Vi} {not in Vi}
This option can be used to set highlighting mode for various This option can be used to set highlighting mode for various
@ -3670,6 +3672,8 @@ A jump table for the options with a short description can be found at |Q_op|.
use for that occasion. The occasions are: use for that occasion. The occasions are:
|hl-SpecialKey| 8 Meta and special keys listed with ":map" |hl-SpecialKey| 8 Meta and special keys listed with ":map"
|hl-EndOfBuffer| ~ lines after the last line in the buffer |hl-EndOfBuffer| ~ lines after the last line in the buffer
|hl-TermCursor| z Cursor in a focused terminal
|hl-TermCursorNC| Z Cursor in an unfocused terminal
|hl-NonText| @ '@' at the end of the window and |hl-NonText| @ '@' at the end of the window and
characters from 'showbreak' characters from 'showbreak'
|hl-Directory| d directories in CTRL-D listing and other special |hl-Directory| d directories in CTRL-D listing and other special
@ -3681,7 +3685,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|hl-ModeMsg| M Mode (e.g., "-- INSERT --") |hl-ModeMsg| M Mode (e.g., "-- INSERT --")
|hl-LineNr| n line number for ":number" and ":#" commands, and |hl-LineNr| n line number for ":number" and ":#" commands, and
when 'number' or 'relativenumber' option is set. when 'number' or 'relativenumber' option is set.
|hl-CursorLineNr| N like n for when 'cursorline' or 'relativenumber' is |hl-CursorLineNr| N like n for when 'cursorline' or 'relativenumber' is
set. set.
|hl-Question| r |hit-enter| prompt and yes/no questions |hl-Question| r |hit-enter| prompt and yes/no questions
|hl-StatusLine| s status line of current window |status-line| |hl-StatusLine| s status line of current window |status-line|

View File

@ -4763,6 +4763,10 @@ DiffText diff mode: Changed text within a changed line |diff.txt|
{Nvim} *hl-EndOfBuffer* {Nvim} *hl-EndOfBuffer*
EndOfBuffer filler lines (~) after the end of the buffer. EndOfBuffer filler lines (~) after the end of the buffer.
By default, this is highlighted like |hl-NonText|. By default, this is highlighted like |hl-NonText|.
{Nvim} *hl-TermCursor*
TermCursor cursor in a focused terminal
{Nvim} *hl-TermCursorNC*
TermCursorNC cursor in an unfocused terminal
*hl-ErrorMsg* *hl-ErrorMsg*
ErrorMsg error messages on the command line ErrorMsg error messages on the command line
*hl-VertSplit* *hl-VertSplit*

View File

@ -68,6 +68,8 @@ Events:
Highlight groups: Highlight groups:
- |hl-EndOfBuffer| - |hl-EndOfBuffer|
- |hl-TermCursor|
- |hl-TermCursorNC|
============================================================================== ==============================================================================
5. Missing legacy features *nvim-features-missing* 5. Missing legacy features *nvim-features-missing*

View File

@ -68,7 +68,7 @@ syn keyword vimAutoEvent contained BufAdd BufCreate BufDelete BufEnter BufFilePo
syn keyword vimGroup contained Comment Constant String Character Number Boolean Float Identifier Function Statement Conditional Repeat Label Operator Keyword Exception PreProc Include Define Macro PreCondit Type StorageClass Structure Typedef Special SpecialChar Tag Delimiter SpecialComment Debug Underlined Ignore Error Todo syn keyword vimGroup contained Comment Constant String Character Number Boolean Float Identifier Function Statement Conditional Repeat Label Operator Keyword Exception PreProc Include Define Macro PreCondit Type StorageClass Structure Typedef Special SpecialChar Tag Delimiter SpecialComment Debug Underlined Ignore Error Todo
" Default highlighting groups {{{2 " Default highlighting groups {{{2
syn keyword vimHLGroup contained ColorColumn Cursor CursorColumn CursorIM CursorLine CursorLineNr DiffAdd DiffChange DiffDelete DiffText Directory EndOfBuffer ErrorMsg FoldColumn Folded IncSearch LineNr MatchParen Menu ModeMsg MoreMsg NonText Normal Pmenu PmenuSbar PmenuSel PmenuThumb Question Scrollbar Search SignColumn SpecialKey SpellBad SpellCap SpellLocal SpellRare StatusLine StatusLineNC TabLine TabLineFill TabLineSel Title Tooltip VertSplit Visual VisualNOS WarningMsg WildMenu syn keyword vimHLGroup contained ColorColumn Cursor CursorColumn CursorIM CursorLine CursorLineNr DiffAdd DiffChange DiffDelete DiffText Directory EndOfBuffer ErrorMsg FoldColumn Folded IncSearch LineNr MatchParen Menu ModeMsg MoreMsg NonText Normal Pmenu PmenuSbar PmenuSel PmenuThumb Question Scrollbar Search SignColumn SpecialKey SpellBad SpellCap SpellLocal SpellRare StatusLine StatusLineNC TabLine TabLineFill TabLineSel TermCursor TermCursorNC Title Tooltip VertSplit Visual VisualNOS WarningMsg WildMenu
syn match vimHLGroup contained "Conceal" syn match vimHLGroup contained "Conceal"
syn case match syn case match

View File

@ -404,7 +404,9 @@ EXTERN int no_check_timestamps INIT(= 0); /* Don't check timestamps */
typedef enum { typedef enum {
HLF_8 = 0 /* Meta & special keys listed with ":map", text that is HLF_8 = 0 /* Meta & special keys listed with ":map", text that is
displayed different from what it is */ displayed different from what it is */
, HLF_EOB // after the last line in the buffer , HLF_EOB //< after the last line in the buffer
, HLF_TERM //< terminal cursor focused
, HLF_TERMNC //< terminal cursor unfocused
, HLF_AT /* @ characters at end of screen, characters that , HLF_AT /* @ characters at end of screen, characters that
don't really exist in the text */ don't really exist in the text */
, HLF_D /* directories in CTRL-D listing */ , HLF_D /* directories in CTRL-D listing */
@ -451,10 +453,10 @@ typedef enum {
/* The HL_FLAGS must be in the same order as the HLF_ enums! /* The HL_FLAGS must be in the same order as the HLF_ enums!
* When changing this also adjust the default for 'highlight'. */ * When changing this also adjust the default for 'highlight'. */
#define HL_FLAGS {'8', '~', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', 'N', 'r', \ #define HL_FLAGS {'8', '~', 'z', 'Z', '@', 'd', 'e', 'i', 'l', 'm', 'M', 'n', \
's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', 'A', 'C', \ 'N', 'r', 's', 'S', 'c', 't', 'v', 'V', 'w', 'W', 'f', 'F', \
'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', 'x', 'X', \ 'A', 'C', 'D', 'T', '-', '>', 'B', 'P', 'R', 'L', '+', '=', \
'*', '#', '_', '!', '.', 'o'} 'x', 'X', '*', '#', '_', '!', '.', 'o'}
EXTERN int highlight_attr[HLF_COUNT]; /* Highl. attr for each context. */ EXTERN int highlight_attr[HLF_COUNT]; /* Highl. attr for each context. */
EXTERN int highlight_user[9]; /* User[1-9] attributes */ EXTERN int highlight_user[9]; /* User[1-9] attributes */

View File

@ -363,13 +363,14 @@ typedef struct vimoption {
# define ISP_LATIN1 (char_u *)"@,161-255" # define ISP_LATIN1 (char_u *)"@,161-255"
#define HIGHLIGHT_INIT \ #define HIGHLIGHT_INIT \
"8:SpecialKey,~:EndOfBuffer,@:NonText,d:Directory,e:ErrorMsg,i:IncSearch," \ "8:SpecialKey,~:EndOfBuffer,z:TermCursor,Z:TermCursorNC,@:NonText," \
"l:Search,m:MoreMsg,M:ModeMsg,n:LineNr,N:CursorLineNr,r:Question,s:StatusLine," \ "d:Directory,e:ErrorMsg,i:IncSearch,l:Search,m:MoreMsg,M:ModeMsg,n:LineNr," \
"S:StatusLineNC,c:VertSplit,t:Title,v:Visual,V:VisualNOS,w:WarningMsg," \ "N:CursorLineNr,r:Question,s:StatusLine,S:StatusLineNC,c:VertSplit,t:Title," \
"W:WildMenu,f:Folded,F:FoldColumn,A:DiffAdd,C:DiffChange,D:DiffDelete," \ "v:Visual,V:VisualNOS,w:WarningMsg,W:WildMenu,f:Folded,F:FoldColumn," \
"T:DiffText,>:SignColumn,-:Conceal,B:SpellBad,P:SpellCap,R:SpellRare," \ "A:DiffAdd,C:DiffChange,D:DiffDelete,T:DiffText,>:SignColumn,-:Conceal," \
"L:SpellLocal,+:Pmenu,=:PmenuSel,x:PmenuSbar,X:PmenuThumb,*:TabLine," \ "B:SpellBad,P:SpellCap,R:SpellRare,L:SpellLocal,+:Pmenu,=:PmenuSel," \
"#:TabLineSel,_:TabLineFill,!:CursorColumn,.:CursorLine,o:ColorColumn" "x:PmenuSbar,X:PmenuThumb,*:TabLine,#:TabLineSel,_:TabLineFill," \
"!:CursorColumn,.:CursorLine,o:ColorColumn"
/* /*
* options[] is initialized here. * options[] is initialized here.

View File

@ -5785,6 +5785,8 @@ static char *(highlight_init_both[]) =
"TabLineSel term=bold cterm=bold gui=bold"), "TabLineSel term=bold cterm=bold gui=bold"),
CENT("TabLineFill term=reverse cterm=reverse", CENT("TabLineFill term=reverse cterm=reverse",
"TabLineFill term=reverse cterm=reverse gui=reverse"), "TabLineFill term=reverse cterm=reverse gui=reverse"),
CENT("TermCursor cterm=reverse",
"TermCursor cterm=reverse gui=reverse"),
NULL NULL
}; };

View File

@ -130,8 +130,6 @@ struct terminal {
// the default values are used to obtain the color numbers passed to cterm // the default values are used to obtain the color numbers passed to cterm
// colors // colors
RgbValue colors[256]; RgbValue colors[256];
// attributes for focused/unfocused cursor cells
int focused_cursor_attr_id, unfocused_cursor_attr_id;
}; };
static VTermScreenCallbacks vterm_screen_callbacks = { static VTermScreenCallbacks vterm_screen_callbacks = {
@ -260,41 +258,6 @@ Terminal *terminal_open(TerminalOptions opts)
} }
} }
// Configure cursor highlighting when focused/unfocused
char *group = get_config_string(rv, "terminal_focused_cursor_highlight");
if (group) {
int group_id = syn_name2id((uint8_t *)group);
free(group);
if (group_id) {
rv->focused_cursor_attr_id = syn_id2attr(group_id);
}
}
if (!rv->focused_cursor_attr_id) {
rv->focused_cursor_attr_id = get_attr_entry(&(attrentry_T) {
.rgb_ae_attr = HL_INVERSE, .rgb_fg_color = -1, .rgb_bg_color = -1,
.cterm_ae_attr = HL_INVERSE, .cterm_fg_color = 0, .cterm_bg_color = 0
});
}
group = get_config_string(rv, "terminal_unfocused_cursor_highlight");
if (group) {
int group_id = syn_name2id((uint8_t *)group);
free(group);
if (group_id) {
rv->unfocused_cursor_attr_id = syn_id2attr(group_id);
}
}
if (!rv->unfocused_cursor_attr_id) {
int yellow_rgb = RGB(0xfc, 0xe9, 0x4f);
int yellow_term = 12;
rv->unfocused_cursor_attr_id = get_attr_entry(&(attrentry_T) {
.rgb_ae_attr = 0, .rgb_fg_color = -1, .rgb_bg_color = yellow_rgb,
.cterm_ae_attr = 0, .cterm_fg_color = 0, .cterm_bg_color = yellow_term,
});
}
return rv; return rv;
} }
@ -555,7 +518,7 @@ void terminal_get_line_attributes(Terminal *term, win_T *wp, int linenr,
if (term->cursor.visible && term->cursor.row == row if (term->cursor.visible && term->cursor.row == row
&& term->cursor.col == col) { && term->cursor.col == col) {
attr_id = hl_combine_attr(attr_id, is_focused(term) && wp == curwin ? attr_id = hl_combine_attr(attr_id, is_focused(term) && wp == curwin ?
term->focused_cursor_attr_id : term->unfocused_cursor_attr_id); hl_attr(HLF_TERM) : hl_attr(HLF_TERMNC));
} }
term_attrs[col] = attr_id; term_attrs[col] = attr_id;

View File

@ -24,10 +24,10 @@ describe(':highlight', function()
guifg=Blue | guifg=Blue |
EndOfBuffer xxx links to NonText| EndOfBuffer xxx links to NonText|
| |
TermCursor xxx cterm=reverse |
gui=reverse |
TermCursorNC xxx cleared |
NonText xxx ctermfg=12 | NonText xxx ctermfg=12 |
gui=bold |
guifg=Blue |
Directory xxx ctermfg=4 |
-- More --^ | -- More --^ |
]]) ]])
feed('q') feed('q')

View File

@ -129,10 +129,8 @@ describe('cursor with customized highlighting', function()
before_each(function() before_each(function()
clear() clear()
nvim('set_var', 'terminal_focused_cursor_highlight', 'CursorFocused') nvim('command', 'highlight TermCursor ctermfg=45 ctermbg=46 cterm=NONE')
nvim('set_var', 'terminal_unfocused_cursor_highlight', 'CursorUnfocused') nvim('command', 'highlight TermCursorNC ctermfg=55 ctermbg=56 cterm=NONE')
nvim('command', 'highlight CursorFocused ctermfg=45 ctermbg=46')
nvim('command', 'highlight CursorUnfocused ctermfg=55 ctermbg=56')
screen = Screen.new(50, 7) screen = Screen.new(50, 7)
screen:set_default_attr_ids({ screen:set_default_attr_ids({
[1] = {foreground = 45, background = 46}, [1] = {foreground = 45, background = 46},

View File

@ -34,6 +34,8 @@ local function disable_mouse() feed_termcode('[?1002l') end
local function screen_setup(extra_height) local function screen_setup(extra_height)
nvim('command', 'highlight TermCursor cterm=reverse')
nvim('command', 'highlight TermCursorNC ctermbg=11')
nvim('set_var', 'terminal_scrollback_buffer_size', 10) nvim('set_var', 'terminal_scrollback_buffer_size', 10)
if not extra_height then extra_height = 0 end if not extra_height then extra_height = 0 end
local screen = Screen.new(50, 7 + extra_height) local screen = Screen.new(50, 7 + extra_height)