Line | Branch | Exec | Source |
---|---|---|---|
1 | #ifndef TERMINAL_CURSOR_H | ||
2 | #define TERMINAL_CURSOR_H | ||
3 | |||
4 | #include <stdbool.h> | ||
5 | #include <stdint.h> | ||
6 | #include "terminal/color.h" | ||
7 | #include "terminal/terminal.h" | ||
8 | #include "util/macros.h" | ||
9 | #include "util/ptr-array.h" | ||
10 | |||
11 | typedef enum { | ||
12 | CURSOR_MODE_DEFAULT, // Fallback, for modes left unspecified | ||
13 | CURSOR_MODE_INSERT, // Normal mode with `set overwrite false` | ||
14 | CURSOR_MODE_OVERWRITE, // Normal mode with `set overwrite true` | ||
15 | CURSOR_MODE_CMDLINE, // Command or search mode | ||
16 | NR_CURSOR_MODES, | ||
17 | } CursorInputMode; | ||
18 | |||
19 | 9 | static inline bool cursor_color_is_valid(int32_t c) | |
20 | { | ||
21 |
3/4✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→5) taken 7 times.
✓ Branch 2 (3→4) taken 2 times.
✗ Branch 3 (3→5) not taken.
|
9 | return c == COLOR_KEEP || c == COLOR_DEFAULT || color_is_rgb(c); |
22 | } | ||
23 | |||
24 | 2 | static inline bool cursor_type_is_valid(TermCursorType type) | |
25 | { | ||
26 | 2 | return type >= CURSOR_DEFAULT && type <= CURSOR_KEEP; | |
27 | } | ||
28 | |||
29 | 5 | static inline bool same_cursor(const TermCursorStyle *a, const TermCursorStyle *b) | |
30 | { | ||
31 |
4/4✓ Branch 0 (2→3) taken 4 times.
✓ Branch 1 (2→4) taken 1 times.
✓ Branch 2 (3→4) taken 1 times.
✓ Branch 3 (3→5) taken 3 times.
|
5 | return a->type == b->type && a->color == b->color; |
32 | } | ||
33 | |||
34 | 4 | static inline TermCursorStyle get_default_cursor_style(CursorInputMode mode) | |
35 | { | ||
36 | 4 | bool is_default_mode = (mode == CURSOR_MODE_DEFAULT); | |
37 | 8 | return (TermCursorStyle) { | |
38 |
2/2✓ Branch 0 (2→3) taken 3 times.
✓ Branch 1 (2→4) taken 1 times.
|
4 | .type = is_default_mode ? CURSOR_DEFAULT : CURSOR_KEEP, |
39 | .color = is_default_mode ? COLOR_DEFAULT : COLOR_KEEP, | ||
40 | }; | ||
41 | } | ||
42 | |||
43 | const char *cursor_mode_to_str(CursorInputMode mode) RETURNS_NONNULL; | ||
44 | const char *cursor_type_to_str(TermCursorType type) RETURNS_NONNULL; | ||
45 | const char *cursor_color_to_str(char buf[COLOR_STR_BUFSIZE], int32_t color) NONNULL_ARGS_AND_RETURN; | ||
46 | CursorInputMode cursor_mode_from_str(const char *name) NONNULL_ARGS; | ||
47 | TermCursorType cursor_type_from_str(const char *name) NONNULL_ARGS; | ||
48 | int32_t cursor_color_from_str(const char *str) NONNULL_ARGS; | ||
49 | void collect_cursor_modes(PointerArray *a, const char *prefix) NONNULL_ARGS; | ||
50 | void collect_cursor_types(PointerArray *a, const char *prefix) NONNULL_ARGS; | ||
51 | void collect_cursor_colors(PointerArray *a, const char *prefix) NONNULL_ARGS; | ||
52 | |||
53 | #endif | ||
54 |