commit 2b4429778db5162857ae335ac0b7e36b765e3492
parent 0206052b5660cb77cdd0a0ac3c83dd4c3d996007
Author: William Casarin <jb55@jb55.com>
Date: Mon, 9 Jul 2018 16:08:12 -0700
prefix names
Diffstat:
M | cfg.def.h | | | 13 | ++++++++----- |
M | cmdtree.c | | | 110 | +++++++++++++++++++++++++++++++++++++++---------------------------------------- |
2 files changed, 62 insertions(+), 61 deletions(-)
diff --git a/cfg.def.h b/cfg.def.h
@@ -21,17 +21,20 @@ static const char *fonts[] = {
"Monospace:size=14"
};
/* static const char *prompt = NULL; /\* -p option; prompt to the left of input field *\/ */
+
+#define scheme_bg "#222222"
+
static struct scheme schemes[SchemeLast] = {
- [SchemeNorm] = { .bg = "#222222",
+ [SchemeNorm] = { .bg = scheme_bg,
.bind = "#D19A66",
.arrow = "#888",
.name = "#bbbbbb"
},
- [SchemePrefix] = { .bg = "#005577",
- .bind = "#eeeeee",
- .arrow = "#666666",
- .name = "#eeeeee"
+ [SchemePrefix] = { .bg = scheme_bg,
+ .bind = "#eeeeee",
+ .arrow = "#888",
+ .name = "#c678dd"
},
};
diff --git a/cmdtree.c b/cmdtree.c
@@ -137,29 +137,43 @@ setup(Drw *drw)
}
static int
-draw_command(Drw *drw, int x, int y, const char *name, const char *binding) {
+draw_command(Drw *drw, int x, int y, struct command *cmd) {
+ char buf[256];
int lpad = 0;
int pad = 0;
unsigned int w = 50;
int invert = 0;
+ int isprefix = 0;
+ char *name = cmd->name;
//drw_fontset_getwidth(drw, binding) + 1;
drw_setscheme(drw, &schemes[SchemeNorm].bind_clr,
&schemes[SchemeNorm].bg_clr);
- w = drw_fontset_getwidth(drw, binding);
- x = drw_text(drw, x+pad, y, w, bh, lpad, binding, invert);
+ w = drw_fontset_getwidth(drw, cmd->bind);
+ x = drw_text(drw, x+pad, y, w, bh, lpad, cmd->bind, invert);
w = sep_width;
drw_setscheme(drw, &schemes[SchemeNorm].arrow_clr,
&schemes[SchemeNorm].bg_clr);
x = drw_text(drw, x+pad, y, w, bh, lpad, separator, invert);
- drw_setscheme(drw, &schemes[SchemeNorm].name_clr,
- &schemes[SchemeNorm].bg_clr);
+ isprefix = command_is_prefix(cmd);
+
+ if (isprefix)
+ drw_setscheme(drw, &schemes[SchemePrefix].name_clr,
+ &schemes[SchemePrefix].bg_clr);
+ else
+ drw_setscheme(drw, &schemes[SchemeNorm].name_clr,
+ &schemes[SchemeNorm].bg_clr);
- w = drw_fontset_getwidth(drw, name);
+ if (isprefix) {
+ snprintf(buf, 256, "+%s", cmd->name);
+ name = buf;
+ }
+
+ w = drw_fontset_getwidth(drw, buf);
x = drw_text(drw, x+pad, y, w, bh, lpad, name, invert);
return x;
@@ -170,11 +184,10 @@ draw_command(Drw *drw, int x, int y, const char *name, const char *binding) {
/* calc_tree_exts(struct node *nodes, int num_nodes, int *rows, int *cols) { */
/* } */
static void
-draw_tree_vertical(Drw *drw, int x, int y, int w, int h) {
+draw_tree_vertical(Drw *drw, struct command *cmds, int x, int y, int w, int h) {
int i;
- char buf[512];
- char smallbuf[32];
int colw = 0;
+ int ncmds = tal_count(cmds);
x += xpad;
y += ypad;
@@ -184,65 +197,50 @@ draw_tree_vertical(Drw *drw, int x, int y, int w, int h) {
drw_rect(drw, 0, 0, w, h, 1, 1);
int c = '0';
- for (i = 0; i < 40; ++i, ++c, y += bh) {
- if (i % 2 == 0)
- snprintf(buf, 512, "item-long-%d", i);
- else if (i % 6 == 0)
- snprintf(buf, 512, "herpderp-%d", i);
- else if (i % 7 == 0)
- snprintf(buf, 512, "ksdfsdjhfsdf-%d", i);
- else
- snprintf(buf, 512, "hi-%d", i);
- if (c > '~') c = '0';
- sprintf(smallbuf, "%c", c);
-
- if (y >= mh) {
- x = colw;
- y = 0;
- colw = 0;
- }
- colw = MAX(draw_command(drw, x, y, buf, smallbuf) + 20, colw);
- }
-}
-static void
-draw_tree_horizontal(Drw *drw, int x, int y, int w, int h) {
- int i, dx = x, dy = y;
- char buf[512];
- char smallbuf[32];
+ for (i = 0; i < ncmds; ++i, ++c, y += bh) {
+ struct command *cmd = &cmds[i];
- drw_setscheme(drw, &schemes[SchemeNorm].bg_clr,
- &schemes[SchemeNorm].bg_clr);
- drw_rect(drw, 0, 0, w, h, 1, 1);
-
- int c = '0';
- for (i = 0; i < 50; ++i, ++c) {
- if (i % 2 == 0)
- snprintf(buf, 512, "item-long-%d", i);
- else if (i % 6 == 0)
- snprintf(buf, 512, "herpderp-%d", i);
- else if (i % 7 == 0)
- snprintf(buf, 512, "ksdfsdjhfsdf-%d", i);
- else
- snprintf(buf, 512, "hi-%d", i);
- if (c > '~') c = '0';
- sprintf(smallbuf, "%c", c);
- dx = draw_command(drw, dx, dy, buf, smallbuf) + 20;
- if (dx >= mw) {
- dx = 0;
- dy += bh;
- }
+ colw = MAX(draw_command(drw, x, y, cmd) + 20, colw);
}
}
+/* static void */
+/* draw_tree_horizontal(Drw *drw, struct command *cmds, int x, int y, int w, int h) { */
+/* int i, dx = x, dy = y; */
+
+/* drw_setscheme(drw, &schemes[SchemeNorm].bg_clr, */
+/* &schemes[SchemeNorm].bg_clr); */
+/* drw_rect(drw, 0, 0, w, h, 1, 1); */
+
+/* int c = '0'; */
+/* for (i = 0; i < 50; ++i, ++c) { */
+/* if (i % 2 == 0) */
+/* snprintf(buf, 512, "item-long-%d", i); */
+/* else if (i % 6 == 0) */
+/* snprintf(buf, 512, "herpderp-%d", i); */
+/* else if (i % 7 == 0) */
+/* snprintf(buf, 512, "ksdfsdjhfsdf-%d", i); */
+/* else */
+/* snprintf(buf, 512, "hi-%d", i); */
+/* if (c > '~') c = '0'; */
+/* sprintf(smallbuf, "%c", c); */
+/* dx = draw_command(drw, dx, dy, cmd) + 20; */
+/* if (dx >= mw) { */
+/* dx = 0; */
+/* dy += bh; */
+/* } */
+/* } */
+/* } */
+
static void
draw_tree(Drw *drw, int x, int y, int w, int h) {
if (!drw)
return;
/* draw_tree_horizontal(drw, x, y, w, h); */
- draw_tree_vertical(drw, x, y, w, h);
+ draw_tree_vertical(drw, rootcmds, x, y, w, h);
XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y);
XSync(drw->dpy, False);