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