dte test coverage


Directory: ./
File: src/terminal/cursor.c
Date: 2024-12-21 16:03:22
Exec Total Coverage
Lines: 34 34 100.0%
Functions: 10 10 100.0%
Branches: 2 2 100.0%

Line Branch Exec Source
1 #include <string.h>
2 #include "cursor.h"
3 #include "style.h"
4 #include "util/array.h"
5 #include "util/debug.h"
6
7 static const char cursor_modes[NR_CURSOR_MODES][12] = {
8 [CURSOR_MODE_DEFAULT] = "default",
9 [CURSOR_MODE_INSERT] = "insert",
10 [CURSOR_MODE_OVERWRITE] = "overwrite",
11 [CURSOR_MODE_CMDLINE] = "cmdline",
12 };
13
14 static const char cursor_types[][20] = {
15 [CURSOR_DEFAULT] = "default",
16 [CURSOR_BLINKING_BLOCK] = "blinking-block",
17 [CURSOR_STEADY_BLOCK] = "block",
18 [CURSOR_BLINKING_UNDERLINE] = "blinking-underline",
19 [CURSOR_STEADY_UNDERLINE] = "underline",
20 [CURSOR_BLINKING_BAR] = "blinking-bar",
21 [CURSOR_STEADY_BAR] = "bar",
22 [CURSOR_KEEP] = "keep",
23 };
24
25 static const char cursor_colors[][8] = {
26 "keep",
27 "default",
28 };
29
30 18 UNITTEST {
31 18 CHECK_STRING_ARRAY(cursor_modes);
32 18 CHECK_STRING_ARRAY(cursor_types);
33 18 CHECK_STRING_ARRAY(cursor_colors);
34 18 }
35
36 4 const char *cursor_mode_to_str(CursorInputMode mode)
37 {
38 4 BUG_ON(mode < 0 || mode >= ARRAYLEN(cursor_modes));
39 4 return cursor_modes[mode];
40 }
41
42 5 const char *cursor_type_to_str(TermCursorType type)
43 {
44 5 BUG_ON(type < 0 || type >= ARRAYLEN(cursor_types));
45 5 return cursor_types[type];
46 }
47
48 7 const char *cursor_color_to_str(char buf[COLOR_STR_BUFSIZE], int32_t color)
49 {
50 7 BUG_ON(!cursor_color_is_valid(color));
51 7 size_t n = color_to_str(buf, color);
52 7 BUG_ON(n < STRLEN("keep") || n >= COLOR_STR_BUFSIZE);
53 7 buf[n] = '\0';
54 7 return buf;
55 }
56
57 12 CursorInputMode cursor_mode_from_str(const char *name)
58 {
59 12 return STR_TO_ENUM(name, cursor_modes, NR_CURSOR_MODES);
60 }
61
62 15 TermCursorType cursor_type_from_str(const char *name)
63 {
64 15 return STR_TO_ENUM(name, cursor_types, CURSOR_INVALID);
65 }
66
67 12 int32_t cursor_color_from_str(const char *str)
68 {
69
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 7 times.
12 if (str[0] == '#') {
70 5 return parse_rgb(str + 1, strlen(str + 1));
71 }
72 7 return STR_TO_ENUM_WITH_OFFSET(str, cursor_colors, COLOR_INVALID, -2);
73 }
74
75 1 void collect_cursor_modes(PointerArray *a, const char *prefix)
76 {
77 1 COLLECT_STRINGS(cursor_modes, a, prefix);
78 1 }
79
80 2 void collect_cursor_types(PointerArray *a, const char *prefix)
81 {
82 2 COLLECT_STRINGS(cursor_types, a, prefix);
83 2 }
84
85 1 void collect_cursor_colors(PointerArray *a, const char *prefix)
86 {
87 1 COLLECT_STRINGS(cursor_colors, a, prefix);
88 1 }
89