Blame


1 c92e529c 2021-06-15 op /*
2 c92e529c 2021-06-15 op * Copyright (c) 2021 Omar Polo <op@omarpolo.com>
3 c92e529c 2021-06-15 op *
4 c92e529c 2021-06-15 op * Permission to use, copy, modify, and distribute this software for any
5 c92e529c 2021-06-15 op * purpose with or without fee is hereby granted, provided that the above
6 c92e529c 2021-06-15 op * copyright notice and this permission notice appear in all copies.
7 c92e529c 2021-06-15 op *
8 c92e529c 2021-06-15 op * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 c92e529c 2021-06-15 op * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 c92e529c 2021-06-15 op * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 c92e529c 2021-06-15 op * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 c92e529c 2021-06-15 op * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 c92e529c 2021-06-15 op * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 c92e529c 2021-06-15 op * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 c92e529c 2021-06-15 op */
16 c92e529c 2021-06-15 op
17 c92e529c 2021-06-15 op #include "telescope.h"
18 c92e529c 2021-06-15 op
19 c92e529c 2021-06-15 op #include <curses.h>
20 1a99965e 2021-06-19 op #include <limits.h>
21 db7cc27a 2021-06-19 op #include <stdlib.h>
22 69e1d1b6 2021-06-15 op #include <string.h>
23 c92e529c 2021-06-15 op
24 db7cc27a 2021-06-19 op char *new_tab_url = NULL;
25 1a99965e 2021-06-19 op int fill_column = INT_MAX;
26 72b18268 2021-06-19 op int olivetti_mode = 0;
27 2c748a1f 2021-06-21 op int enable_colors = 1;
28 1a99965e 2021-06-19 op
29 c92e529c 2021-06-15 op struct lineprefix line_prefixes[] = {
30 c92e529c 2021-06-15 op [LINE_TEXT] = { "", "" },
31 c92e529c 2021-06-15 op [LINE_LINK] = { "=> ", " " },
32 c92e529c 2021-06-15 op [LINE_TITLE_1] = { "# ", " " },
33 c92e529c 2021-06-15 op [LINE_TITLE_2] = { "## ", " " },
34 c92e529c 2021-06-15 op [LINE_TITLE_3] = { "### ", " " },
35 c92e529c 2021-06-15 op [LINE_ITEM] = { "* ", " " },
36 c92e529c 2021-06-15 op [LINE_QUOTE] = { "> ", " " },
37 c92e529c 2021-06-15 op [LINE_PRE_START] = { "```", " " },
38 c92e529c 2021-06-15 op [LINE_PRE_CONTENT] = { "", "" },
39 c92e529c 2021-06-15 op [LINE_PRE_END] = { "```", "```" },
40 c92e529c 2021-06-15 op };
41 c92e529c 2021-06-15 op
42 c92e529c 2021-06-15 op struct line_face line_faces[] = {
43 c92e529c 2021-06-15 op [LINE_TEXT] = { 0, 0 },
44 c92e529c 2021-06-15 op [LINE_LINK] = { 0, A_UNDERLINE },
45 c92e529c 2021-06-15 op [LINE_TITLE_1] = { A_BOLD, A_BOLD },
46 c92e529c 2021-06-15 op [LINE_TITLE_2] = { A_BOLD, A_BOLD },
47 c92e529c 2021-06-15 op [LINE_TITLE_3] = { A_BOLD, A_BOLD },
48 c92e529c 2021-06-15 op [LINE_ITEM] = { 0, 0 },
49 c92e529c 2021-06-15 op [LINE_QUOTE] = { 0, A_DIM },
50 c92e529c 2021-06-15 op [LINE_PRE_START] = { 0, 0 },
51 c92e529c 2021-06-15 op [LINE_PRE_CONTENT] = { 0, 0 },
52 c92e529c 2021-06-15 op [LINE_PRE_END] = { 0, 0 },
53 c92e529c 2021-06-15 op };
54 c92e529c 2021-06-15 op
55 c92e529c 2021-06-15 op struct tab_face tab_face = {
56 c92e529c 2021-06-15 op .background = A_REVERSE,
57 c92e529c 2021-06-15 op .tab = A_REVERSE,
58 c92e529c 2021-06-15 op .current_tab = A_NORMAL,
59 c92e529c 2021-06-15 op };
60 d5493194 2021-06-15 op
61 d5493194 2021-06-15 op struct modeline_face modeline_face = {
62 d5493194 2021-06-15 op .background = A_REVERSE,
63 d5493194 2021-06-15 op };
64 d5493194 2021-06-15 op
65 d5493194 2021-06-15 op struct minibuffer_face minibuffer_face = {
66 d5493194 2021-06-15 op .background = A_NORMAL,
67 d5493194 2021-06-15 op };
68 69e1d1b6 2021-06-15 op
69 69e1d1b6 2021-06-15 op int
70 69e1d1b6 2021-06-15 op config_setprfx(const char *name, int cont, const char *str)
71 69e1d1b6 2021-06-15 op {
72 69e1d1b6 2021-06-15 op size_t i;
73 69e1d1b6 2021-06-15 op struct lineprefix *p;
74 69e1d1b6 2021-06-15 op struct mapping {
75 69e1d1b6 2021-06-15 op const char *label;
76 69e1d1b6 2021-06-15 op int id;
77 69e1d1b6 2021-06-15 op } mappings[] = {
78 69e1d1b6 2021-06-15 op {"text", LINE_TEXT},
79 69e1d1b6 2021-06-15 op {"link", LINE_LINK},
80 69e1d1b6 2021-06-15 op {"title1", LINE_TITLE_1},
81 69e1d1b6 2021-06-15 op {"title2", LINE_TITLE_2},
82 69e1d1b6 2021-06-15 op {"title3", LINE_TITLE_3},
83 69e1d1b6 2021-06-15 op {"item", LINE_ITEM},
84 69e1d1b6 2021-06-15 op {"quote", LINE_QUOTE},
85 69e1d1b6 2021-06-15 op {"pre.start", LINE_PRE_START},
86 69e1d1b6 2021-06-15 op {"pre", LINE_PRE_CONTENT},
87 69e1d1b6 2021-06-15 op {"pre.end", LINE_PRE_END},
88 69e1d1b6 2021-06-15 op };
89 69e1d1b6 2021-06-15 op
90 69e1d1b6 2021-06-15 op if (!has_prefix(name, "line."))
91 69e1d1b6 2021-06-15 op return 0;
92 69e1d1b6 2021-06-15 op name += 5;
93 69e1d1b6 2021-06-15 op
94 69e1d1b6 2021-06-15 op for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
95 69e1d1b6 2021-06-15 op if (!strcmp(name, mappings[i].label)) {
96 69e1d1b6 2021-06-15 op name += strlen(mappings[i].label);
97 69e1d1b6 2021-06-15 op p = &line_prefixes[mappings[i].id];
98 69e1d1b6 2021-06-15 op
99 69e1d1b6 2021-06-15 op if (cont)
100 69e1d1b6 2021-06-15 op p->prfx2 = str;
101 69e1d1b6 2021-06-15 op else
102 69e1d1b6 2021-06-15 op p->prfx1 = str;
103 69e1d1b6 2021-06-15 op
104 69e1d1b6 2021-06-15 op return 1;
105 69e1d1b6 2021-06-15 op }
106 69e1d1b6 2021-06-15 op }
107 69e1d1b6 2021-06-15 op
108 69e1d1b6 2021-06-15 op return 0;
109 69e1d1b6 2021-06-15 op }
110 86e7d7b4 2021-06-19 op
111 86e7d7b4 2021-06-19 op int
112 86e7d7b4 2021-06-19 op config_setvari(const char *var, int val)
113 86e7d7b4 2021-06-19 op {
114 1a99965e 2021-06-19 op if (!strcmp(var, "fill-column")) {
115 cc073cd2 2021-06-19 op if ((fill_column = val) <= 0)
116 2106687b 2021-06-19 op fill_column = INT_MAX;
117 72b18268 2021-06-19 op } else if (!strcmp(var, "olivetti-mode")) {
118 72b18268 2021-06-19 op olivetti_mode = !!val;
119 2c748a1f 2021-06-21 op } else if (!strcmp(var, "enable-colors")) {
120 2c748a1f 2021-06-21 op enable_colors = !!val;
121 2c748a1f 2021-06-21 op } else {
122 1a99965e 2021-06-19 op return 0;
123 2c748a1f 2021-06-21 op }
124 2c748a1f 2021-06-21 op
125 1a99965e 2021-06-19 op return 1;
126 86e7d7b4 2021-06-19 op }
127 86e7d7b4 2021-06-19 op
128 86e7d7b4 2021-06-19 op int
129 86e7d7b4 2021-06-19 op config_setvars(const char *var, char *val)
130 86e7d7b4 2021-06-19 op {
131 db7cc27a 2021-06-19 op if (!strcmp(var, "new-tab-url")) {
132 db7cc27a 2021-06-19 op if (new_tab_url != NULL)
133 db7cc27a 2021-06-19 op free(new_tab_url);
134 db7cc27a 2021-06-19 op new_tab_url = val;
135 db7cc27a 2021-06-19 op } else
136 db7cc27a 2021-06-19 op return 0;
137 db7cc27a 2021-06-19 op return 1;
138 86e7d7b4 2021-06-19 op }