dte test coverage


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 50.0% high: ≥ 85.0%
Coverage Exec / Excl / Total
Lines: 100.0% 12 / 0 / 12
Functions: 100.0% 4 / 0 / 4
Branches: 100.0% 14 / 0 / 14

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