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 69e1d1b6 2021-06-15 op #include <string.h>
21 c92e529c 2021-06-15 op
22 c92e529c 2021-06-15 op struct lineprefix line_prefixes[] = {
23 c92e529c 2021-06-15 op [LINE_TEXT] = { "", "" },
24 c92e529c 2021-06-15 op [LINE_LINK] = { "=> ", " " },
25 c92e529c 2021-06-15 op [LINE_TITLE_1] = { "# ", " " },
26 c92e529c 2021-06-15 op [LINE_TITLE_2] = { "## ", " " },
27 c92e529c 2021-06-15 op [LINE_TITLE_3] = { "### ", " " },
28 c92e529c 2021-06-15 op [LINE_ITEM] = { "* ", " " },
29 c92e529c 2021-06-15 op [LINE_QUOTE] = { "> ", " " },
30 c92e529c 2021-06-15 op [LINE_PRE_START] = { "```", " " },
31 c92e529c 2021-06-15 op [LINE_PRE_CONTENT] = { "", "" },
32 c92e529c 2021-06-15 op [LINE_PRE_END] = { "```", "```" },
33 c92e529c 2021-06-15 op };
34 c92e529c 2021-06-15 op
35 c92e529c 2021-06-15 op struct line_face line_faces[] = {
36 c92e529c 2021-06-15 op [LINE_TEXT] = { 0, 0 },
37 c92e529c 2021-06-15 op [LINE_LINK] = { 0, A_UNDERLINE },
38 c92e529c 2021-06-15 op [LINE_TITLE_1] = { A_BOLD, A_BOLD },
39 c92e529c 2021-06-15 op [LINE_TITLE_2] = { A_BOLD, A_BOLD },
40 c92e529c 2021-06-15 op [LINE_TITLE_3] = { A_BOLD, A_BOLD },
41 c92e529c 2021-06-15 op [LINE_ITEM] = { 0, 0 },
42 c92e529c 2021-06-15 op [LINE_QUOTE] = { 0, A_DIM },
43 c92e529c 2021-06-15 op [LINE_PRE_START] = { 0, 0 },
44 c92e529c 2021-06-15 op [LINE_PRE_CONTENT] = { 0, 0 },
45 c92e529c 2021-06-15 op [LINE_PRE_END] = { 0, 0 },
46 c92e529c 2021-06-15 op };
47 c92e529c 2021-06-15 op
48 c92e529c 2021-06-15 op struct tab_face tab_face = {
49 c92e529c 2021-06-15 op .background = A_REVERSE,
50 c92e529c 2021-06-15 op .tab = A_REVERSE,
51 c92e529c 2021-06-15 op .current_tab = A_NORMAL,
52 c92e529c 2021-06-15 op };
53 d5493194 2021-06-15 op
54 d5493194 2021-06-15 op struct modeline_face modeline_face = {
55 d5493194 2021-06-15 op .background = A_REVERSE,
56 d5493194 2021-06-15 op };
57 d5493194 2021-06-15 op
58 d5493194 2021-06-15 op struct minibuffer_face minibuffer_face = {
59 d5493194 2021-06-15 op .background = A_NORMAL,
60 d5493194 2021-06-15 op };
61 69e1d1b6 2021-06-15 op
62 69e1d1b6 2021-06-15 op int
63 69e1d1b6 2021-06-15 op config_setprfx(const char *name, int cont, const char *str)
64 69e1d1b6 2021-06-15 op {
65 69e1d1b6 2021-06-15 op size_t i;
66 69e1d1b6 2021-06-15 op struct lineprefix *p;
67 69e1d1b6 2021-06-15 op struct mapping {
68 69e1d1b6 2021-06-15 op const char *label;
69 69e1d1b6 2021-06-15 op int id;
70 69e1d1b6 2021-06-15 op } mappings[] = {
71 69e1d1b6 2021-06-15 op {"text", LINE_TEXT},
72 69e1d1b6 2021-06-15 op {"link", LINE_LINK},
73 69e1d1b6 2021-06-15 op {"title1", LINE_TITLE_1},
74 69e1d1b6 2021-06-15 op {"title2", LINE_TITLE_2},
75 69e1d1b6 2021-06-15 op {"title3", LINE_TITLE_3},
76 69e1d1b6 2021-06-15 op {"item", LINE_ITEM},
77 69e1d1b6 2021-06-15 op {"quote", LINE_QUOTE},
78 69e1d1b6 2021-06-15 op {"pre.start", LINE_PRE_START},
79 69e1d1b6 2021-06-15 op {"pre", LINE_PRE_CONTENT},
80 69e1d1b6 2021-06-15 op {"pre.end", LINE_PRE_END},
81 69e1d1b6 2021-06-15 op };
82 69e1d1b6 2021-06-15 op
83 69e1d1b6 2021-06-15 op if (!has_prefix(name, "line."))
84 69e1d1b6 2021-06-15 op return 0;
85 69e1d1b6 2021-06-15 op name += 5;
86 69e1d1b6 2021-06-15 op
87 69e1d1b6 2021-06-15 op for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
88 69e1d1b6 2021-06-15 op if (!strcmp(name, mappings[i].label)) {
89 69e1d1b6 2021-06-15 op name += strlen(mappings[i].label);
90 69e1d1b6 2021-06-15 op p = &line_prefixes[mappings[i].id];
91 69e1d1b6 2021-06-15 op
92 69e1d1b6 2021-06-15 op if (cont)
93 69e1d1b6 2021-06-15 op p->prfx2 = str;
94 69e1d1b6 2021-06-15 op else
95 69e1d1b6 2021-06-15 op p->prfx1 = str;
96 69e1d1b6 2021-06-15 op
97 69e1d1b6 2021-06-15 op return 1;
98 69e1d1b6 2021-06-15 op }
99 69e1d1b6 2021-06-15 op }
100 69e1d1b6 2021-06-15 op
101 69e1d1b6 2021-06-15 op return 0;
102 69e1d1b6 2021-06-15 op }