-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paththeme.c
144 lines (123 loc) · 5.66 KB
/
theme.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*
* Copyright (C) 2015 Richard Burke
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include <assert.h>
#include "theme.h"
#include "util.h"
/* Create the default theme. This theme is set during session
* initialisation and ensures that wed always has a theme available
* as it is not overwritable (see session.c) */
/* All custom themes specified by the user in config extend this theme
* i.e. Any screen components not set by the user have the same
* theme group values as the default theme */
Theme *th_get_default_theme(void)
{
Theme *theme = malloc(sizeof(Theme));
RETURN_IF_NULL(theme);
theme->groups[ST_NORMAL] = TG_VAL(DC_NONE , DC_NONE , DA_NONE);
theme->groups[ST_COMMENT] = TG_VAL(DC_BLUE , DC_NONE , DA_NONE);
theme->groups[ST_CONSTANT] = TG_VAL(DC_RED , DC_NONE , DA_NONE);
theme->groups[ST_SPECIAL] = TG_VAL(DC_MAGENTA, DC_NONE , DA_NONE);
theme->groups[ST_IDENTIFIER] = TG_VAL(DC_CYAN , DC_NONE , DA_NONE);
theme->groups[ST_STATEMENT] = TG_VAL(DC_YELLOW , DC_NONE , DA_NONE);
theme->groups[ST_TYPE] = TG_VAL(DC_GREEN , DC_NONE , DA_NONE);
theme->groups[ST_ERROR] = TG_VAL(DC_WHITE , DC_RED , DA_NONE);
theme->groups[ST_TODO] = TG_VAL(DC_NONE , DC_YELLOW, DA_NONE);
theme->groups[SC_LINENO] = TG_VAL(DC_YELLOW, DC_NONE , DA_NONE);
theme->groups[SC_BUFFER_TAB_BAR] = TG_VAL(DC_BLUE , DC_WHITE , DA_NONE);
theme->groups[SC_ACTIVE_BUFFER_TAB_BAR] = TG_VAL(DC_WHITE , DC_BLUE , DA_NONE);
theme->groups[SC_STATUS_BAR] = TG_VAL(DC_YELLOW, DC_BLUE , DA_NONE);
theme->groups[SC_ERROR_MESSAGE] = TG_VAL(DC_WHITE , DC_RED , DA_NONE);
theme->groups[SC_BUFFER_END] = TG_VAL(DC_BLUE , DC_NONE , DA_NONE);
theme->groups[SC_COLORCOLUMN] = TG_VAL(DC_NONE , DC_RED , DA_NONE);
theme->groups[SC_SEARCH_MATCH] = TG_VAL(DC_BLACK , DC_YELLOW, DA_NONE);
theme->groups[SC_PRIMARY_SEARCH_MATCH] = TG_VAL(DC_BLACK , DC_WHITE , DA_NONE);
theme->groups[SC_FILE_EXPLORER_TITLE] = TG_VAL(DC_CYAN , DC_NONE , DA_NONE);
theme->groups[SC_FILE_EXPLORER_FILE_ENTRY] = TG_VAL(DC_WHITE , DC_NONE , DA_NONE);
theme->groups[SC_FILE_EXPLORER_DIRECTORY_ENTRY] = TG_VAL(DC_BLUE , DC_NONE , DA_NONE);
theme->groups[SC_PRIMARY_SEARCH_MATCH] = TG_VAL(DC_BLACK , DC_WHITE , DA_NONE);
return theme;
}
int th_str_to_draw_color(DrawColor *draw_color_ptr, const char *draw_color_str)
{
assert(draw_color_str != NULL);
static const char *draw_colors[] = {
[DC_NONE] = "none",
[DC_BLACK] = "black",
[DC_RED] = "red",
[DC_GREEN] = "green",
[DC_YELLOW] = "yellow",
[DC_BLUE] = "blue",
[DC_MAGENTA] = "magenta",
[DC_CYAN] = "cyan",
[DC_WHITE] = "white"
};
static const size_t draw_color_num = ARRAY_SIZE(draw_colors, const char *);
for (size_t k = 0; k < draw_color_num; k++) {
if (strcmp(draw_colors[k], draw_color_str) == 0) {
*draw_color_ptr = k;
return 1;
}
}
return 0;
}
int th_str_to_screen_component(ScreenComponent *screen_comp_ptr,
const char *screen_comp_str)
{
assert(screen_comp_str != NULL);
static const char *screen_comps[] = {
[SC_LINENO] = "lineno",
[SC_BUFFER_TAB_BAR] = "buffertabbar",
[SC_ACTIVE_BUFFER_TAB_BAR] = "activebuffertabbar",
[SC_STATUS_BAR] = "statusbar",
[SC_ERROR_MESSAGE] = "errormessage",
[SC_BUFFER_END] = "bufferend",
[SC_COLORCOLUMN] = "colorcolumn",
[SC_SEARCH_MATCH] = "searchmatch",
[SC_PRIMARY_SEARCH_MATCH] = "primarysearchmatch",
[SC_FILE_EXPLORER_TITLE] = "fileexplorertitle",
[SC_FILE_EXPLORER_FILE_ENTRY] = "fileexplorerfileentry",
[SC_FILE_EXPLORER_DIRECTORY_ENTRY] = "fileexplorerdirectoryentry"
};
for (size_t k = ST_ENTRY_NUM; k < SC_ENTRY_NUM; k++) {
if (strcmp(screen_comps[k], screen_comp_str) == 0) {
*screen_comp_ptr = k;
return 1;
}
}
return 0;
}
int th_is_valid_group_name(const char *group_name)
{
assert(group_name != NULL);
SyntaxToken token;
ScreenComponent screen_comp;
return sy_str_to_token(&token, group_name) ||
th_str_to_screen_component(&screen_comp, group_name);
}
void th_set_screen_comp_colors(Theme *theme, uint screen_comp,
DrawColor fg_color, DrawColor bg_color)
{
assert(screen_comp < SC_ENTRY_NUM);
theme->groups[screen_comp] = TG_VAL(fg_color, bg_color, DA_NONE);
}
ThemeGroup th_get_theme_group(const Theme *theme, uint screen_comp)
{
assert(screen_comp < SC_ENTRY_NUM);
return theme->groups[screen_comp];
}