aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmar Polo <op@omarpolo.com>2021-06-22 10:12:06 +0200
committerOmar Polo <op@omarpolo.com>2021-06-22 10:12:06 +0200
commitd0149485ec5e6901bde423a3c69bd01359901e00 (patch)
tree29194c417bf8e788484ad1bde16c4ddc528238f5
parent33fc3a8ff681ef26cc5e94e35ff82260586c3af2 (diff)
downloadtelescope-d0149485ec5e6901bde423a3c69bd01359901e00.tar.gz
telescope-d0149485ec5e6901bde423a3c69bd01359901e00.tar.bz2
allow changing the attributes
`attr' now follows the same rule as `fg' and `bg', with the three airity variant. Attributes by themselves are a comma-separated list of keywords, each one representing a ncurses attribute.
-rw-r--r--ChangeLog4
-rw-r--r--defaults.c31
-rw-r--r--parse.y70
-rw-r--r--telescope.h1
4 files changed, 98 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index e4044fa..42f48f2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2021-06-22 Omar Polo <op@omarpolo.com>
+
+ * parse.y (attrname): allow changing the attributes
+
2021-06-21 Omar Polo <op@omarpolo.com>
* telescope.h (enum pairs): allow changing the background color of the body window
diff --git a/defaults.c b/defaults.c
index 7dce021..66f9250 100644
--- a/defaults.c
+++ b/defaults.c
@@ -30,6 +30,7 @@ static struct lineface_descr {
int pp, p, tp;
int prfx_bg, bg, trail_bg;
int prfx_fg, fg, trail_fg;
+ int prfx_attr, attr, trail_attr;
} linefaces_descr[] = {
[LINE_TEXT] = {.pp=PT_PRFX, .p=PT, .tp=PT_TRAIL},
[LINE_LINK] = {.pp=PL_PRFX, .p=PL, .tp=PL_TRAIL},
@@ -222,6 +223,30 @@ config_setcolor(int bg, const char *name, int prfx, int line, int trail)
return 1;
}
+int
+config_setattr(const char *name, int prfx, int line, int trail)
+{
+ struct mapping *m;
+ struct lineface_descr *d;
+
+ if (has_prefix(name, "line.")) {
+ name += 5;
+
+ if ((m = mapping_by_name(name)) == NULL)
+ return 0;
+
+ d = &linefaces_descr[m->linetype];
+
+ d->prfx_attr = prfx;
+ d->attr = line;
+ d->trail_attr = trail;
+ } else {
+ return 0;
+ }
+
+ return 1;
+}
+
void
config_apply_colors(void)
{
@@ -235,13 +260,13 @@ config_apply_colors(void)
f = &line_faces[i];
init_pair(d->pp, d->prfx_fg, d->prfx_bg);
- f->prefix_prop = COLOR_PAIR(d->pp);
+ f->prefix_prop = COLOR_PAIR(d->pp) | d->prfx_attr;
init_pair(d->p, d->fg, d->bg);
- f->text_prop = COLOR_PAIR(d->p);
+ f->text_prop = COLOR_PAIR(d->p) | d->attr;
init_pair(d->tp, d->trail_fg, d->trail_bg);
- f->trail_prop = COLOR_PAIR(d->tp);
+ f->trail_prop = COLOR_PAIR(d->tp) | d->trail_attr;
}
init_pair(PBODY, body_face.fg, body_face.bg);
diff --git a/parse.y b/parse.y
index 4b5457b..8f755a3 100644
--- a/parse.y
+++ b/parse.y
@@ -57,11 +57,13 @@ static void setvari(char *, int);
static void setvars(char *, char *);
static int colorname(const char *);
static void setcolor(const char *, const char *, const char *);
+static int attrname(char *);
+static void setattr(char *, char *, char *);
%}
%token TSET
-%token TSTYLE TPRFX TCONT TBG TFG TATTR TBOLD TUNDERLINE
+%token TSTYLE TPRFX TCONT TBG TFG TATTR
%token TBIND TUNBIND
%token <str> TSTRING
@@ -100,8 +102,7 @@ styleopt : TPRFX TSTRING { setprfx($2, $2); }
| TPRFX TSTRING TSTRING { setprfx($2, $2); }
| TBG { color_type = TBG; } colorspec
| TFG { color_type = TFG; } colorspec
- | TATTR TBOLD { printf("style attr setted to bold\n"); }
- | TATTR TUNDERLINE { printf("style attr setted to underline\n"); }
+ | TATTR attr
;
colorspec : TSTRING { setcolor($1, $1, $1); free($1); }
@@ -109,6 +110,11 @@ colorspec : TSTRING { setcolor($1, $1, $1); free($1); }
| TSTRING TSTRING TSTRING { setcolor($1, $2, $3); free($1); free($2); free($3); }
;
+attr : TSTRING { setattr($1, $1, $1); free($1); }
+ | TSTRING TSTRING { setattr($1, $2, $1); free($1); free($2); }
+ | TSTRING TSTRING TSTRING { setattr($1, $2, $3); free($1); free($2); free($3); }
+ ;
+
bind : TBIND TSTRING TSTRING TSTRING { printf("TODO: bind %s %s %s\n", $2, $3, $4); }
;
@@ -141,8 +147,6 @@ static struct keyword {
{ "bg", TBG },
{ "fg", TFG },
{ "attr", TATTR },
- { "bold", TBOLD },
- { "underline", TUNDERLINE },
{ "bind", TBIND },
{ "unbind", TUNBIND },
};
@@ -355,6 +359,62 @@ setcolor(const char *prfx, const char *line, const char *trail)
yyerror("invalid style %s", current_style);
}
+static int
+attrname(char *n)
+{
+ struct {
+ const char *name;
+ unsigned int val;
+ } *i, attrs[] = {
+ { "normal", A_NORMAL },
+ { "standout", A_STANDOUT },
+ { "underline", A_UNDERLINE },
+ { "reverse", A_REVERSE },
+ { "blink", A_BLINK },
+ { "dim", A_DIM },
+ { "bold", A_BOLD },
+ { NULL, 0 },
+ };
+ int ret, found;
+ char *ap;
+
+ ret = 0;
+ while ((ap = strsep(&n, ",")) != NULL) {
+ if (*ap == '\0')
+ continue;
+
+ found = 0;
+ for (i = attrs; i ->name != NULL; ++i) {
+ if (strcmp(i->name, ap))
+ continue;
+ ret |= i->val;
+ found = 1;
+ break;
+ }
+
+ if (!found)
+ yyerror("unknown attribute \"%s\" at col %d",
+ ap, yylval.colno+1);
+ }
+
+ return ret;
+}
+
+static void
+setattr(char *prfx, char *line, char *trail)
+{
+ int p, l, t;
+
+ assert(current_style != NULL);
+
+ p = attrname(prfx);
+ l = attrname(line);
+ t = attrname(trail);
+
+ if (!config_setattr(current_style, p, l, t))
+ yyerror("invalid style %s", current_style);
+}
+
void
parseconfig(const char *filename, int fonf)
{
diff --git a/telescope.h b/telescope.h
index 7547d79..5a4e64e 100644
--- a/telescope.h
+++ b/telescope.h
@@ -260,6 +260,7 @@ int config_setprfx(const char *, const char *, const char *);
int config_setvari(const char *, int);
int config_setvars(const char *, char *);
int config_setcolor(int, const char *, int, int, int);
+int config_setattr(const char *, int, int, int);
void config_apply_colors(void);
/* fs.c */