Blob


1 /*
2 * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 *
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.
7 *
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.
15 */
17 #include "telescope.h"
19 #include <curses.h>
20 #include <limits.h>
21 #include <stdlib.h>
22 #include <string.h>
24 char *new_tab_url = NULL;
25 int fill_column = INT_MAX;
26 int olivetti_mode = 0;
27 int enable_colors = 1;
29 struct lineprefix line_prefixes[] = {
30 [LINE_TEXT] = { "", "" },
31 [LINE_LINK] = { "=> ", " " },
32 [LINE_TITLE_1] = { "# ", " " },
33 [LINE_TITLE_2] = { "## ", " " },
34 [LINE_TITLE_3] = { "### ", " " },
35 [LINE_ITEM] = { "* ", " " },
36 [LINE_QUOTE] = { "> ", " " },
37 [LINE_PRE_START] = { "```", " " },
38 [LINE_PRE_CONTENT] = { "", "" },
39 [LINE_PRE_END] = { "```", "```" },
40 };
42 struct line_face line_faces[] = {
43 [LINE_TEXT] = { 0, 0 },
44 [LINE_LINK] = { 0, A_UNDERLINE },
45 [LINE_TITLE_1] = { A_BOLD, A_BOLD },
46 [LINE_TITLE_2] = { A_BOLD, A_BOLD },
47 [LINE_TITLE_3] = { A_BOLD, A_BOLD },
48 [LINE_ITEM] = { 0, 0 },
49 [LINE_QUOTE] = { 0, A_DIM },
50 [LINE_PRE_START] = { 0, 0 },
51 [LINE_PRE_CONTENT] = { 0, 0 },
52 [LINE_PRE_END] = { 0, 0 },
53 };
55 struct tab_face tab_face = {
56 .background = A_REVERSE,
57 .tab = A_REVERSE,
58 .current_tab = A_NORMAL,
59 };
61 struct modeline_face modeline_face = {
62 .background = A_REVERSE,
63 };
65 struct minibuffer_face minibuffer_face = {
66 .background = A_NORMAL,
67 };
69 int
70 config_setprfx(const char *name, int cont, const char *str)
71 {
72 size_t i;
73 struct lineprefix *p;
74 struct mapping {
75 const char *label;
76 int id;
77 } mappings[] = {
78 {"text", LINE_TEXT},
79 {"link", LINE_LINK},
80 {"title1", LINE_TITLE_1},
81 {"title2", LINE_TITLE_2},
82 {"title3", LINE_TITLE_3},
83 {"item", LINE_ITEM},
84 {"quote", LINE_QUOTE},
85 {"pre.start", LINE_PRE_START},
86 {"pre", LINE_PRE_CONTENT},
87 {"pre.end", LINE_PRE_END},
88 };
90 if (!has_prefix(name, "line."))
91 return 0;
92 name += 5;
94 for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
95 if (!strcmp(name, mappings[i].label)) {
96 name += strlen(mappings[i].label);
97 p = &line_prefixes[mappings[i].id];
99 if (cont)
100 p->prfx2 = str;
101 else
102 p->prfx1 = str;
104 return 1;
108 return 0;
111 int
112 config_setvari(const char *var, int val)
114 if (!strcmp(var, "fill-column")) {
115 if ((fill_column = val) <= 0)
116 fill_column = INT_MAX;
117 } else if (!strcmp(var, "olivetti-mode")) {
118 olivetti_mode = !!val;
119 } else if (!strcmp(var, "enable-colors")) {
120 enable_colors = !!val;
121 } else {
122 return 0;
125 return 1;
128 int
129 config_setvars(const char *var, char *val)
131 if (!strcmp(var, "new-tab-url")) {
132 if (new_tab_url != NULL)
133 free(new_tab_url);
134 new_tab_url = val;
135 } else
136 return 0;
137 return 1;