dte test coverage


Directory: ./
File: src/terminal/style.h
Date: 2025-12-11 10:43:49
Coverage Exec Excl Total
Lines: 100.0% 12 0 12
Functions: 100.0% 4 0 4
Branches: 100.0% 14 0 14

Line Branch Exec Source
1 #ifndef TERMINAL_STYLE_H
2 #define TERMINAL_STYLE_H
3
4 #include <stdbool.h>
5 #include <stdint.h>
6 #include <sys/types.h>
7 #include "color.h"
8 #include "util/macros.h"
9 #include "util/ptr-array.h"
10
11 #define COLOR_STR_BUFSIZE 16
12 #define TERM_STYLE_BUFSIZE 128
13
14 enum {
15 ATTR_KEEP = 0x01,
16 ATTR_UNDERLINE = 0x02,
17 ATTR_REVERSE = 0x04,
18 ATTR_BLINK = 0x08,
19 ATTR_DIM = 0x10,
20 ATTR_BOLD = 0x20,
21 ATTR_INVIS = 0x40,
22 ATTR_ITALIC = 0x80,
23 ATTR_STRIKETHROUGH = 0x100,
24 ATTR_ALL = (ATTR_STRIKETHROUGH << 1) - 1,
25 };
26
27 typedef struct DESIGNATED_INIT {
28 int32_t fg;
29 int32_t bg;
30 unsigned int attr;
31 } TermStyle;
32
33 5 static inline TermStyle term_style(int32_t fg, int32_t bg, unsigned int attr)
34 {
35 5 return (TermStyle){.fg = fg, .bg = bg, .attr = attr};
36 }
37
38 418 static inline bool same_style(const TermStyle *a, const TermStyle *b)
39 {
40
6/6
✓ Branch 2 → 3 taken 253 times.
✓ Branch 2 → 5 taken 165 times.
✓ Branch 3 → 4 taken 250 times.
✓ Branch 3 → 5 taken 3 times.
✓ Branch 4 → 5 taken 8 times.
✓ Branch 4 → 6 taken 242 times.
418 return a->fg == b->fg && a->bg == b->bg && a->attr == b->attr;
41 }
42
43 7 static inline void mask_style2(TermStyle *style, const TermStyle *over, bool mask_bg)
44 {
45 14 *style = (TermStyle) {
46
2/2
✓ Branch 2 → 3 taken 2 times.
✓ Branch 2 → 4 taken 5 times.
7 .fg = (over->fg == COLOR_KEEP) ? style->fg : over->fg,
47
4/4
✓ Branch 4 → 5 taken 3 times.
✓ Branch 4 → 6 taken 4 times.
✓ Branch 5 → 6 taken 1 time.
✓ Branch 5 → 7 taken 2 times.
7 .bg = (over->bg == COLOR_KEEP || !mask_bg) ? style->bg : over->bg,
48
2/2
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 6 times.
7 .attr = (over->attr & ATTR_KEEP) ? style->attr : over->attr,
49 };
50 7 }
51
52 3 static inline void mask_style(TermStyle *style, const TermStyle *over)
53 {
54 3 return mask_style2(style, over, true);
55 }
56
57 ssize_t parse_term_style(TermStyle *style, char **strs, size_t nstrs) NONNULL_ARGS WARN_UNUSED_RESULT;
58 size_t color_to_str(char buf[static COLOR_STR_BUFSIZE], int32_t color) NONNULL_ARGS WARN_UNUSED_RESULT;
59 const char *term_style_to_string(char buf[static TERM_STYLE_BUFSIZE], const TermStyle *style) NONNULL_ARGS_AND_RETURN;
60 void collect_colors_and_attributes(PointerArray *a, const char *prefix) NONNULL_ARGS;
61
62 #endif
63