Changed prototypes to accept a boolean "rgb"

This commit is contained in:
Matthieu Coudron
2017-09-03 05:25:57 +02:00
parent e3a2cca387
commit 3a00648639
3 changed files with 17 additions and 17 deletions

View File

@@ -59,9 +59,10 @@ void nvim_command(String command, Error *err)
/// Retrieves highlight description from its name
///
/// @param name Highlight group name
/// @param rgb True to export GUI values
/// @return a highlight description e.g. {'bold': true, 'bg': 123, 'fg': 42}
/// @see nvim_get_hl_by_id
Dictionary nvim_get_hl_by_name(String name, Error *err)
Dictionary nvim_get_hl_by_name(String name, Boolean rgb, Error *err)
FUNC_API_SINCE(3)
{
Dictionary result = ARRAY_DICT_INIT;
@@ -72,15 +73,16 @@ Dictionary nvim_get_hl_by_name(String name, Error *err)
name.data);
return result;
}
result = nvim_get_hl_by_id(id, err);
result = nvim_get_hl_by_id(id, rgb, err);
return result;
}
/// Retrieves highlight description from its id
///
/// @param hl_id highlight id as returned by |hlID()|
/// @param rgb True to export GUI values
/// @see nvim_get_hl_by_name
Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err)
Dictionary nvim_get_hl_by_id(Integer hl_id, Boolean rgb, Error *err)
FUNC_API_SINCE(3)
{
Dictionary dic = ARRAY_DICT_INIT;
@@ -89,7 +91,7 @@ Dictionary nvim_get_hl_by_id(Integer hl_id, Error *err)
return dic;
}
int attrcode = syn_id2attr((int)hl_id);
return hl_get_attr_by_id(attrcode, err);
return hl_get_attr_by_id(attrcode, rgb, err);
}
/// Passes input keys to Nvim.

View File

@@ -8224,7 +8224,7 @@ RgbValue name_to_color(const uint8_t *name)
/// Retrieves attribute description from its id
///
/// @param attr_id attribute id
Dictionary hl_get_attr_by_id(Integer attr_id, Error *err)
Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Error *err)
{
HlAttrs attrs = HLATTRS_INIT;
Dictionary dic = ARRAY_DICT_INIT;
@@ -8240,7 +8240,7 @@ Dictionary hl_get_attr_by_id(Integer attr_id, Error *err)
return dic;
}
attrs = attrentry2hlattrs(aep, p_tgc);
attrs = attrentry2hlattrs(aep, rgb);
end:
return hlattrs2dict(attrs);

View File

@@ -27,14 +27,13 @@ describe('highlight api',function()
it("nvim_get_hl_by_id", function()
local hl_id = eval("hlID('NewHighlight')")
eq(expected_cterm, nvim("get_hl_by_id", hl_id))
eq(expected_cterm, nvim("get_hl_by_id", hl_id, false))
command('set termguicolors')
hl_id = eval("hlID('NewHighlight')")
eq(expected_rgb, nvim("get_hl_by_id", hl_id))
eq(expected_rgb, nvim("get_hl_by_id", hl_id, true))
-- assume there is no hl with id 30000
local err, emsg = pcall(meths.get_hl_by_id, 30000)
-- assume there is no hl with id = 30000
local err, emsg = pcall(meths.get_hl_by_id, 30000, false)
eq(false, err)
ok(string.find(emsg, 'Invalid highlight id') ~= nil)
end)
@@ -44,16 +43,15 @@ describe('highlight api',function()
foreground = Screen.colors.Red }
-- test "Normal" hl defaults
eq({}, nvim("get_hl_by_name", 'Normal'))
eq({}, nvim("get_hl_by_name", 'Normal', true))
eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight'))
command('set termguicolors')
eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight'))
eq(expected_cterm, nvim("get_hl_by_name", 'NewHighlight', false))
eq(expected_rgb, nvim("get_hl_by_name", 'NewHighlight', true))
command('hi Normal guifg=red guibg=yellow')
eq(expected_normal, nvim("get_hl_by_name", 'Normal'))
eq(expected_normal, nvim("get_hl_by_name", 'Normal', true))
local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight')
local err, emsg = pcall(meths.get_hl_by_name , 'unknown_highlight', false)
eq(false, err)
ok(string.find(emsg, 'Invalid highlight name') ~= nil)
end)