aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/highlight.c
diff options
context:
space:
mode:
authorNull Chilly <56817415+nullchilly@users.noreply.github.com>2023-03-23 16:31:39 +0700
committerGitHub <noreply@github.com>2023-03-23 10:31:39 +0100
commitc0fe6c040e19ef9102a8507ffcbd88b83186326a (patch)
treeabaecffb9bfd97ae0f00502c7560eb001100c135 /src/nvim/highlight.c
parentea0b66d208dbcd5d5c0a17810596d769c7a0b6dd (diff)
downloadrneovim-c0fe6c040e19ef9102a8507ffcbd88b83186326a.tar.gz
rneovim-c0fe6c040e19ef9102a8507ffcbd88b83186326a.tar.bz2
rneovim-c0fe6c040e19ef9102a8507ffcbd88b83186326a.zip
feat(api): add nvim_get_hl (#22693)
Problem: no way of getting all highlight group definitions in a namespace. Solution: add `nvim_get_hl()`, deprecate `nvim_get_hl_by_name()` and `nvim_get_hl_by_id()`.
Diffstat (limited to 'src/nvim/highlight.c')
-rw-r--r--src/nvim/highlight.c34
1 files changed, 19 insertions, 15 deletions
diff --git a/src/nvim/highlight.c b/src/nvim/highlight.c
index 305e84276c..a97f8f4142 100644
--- a/src/nvim/highlight.c
+++ b/src/nvim/highlight.c
@@ -821,7 +821,7 @@ Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Arena *arena, Error *
return dic;
}
Dictionary retval = arena_dict(arena, HLATTRS_DICT_SIZE);
- hlattrs2dict(&retval, syn_attr2entry((int)attr_id), rgb);
+ hlattrs2dict(&retval, syn_attr2entry((int)attr_id), rgb, false);
return retval;
}
@@ -830,7 +830,9 @@ Dictionary hl_get_attr_by_id(Integer attr_id, Boolean rgb, Arena *arena, Error *
/// @param[in/out] hl Dictionary with pre-allocated space for HLATTRS_DICT_SIZE elements
/// @param[in] aep data to convert
/// @param use_rgb use 'gui*' settings if true, else resorts to 'cterm*'
-void hlattrs2dict(Dictionary *dict, HlAttrs ae, bool use_rgb)
+/// @param short_keys change (foreground, background, special) to (fg, bg, sp) for 'gui*' settings
+/// (foreground, background) to (ctermfg, ctermbg) for 'cterm*' settings
+void hlattrs2dict(Dictionary *dict, HlAttrs ae, bool use_rgb, bool short_keys)
{
assert(dict->capacity >= HLATTRS_DICT_SIZE); // at most 16 items
Dictionary hl = *dict;
@@ -887,32 +889,34 @@ void hlattrs2dict(Dictionary *dict, HlAttrs ae, bool use_rgb)
}
if (use_rgb) {
- if (mask & HL_FG_INDEXED) {
- PUT_C(hl, "fg_indexed", BOOLEAN_OBJ(true));
- }
-
- if (mask & HL_BG_INDEXED) {
- PUT_C(hl, "bg_indexed", BOOLEAN_OBJ(true));
- }
-
if (ae.rgb_fg_color != -1) {
- PUT_C(hl, "foreground", INTEGER_OBJ(ae.rgb_fg_color));
+ PUT_C(hl, short_keys ? "fg" : "foreground", INTEGER_OBJ(ae.rgb_fg_color));
}
if (ae.rgb_bg_color != -1) {
- PUT_C(hl, "background", INTEGER_OBJ(ae.rgb_bg_color));
+ PUT_C(hl, short_keys ? "bg" : "background", INTEGER_OBJ(ae.rgb_bg_color));
}
if (ae.rgb_sp_color != -1) {
- PUT_C(hl, "special", INTEGER_OBJ(ae.rgb_sp_color));
+ PUT_C(hl, short_keys ? "sp" : "special", INTEGER_OBJ(ae.rgb_sp_color));
+ }
+
+ if (!short_keys) {
+ if (mask & HL_FG_INDEXED) {
+ PUT_C(hl, "fg_indexed", BOOLEAN_OBJ(true));
+ }
+
+ if (mask & HL_BG_INDEXED) {
+ PUT_C(hl, "bg_indexed", BOOLEAN_OBJ(true));
+ }
}
} else {
if (ae.cterm_fg_color != 0) {
- PUT_C(hl, "foreground", INTEGER_OBJ(ae.cterm_fg_color - 1));
+ PUT_C(hl, short_keys ? "ctermfg" : "foreground", INTEGER_OBJ(ae.cterm_fg_color - 1));
}
if (ae.cterm_bg_color != 0) {
- PUT_C(hl, "background", INTEGER_OBJ(ae.cterm_bg_color - 1));
+ PUT_C(hl, short_keys ? "ctermbg" : "background", INTEGER_OBJ(ae.cterm_bg_color - 1));
}
}