feat(highlight): support for blend in nvim_set_hl (#17516)

This commit is contained in:
Lewis Russell 2022-02-24 16:50:05 +00:00 committed by GitHub
parent 73da7cef7b
commit b5bf4877c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 0 deletions

View File

@ -97,6 +97,7 @@ return {
"special"; "sp";
"link";
"fallback";
"blend";
"temp";
};
highlight_cterm = {

View File

@ -800,6 +800,7 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
{
HlAttrs hlattrs = HLATTRS_INIT;
int32_t fg = -1, bg = -1, ctermfg = -1, ctermbg = -1, sp = -1;
int blend = -1;
int16_t mask = 0;
int16_t cterm_mask = 0;
bool cterm_mask_provided = false;
@ -847,6 +848,20 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
return hlattrs;
}
if (dict->blend.type == kObjectTypeInteger) {
Integer blend0 = dict->blend.data.integer;
if (blend0 < 0 || blend0 > 100) {
api_set_error(err, kErrorTypeValidation, "'blend' is not between 0 to 100");
} else {
blend = (int)blend0;
}
} else if (HAS_KEY(dict->blend)) {
api_set_error(err, kErrorTypeValidation, "'blend' must be an integer");
}
if (ERROR_SET(err)) {
return hlattrs;
}
if (HAS_KEY(dict->link)) {
if (link_id) {
*link_id = object_to_hl_id(dict->link, "link", err);
@ -908,6 +923,7 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
hlattrs.rgb_bg_color = bg;
hlattrs.rgb_fg_color = fg;
hlattrs.rgb_sp_color = sp;
hlattrs.hl_blend = blend;
hlattrs.cterm_bg_color = ctermbg == -1 ? 0 : ctermbg + 1;
hlattrs.cterm_fg_color = ctermfg == -1 ? 0 : ctermfg + 1;
hlattrs.cterm_ae_attr = cterm_mask;

View File

@ -323,5 +323,9 @@ describe("API: set highlight", function()
exec_capture('highlight Test_hl3'))
end
meths.set_hl(0, 'Test_hl3', {fg='#FF00FF', blend=50})
eq('Test_hl3 xxx guifg=#FF00FF blend=50',
exec_capture('highlight Test_hl3'))
end)
end)