| 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 | }; | ||
| 25 | |||
| 26 | typedef struct { | ||
| 27 | int32_t fg; | ||
| 28 | int32_t bg; | ||
| 29 | unsigned int attr; | ||
| 30 | } TermStyle; | ||
| 31 | |||
| 32 | 5 | static inline TermStyle term_style(int32_t fg, int32_t bg, unsigned int attr) | |
| 33 | { | ||
| 34 | 5 | return (TermStyle){.fg = fg, .bg = bg, .attr = attr}; | |
| 35 | } | ||
| 36 | |||
| 37 | 418 | static inline bool same_style(const TermStyle *a, const TermStyle *b) | |
| 38 | { | ||
| 39 | 
        6/6✓ Branch 0 (2→3) taken 253 times. 
            ✓ Branch 1 (2→5) taken 165 times. 
            ✓ Branch 2 (3→4) taken 250 times. 
            ✓ Branch 3 (3→5) taken 3 times. 
            ✓ Branch 4 (4→5) taken 8 times. 
            ✓ Branch 5 (4→6) taken 242 times. 
           | 
      418 | return a->fg == b->fg && a->bg == b->bg && a->attr == b->attr; | 
| 40 | } | ||
| 41 | |||
| 42 | 7 | static inline void mask_style2(TermStyle *style, const TermStyle *over, bool mask_bg) | |
| 43 | { | ||
| 44 | 14 | *style = (TermStyle) { | |
| 45 | 
        2/2✓ Branch 0 (2→3) taken 2 times. 
            ✓ Branch 1 (2→4) taken 5 times. 
           | 
      7 | .fg = (over->fg == COLOR_KEEP) ? style->fg : over->fg, | 
| 46 | 
        4/4✓ Branch 0 (4→5) taken 3 times. 
            ✓ Branch 1 (4→6) taken 4 times. 
            ✓ Branch 2 (5→6) taken 1 times. 
            ✓ Branch 3 (5→7) taken 2 times. 
           | 
      7 | .bg = (over->bg == COLOR_KEEP || !mask_bg) ? style->bg : over->bg, | 
| 47 | 
        2/2✓ Branch 0 (7→8) taken 1 times. 
            ✓ Branch 1 (7→9) taken 6 times. 
           | 
      7 | .attr = (over->attr & ATTR_KEEP) ? style->attr : over->attr, | 
| 48 | }; | ||
| 49 | 7 | } | |
| 50 | |||
| 51 | 3 | static inline void mask_style(TermStyle *style, const TermStyle *over) | |
| 52 | { | ||
| 53 | 3 | return mask_style2(style, over, true); | |
| 54 | } | ||
| 55 | |||
| 56 | ssize_t parse_term_style(TermStyle *style, char **strs, size_t nstrs) NONNULL_ARGS WARN_UNUSED_RESULT; | ||
| 57 | size_t color_to_str(char buf[static COLOR_STR_BUFSIZE], int32_t color) NONNULL_ARGS WARN_UNUSED_RESULT; | ||
| 58 | const char *term_style_to_string(char buf[static TERM_STYLE_BUFSIZE], const TermStyle *style) NONNULL_ARGS_AND_RETURN; | ||
| 59 | void collect_colors_and_attributes(PointerArray *a, const char *prefix) NONNULL_ARGS; | ||
| 60 | |||
| 61 | #endif | ||
| 62 |