commit 7c93295aab6ab26e0c2305fbd221dcc8a6dcdfe3
parent 2b4429778db5162857ae335ac0b7e36b765e3492
Author: William Casarin <jb55@jb55.com>
Date: Mon, 9 Jul 2018 16:19:34 -0700
add prefix to scemes
Diffstat:
3 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/cfg.def.h b/cfg.def.h
@@ -18,7 +18,7 @@ static const char *separator = " → ";
/* -fn option overrides fonts[0]; default X11 font or font set */
static const char *fonts[] = {
- "Monospace:size=14"
+ "monospace:size=14"
};
/* static const char *prompt = NULL; /\* -p option; prompt to the left of input field *\/ */
@@ -28,12 +28,14 @@ static struct scheme schemes[SchemeLast] = {
[SchemeNorm] = { .bg = scheme_bg,
.bind = "#D19A66",
.arrow = "#888",
+ .prefix = "",
.name = "#bbbbbb"
},
[SchemePrefix] = { .bg = scheme_bg,
.bind = "#eeeeee",
.arrow = "#888",
+ .prefix = "",
.name = "#c678dd"
},
};
diff --git a/cmdtree.c b/cmdtree.c
@@ -145,6 +145,9 @@ draw_command(Drw *drw, int x, int y, struct command *cmd) {
int invert = 0;
int isprefix = 0;
char *name = cmd->name;
+ struct scheme *prefix = &schemes[SchemePrefix];
+ struct scheme *norm = &schemes[SchemeNorm];
+ struct scheme *scheme = NULL;
//drw_fontset_getwidth(drw, binding) + 1;
@@ -162,18 +165,18 @@ draw_command(Drw *drw, int x, int y, struct command *cmd) {
isprefix = command_is_prefix(cmd);
if (isprefix)
- drw_setscheme(drw, &schemes[SchemePrefix].name_clr,
- &schemes[SchemePrefix].bg_clr);
+ scheme = prefix;
else
- drw_setscheme(drw, &schemes[SchemeNorm].name_clr,
- &schemes[SchemeNorm].bg_clr);
+ scheme = norm;
- if (isprefix) {
- snprintf(buf, 256, "+%s", cmd->name);
+ drw_setscheme(drw, &scheme->name_clr, &scheme->bg_clr);
+
+ if (scheme->prefix && strlen(scheme->prefix) != 0) {
+ snprintf(buf, 256, "%s%s", scheme->prefix, cmd->name);
name = buf;
}
- w = drw_fontset_getwidth(drw, buf);
+ w = drw_fontset_getwidth(drw, name);
x = drw_text(drw, x+pad, y, w, bh, lpad, name, invert);
return x;
@@ -201,7 +204,11 @@ draw_tree_vertical(Drw *drw, struct command *cmds, int x, int y, int w, int h) {
for (i = 0; i < ncmds; ++i, ++c, y += bh) {
struct command *cmd = &cmds[i];
-
+ if (y >= mh) {
+ x = colw;
+ y = 0;
+ colw = 0;
+ }
colw = MAX(draw_command(drw, x, y, cmd) + 20, colw);
}
}
diff --git a/drw.h b/drw.h
@@ -28,6 +28,7 @@ struct scheme {
const char *bind;
const char *arrow;
const char *name;
+ const char *prefix;
Clr bg_clr;
Clr name_clr;
Clr bind_clr;