2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include "telescope.h"
24 char *new_tab_url = NULL;
25 int fill_column = INT_MAX;
26 int olivetti_mode = 0;
27 int enable_colors = 1;
29 static struct lineface_descr {
31 int prfx_bg, bg, trail_bg;
32 int prfx_fg, fg, trail_fg;
33 } linefaces_descr[] = {
34 [LINE_TEXT] = {.pp=PT_PRFX, .p=PT, .tp=PT_TRAIL},
35 [LINE_LINK] = {.pp=PL_PRFX, .p=PL, .tp=PL_TRAIL},
36 [LINE_TITLE_1] = {.pp=PT1_PRFX, .p=PT1, .tp=PT1_TRAIL},
37 [LINE_TITLE_2] = {.pp=PT2_PRFX, .p=PT1, .tp=PT1_TRAIL},
38 [LINE_TITLE_3] = {.pp=PT3_PRFX, .p=PT3, .tp=PT3_TRAIL},
39 [LINE_ITEM] = {.pp=PI_PRFX, .p=PI, .tp=PI_TRAIL},
40 [LINE_QUOTE] = {.pp=PQ_PRFX, .p=PQ, .tp=PQ_TRAIL},
41 [LINE_PRE_START] = {.pp=PPSTART_PRFX, .p=PT, .tp=PT_TRAIL},
42 [LINE_PRE_CONTENT] = {.pp=PP_PRFX, .p=PP, .tp=PP_TRAIL},
43 [LINE_PRE_END] = {.pp=PPEND_PRFX, .p=PPEND, .tp=PPEND_TRAIL},
46 struct lineprefix line_prefixes[] = {
47 [LINE_TEXT] = { "", "" },
48 [LINE_LINK] = { "=> ", " " },
49 [LINE_TITLE_1] = { "# ", " " },
50 [LINE_TITLE_2] = { "## ", " " },
51 [LINE_TITLE_3] = { "### ", " " },
52 [LINE_ITEM] = { "* ", " " },
53 [LINE_QUOTE] = { "> ", " " },
54 [LINE_PRE_START] = { "```", " " },
55 [LINE_PRE_CONTENT] = { "", "" },
56 [LINE_PRE_END] = { "```", "```" },
59 struct line_face line_faces[] = {
60 [LINE_TEXT] = { 0, 0, 0 },
61 [LINE_LINK] = { 0, A_UNDERLINE, 0 },
62 [LINE_TITLE_1] = { A_BOLD, A_BOLD, 0 },
63 [LINE_TITLE_2] = { A_BOLD, A_BOLD, 0 },
64 [LINE_TITLE_3] = { A_BOLD, A_BOLD, 0 },
65 [LINE_ITEM] = { 0, 0, 0 },
66 [LINE_QUOTE] = { 0, A_DIM, 0 },
67 [LINE_PRE_START] = { 0, 0, 0 },
68 [LINE_PRE_CONTENT] = { 0, 0, 0 },
69 [LINE_PRE_END] = { 0, 0, 0 },
72 struct tab_face tab_face = {
73 .background = A_REVERSE,
75 .current_tab = A_NORMAL,
78 struct body_face body_face = {
84 struct modeline_face modeline_face = {
85 .background = A_REVERSE,
88 struct minibuffer_face minibuffer_face = {
89 .background = A_NORMAL,
98 {"title1", LINE_TITLE_1},
99 {"title2", LINE_TITLE_2},
100 {"title3", LINE_TITLE_3},
102 {"quote", LINE_QUOTE},
103 {"pre.start", LINE_PRE_START},
104 {"pre", LINE_PRE_CONTENT},
105 {"pre.end", LINE_PRE_END},
108 static struct mapping *
109 mapping_by_name(const char *name)
113 for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
114 if (!strcmp(name, mappings[i].label))
124 struct lineface_descr *d;
127 len = sizeof(linefaces_descr)/sizeof(linefaces_descr[0]);
128 for (i = 0; i < len; ++i) {
129 d = &linefaces_descr[i];
131 d->prfx_bg = d->bg = d->trail_bg = -1;
132 d->prfx_fg = d->fg = d->trail_fg = -1;
137 config_setprfx(const char *name, const char *prfx, const char *cont)
139 struct lineprefix *p;
142 if (!has_prefix(name, "line."))
146 if ((m = mapping_by_name(name)) == NULL)
149 p = &line_prefixes[m->linetype];
157 config_setvari(const char *var, int val)
159 if (!strcmp(var, "fill-column")) {
160 if ((fill_column = val) <= 0)
161 fill_column = INT_MAX;
162 } else if (!strcmp(var, "olivetti-mode")) {
163 olivetti_mode = !!val;
164 } else if (!strcmp(var, "enable-colors")) {
165 enable_colors = !!val;
174 config_setvars(const char *var, char *val)
176 if (!strcmp(var, "new-tab-url")) {
177 if (new_tab_url != NULL)
186 config_setcolor(int bg, const char *name, int prfx, int line, int trail)
189 struct lineface_descr *d;
191 if (has_prefix(name, "line.")) {
194 if ((m = mapping_by_name(name)) == NULL)
197 d = &linefaces_descr[m->linetype];
208 } else if (!strcmp(name, "line")) {
210 body_face.lbg = prfx;
212 body_face.rbg = trail;
216 body_face.fg = trail;
226 config_apply_colors(void)
229 struct lineface_descr *d;
232 len = sizeof(linefaces_descr)/sizeof(linefaces_descr[0]);
233 for (i = 0; i < len; ++i) {
234 d = &linefaces_descr[i];
237 init_pair(d->pp, d->prfx_fg, d->prfx_bg);
238 f->prefix_prop = COLOR_PAIR(d->pp);
240 init_pair(d->p, d->fg, d->bg);
241 f->text_prop = COLOR_PAIR(d->p);
243 init_pair(d->tp, d->trail_fg, d->trail_bg);
244 f->trail_prop = COLOR_PAIR(d->tp);
247 init_pair(PBODY, body_face.fg, body_face.bg);
248 body_face.body = COLOR_PAIR(PBODY);
250 init_pair(PBLEFT, body_face.lfg, body_face.lbg);
251 body_face.left = COLOR_PAIR(PBLEFT);
253 init_pair(PBRIGHT, body_face.rfg, body_face.rbg);
254 body_face.right = COLOR_PAIR(PBRIGHT);