Commit Diff


commit - d5493194c967ba9fff329ee44c4c7ea3ed1f541a
commit + 69e1d1b6fb2f3fb532a3d70aeccc3fc32209afde
blob - 4d720585e680b3e6ce97f96636205948425f74db
blob + 0b5437fa1cdd76e9928e66eddfca372c998ef11f
--- defaults.c
+++ defaults.c
@@ -17,6 +17,7 @@
 #include "telescope.h"
 
 #include <curses.h>
+#include <string.h>
 
 struct lineprefix line_prefixes[] = {
 	[LINE_TEXT] =		{ "",		"" },
@@ -57,3 +58,45 @@ struct modeline_face modeline_face = {
 struct minibuffer_face minibuffer_face = {
 	.background = A_NORMAL,
 };
+
+int
+config_setprfx(const char *name, int cont, const char *str)
+{
+	size_t i;
+	struct lineprefix *p;
+	struct mapping {
+		const char	*label;
+		int		 id;
+	} mappings[] = {
+		{"text",	LINE_TEXT},
+		{"link",	LINE_LINK},
+		{"title1",	LINE_TITLE_1},
+		{"title2",	LINE_TITLE_2},
+		{"title3",	LINE_TITLE_3},
+		{"item",	LINE_ITEM},
+		{"quote",	LINE_QUOTE},
+		{"pre.start",	LINE_PRE_START},
+		{"pre",		LINE_PRE_CONTENT},
+		{"pre.end",	LINE_PRE_END},
+	};
+
+	if (!has_prefix(name, "line."))
+		return 0;
+	name += 5;
+
+	for (i = 0; i < sizeof(mappings)/sizeof(mappings[0]); ++i) {
+		if (!strcmp(name, mappings[i].label)) {
+			name += strlen(mappings[i].label);
+			p = &line_prefixes[mappings[i].id];
+
+			if (cont)
+				p->prfx2 = str;
+			else
+				p->prfx1 = str;
+
+			return 1;
+		}
+	}
+
+	return 0;
+}
blob - e03c44868486748ab561d70e313109cd0f80d495
blob + 9bdedf07ad5b7ca28260de004206f7502b804585
--- parse.y
+++ parse.y
@@ -39,6 +39,7 @@ typedef struct {
 } yystype;
 #define YYSTYPE yystype
 
+static char *current_style;
 static const char *path;
 
 FILE *yyfp;
@@ -65,14 +66,18 @@ grammar		: /* empty */
 		| error '\n'
 		;
 
-rule		: set | style | bind | unbind ;
+rule		: set
+		| style		{ free(current_style); current_style = NULL; }
+		| bind
+		| unbind
+		;
 
 set		: TSET TSTRING '=' TSTRING	{ printf("set %s = \"%s\"\n", $2, $4); }
 		| TSET TSTRING '=' TNUMBER	{ printf("set %s = %d\n", $2, $4); }
 		;
 
-style		: TSTYLE TSTRING { printf("(%s) ", $2); }	styleopt
-		| TSTYLE TSTRING { printf("[%s]\n", $2); }	'{' styleopts '}'
+style		: TSTYLE TSTRING { current_style = $2; } styleopt
+		| TSTYLE TSTRING { current_style = $2; } '{' styleopts '}'
 		;
 
 styleopts	: /* empty */
@@ -80,8 +85,8 @@ styleopts	: /* empty */
 		| styleopts styleopt '\n'
 		;
 
-styleopt	: TPRFX TSTRING			{ printf("style prefix setted to \"%s\"\n", $2); }
-		| TCONT TSTRING			{ printf("style cont setted to \"%s\"\n", $2); }
+styleopt	: TPRFX TSTRING			{ setprfx(0, $2); }
+		| TCONT TSTRING			{ setprfx(1, $2); }
 		| TBG TSTRING			{ printf("style background setted to \"%s\"\n", $2); }
 		| TFG TSTRING			{ printf("style foreground setted to \"%s\"\n", $2); }
 		| TATTR TBOLD			{ printf("style attr setted to bold\n"); }
@@ -262,6 +267,18 @@ eof:
 	return 0;
 }
 
+static void
+setprfx(int cont, const char *name)
+{
+	if (current_style == NULL) {
+		warnx("current_style = NULL!");
+		abort();
+	}
+
+	if (!config_setprfx(current_style, cont, name))
+		yyerror("invalid style %s", name);
+}
+
 void
 parseconfig(const char *filename, int fonf)
 {
blob - 6ad2d80640e8219d0bc964512d68a2d47ce5d811
blob + 78f360bb6264efefa0d40f0a66ee9ef7005c74d7
--- telescope.h
+++ telescope.h
@@ -230,6 +230,9 @@ struct keymap {
 	TAILQ_ENTRY(keymap)	 keymaps;
 };
 
+/* defaults.c */
+int		 config_setprfx(const char *, int, const char *);
+
 /* fs.c */
 int		 fs_init(void);
 int		 fs_main(struct imsgbuf*);