commit - 33fc3a8ff681ef26cc5e94e35ff82260586c3af2
commit + d0149485ec5e6901bde423a3c69bd01359901e00
blob - e4044fa58cf2430cf1a51388cd44aad1b9459c0f
blob + 42f48f272ee60d069863adf47105bb414c951585
--- ChangeLog
+++ ChangeLog
+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
blob - 7dce0214ebc10391f7ee3ea7e4bdb9c9399433f9
blob + 66f9250a76777dd8e067b8723cfe5365d506b210
--- defaults.c
+++ defaults.c
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},
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)
{
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);
blob - 4b5457b1155e472fc8c488d049d49832c52afa35
blob + 8f755a300b948aa4e33ef0cdf037bde6696a22a6
--- parse.y
+++ parse.y
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
| 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); }
| 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); }
;
{ "bg", TBG },
{ "fg", TFG },
{ "attr", TATTR },
- { "bold", TBOLD },
- { "underline", TUNDERLINE },
{ "bind", TBIND },
{ "unbind", TUNBIND },
};
t = colorname(trail);
if (!config_setcolor(color_type == TBG, current_style, p, l, t))
+ 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);
}
blob - 7547d79cf0cf2b4515725750464674a637120307
blob + 5a4e64ec3846d5b3e012470a862e6d4e9d44814d
--- telescope.h
+++ telescope.h
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 */