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;
27 struct lineprefix line_prefixes[] = {
28 [LINE_TEXT] = { "", "" },
29 [LINE_LINK] = { "=> ", " " },
30 [LINE_TITLE_1] = { "# ", " " },
31 [LINE_TITLE_2] = { "## ", " " },
32 [LINE_TITLE_3] = { "### ", " " },
33 [LINE_ITEM] = { "* ", " " },
34 [LINE_QUOTE] = { "> ", " " },
35 [LINE_PRE_START] = { "```", " " },
36 [LINE_PRE_CONTENT] = { "", "" },
37 [LINE_PRE_END] = { "```", "```" },
38 };
40 struct line_face line_faces[] = {
41 [LINE_TEXT] = { 0, 0 },
42 [LINE_LINK] = { 0, A_UNDERLINE },
43 [LINE_TITLE_1] = { A_BOLD, A_BOLD },
44 [LINE_TITLE_2] = { A_BOLD, A_BOLD },
45 [LINE_TITLE_3] = { A_BOLD, A_BOLD },
46 [LINE_ITEM] = { 0, 0 },
47 [LINE_QUOTE] = { 0, A_DIM },
48 [LINE_PRE_START] = { 0, 0 },
49 [LINE_PRE_CONTENT] = { 0, 0 },
50 [LINE_PRE_END] = { 0, 0 },
51 };
53 struct tab_face tab_face = {
54 .background = A_REVERSE,
55 .tab = A_REVERSE,
56 .current_tab = A_NORMAL,
57 };
59 struct modeline_face modeline_face = {
60 .background = A_REVERSE,
61 };
63 struct minibuffer_face minibuffer_face = {
64 .background = A_NORMAL,
65 };
67 int
68 config_setprfx(const char *name, int cont, const char *str)
69 {
70 size_t i;
71 struct lineprefix *p;
72 struct mapping {
73 const char *label;
74 int id;
75 } mappings[] = {
76 {"text", LINE_TEXT},
77 {"link", LINE_LINK},
78 {"title1", LINE_TITLE_1},
79 {"title2", LINE_TITLE_2},
80 {"title3", LINE_TITLE_3},
81 {"item", LINE_ITEM},
82 {"quote", LINE_QUOTE},
83 {"pre.start", LINE_PRE_START},
84 {"pre", LINE_PRE_CONTENT},
85 {"pre.end", LINE_PRE_END},
86 };
88 if (!has_prefix(name, "line."))
89 return 0;
90 name += 5;
92 for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
93 if (!strcmp(name, mappings[i].label)) {
94 name += strlen(mappings[i].label);
95 p = &line_prefixes[mappings[i].id];
97 if (cont)
98 p->prfx2 = str;
99 else
100 p->prfx1 = str;
102 return 1;
106 return 0;
109 int
110 config_setvari(const char *var, int val)
112 if (!strcmp(var, "fill-column")) {
113 if (val > 0)
114 fill_column = val;
115 } else
116 return 0;
117 return 1;
120 int
121 config_setvars(const char *var, char *val)
123 if (!strcmp(var, "new-tab-url")) {
124 if (new_tab_url != NULL)
125 free(new_tab_url);
126 new_tab_url = val;
127 } else
128 return 0;
129 return 1;