dte test coverage


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