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