@@ -821,27 +821,27 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
821
821
CHECK_FLAG(dict, mask, global, , HL_GLOBAL);
822
822
823
823
if (HAS_KEY(dict->fg)) {
824
-
fg = object_to_color(dict->fg, "fg", err);
824
+
fg = object_to_color(dict->fg, "fg", true, err);
825
825
} else if (HAS_KEY(dict->foreground)) {
826
-
fg = object_to_color(dict->foreground, "foreground", err);
826
+
fg = object_to_color(dict->foreground, "foreground", true, err);
827
827
}
828
828
if (ERROR_SET(err)) {
829
829
return hlattrs;
830
830
}
831
831
832
832
if (HAS_KEY(dict->bg)) {
833
-
bg = object_to_color(dict->bg, "bg", err);
833
+
bg = object_to_color(dict->bg, "bg", true, err);
834
834
} else if (HAS_KEY(dict->background)) {
835
-
bg = object_to_color(dict->background, "background", err);
835
+
bg = object_to_color(dict->background, "background", true, err);
836
836
}
837
837
if (ERROR_SET(err)) {
838
838
return hlattrs;
839
839
}
840
840
841
841
if (HAS_KEY(dict->sp)) {
842
-
sp = object_to_color(dict->sp, "sp", err);
842
+
sp = object_to_color(dict->sp, "sp", true, err);
843
843
} else if (HAS_KEY(dict->special)) {
844
-
sp = object_to_color(dict->special, "special", err);
844
+
sp = object_to_color(dict->special, "special", true, err);
845
845
}
846
846
if (ERROR_SET(err)) {
847
847
return hlattrs;
@@ -882,14 +882,14 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
882
882
#undef CHECK_FLAG
883
883
884
884
if (HAS_KEY(dict->ctermfg)) {
885
-
ctermfg = object_to_color(dict->ctermfg, "ctermfg", err);
885
+
ctermfg = object_to_color(dict->ctermfg, "ctermfg", false, err);
886
886
if (ERROR_SET(err)) {
887
887
return hlattrs;
888
888
}
889
889
}
890
890
891
891
if (HAS_KEY(dict->ctermbg)) {
892
-
ctermbg = object_to_color(dict->ctermbg, "ctermbg", err);
892
+
ctermbg = object_to_color(dict->ctermbg, "ctermbg", false, err);
893
893
if (ERROR_SET(err)) {
894
894
return hlattrs;
895
895
}
@@ -916,14 +916,25 @@ HlAttrs dict2hlattrs(Dict(highlight) *dict, bool use_rgb, int *link_id, Error *e
916
916
return hlattrs;
917
917
}
918
918
919
-
int object_to_color(Object val, char *key, Error *err)
919
+
int object_to_color(Object val, char *key, bool rgb, Error *err)
920
920
{
921
921
if (val.type == kObjectTypeInteger) {
922
922
return (int)val.data.integer;
923
923
} else if (val.type == kObjectTypeString) {
924
924
String str = val.data.string;
925
925
// TODO(bfredl): be more fancy with "bg", "fg" etc
926
-
return str.size ? name_to_color(str.data) : 0;
926
+
int color;
927
+
if (!str.size) {
928
+
color = 0;
929
+
} else if (rgb) {
930
+
color = name_to_color(str.data);
931
+
} else {
932
+
color = name_to_ctermcolor(str.data);
933
+
}
934
+
if (color < 0) {
935
+
api_set_error(err, kErrorTypeValidation, "'%s' is not a valid color", str.data);
936
+
}
937
+
return color;
927
938
} else {
928
939
api_set_error(err, kErrorTypeValidation, "'%s' must be string or integer", key);
929
940
return 0;
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4