diff options
| author | wrmr | 2025-10-11 18:14:11 -0400 |
|---|---|---|
| committer | wrmr | 2025-10-11 18:14:11 -0400 |
| commit | b4223e982383c6bd73f3b1fe912bc0d5f5483f56 (patch) | |
| tree | fe8174e3f95690734aa43fe0ad3df3da0b9d1f7d | |
| parent | 34a6d1352452ad7aabfe3c849d75101c8cddbe8d (diff) | |
parse attributes for colors
| -rw-r--r-- | main.c | 49 |
1 files changed, 42 insertions, 7 deletions
@@ -913,6 +913,7 @@ void init_curses(void) { } else { use_default_colors(); } + bkgdset(' ' | opt.color[0].attr); for (ColorPair i = 1; i < CPAIR_MAX; i++) { if (opt.color[i].init) { init_pair(i, opt.color[i].fg, opt.color[i].bg); @@ -1046,19 +1047,53 @@ int parse_color(Str s) { return BAD_COLOR; } +int parse_attr(Str s) { + static struct { + Str s; + int v; + } attr_map[] = { + { Ss("standout"), A_STANDOUT }, + { Ss("underline"), A_UNDERLINE }, + { Ss("reverse"), A_REVERSE }, + { Ss("blink"), A_BLINK }, + { Ss("dim"), A_DIM }, + { Ss("bold"), A_BOLD }, + { Ss("italic"), A_ITALIC }, + }; + for (size_t i = 0; i < sizeof attr_map / sizeof *attr_map; i++) { + if (str_eql(s, attr_map[i].s)) { + return attr_map[i].v; + } + } + return 0; +} + int sect_color(Str k, Str v, Arena *perm) { (void)perm; for (int i = 0; i < CPAIR_MAX; i++) { if (!str_eql(k, cpair_name[i])) continue; - Cut c = str_cut(v, ':'); - int fg = parse_color(str_trim(c.head)); - int bg = parse_color(str_trim(c.tail)); - if (fg == BAD_COLOR || bg == BAD_COLOR) return -1; + Str s = v; opt.color[i] = (ColorOpt) { - .fg = fg, - .bg = bg, - .init = 1 + .fg = COLOR_NORM, + .bg = COLOR_NORM, + .attr = 0, + .init = 1, }; + for (;;) { + Cut k = str_cut(s, ','); + s = k.tail; + if (!k.head.n) break; + int attr = parse_attr(k.head); + if (!attr) { + Cut c = str_cut(k.head, ':'); + int fg = parse_color(str_trim(c.head)); + int bg = parse_color(str_trim(c.tail)); + if (fg == BAD_COLOR || bg == BAD_COLOR) return -1; + opt.color[i].fg = fg; + opt.color[i].bg = bg; + } + opt.color[i].attr |= attr; + } } return -1; } |
