~jb55/cmdtree

4f0b9cf334f0a763ff1fcfaabb61796f412a6452 — William Casarin 2 years ago ee15cfc
bind name aliases

this supports SPC as a bind alias. You could also use ' ' but now SPC is
supported and rendered properly.
2 files changed, 20 insertions(+), 3 deletions(-)

M cmdtree.c
M command.c
M cmdtree.c => cmdtree.c +12 -2
@@ 186,6 186,14 @@ setup(Drw *drw)
	/* draw_tree(drw); */
}

static const char *
bind_name(const char *bind) {
	switch (*bind) {
	case ' ': return "SPC";
	default:  return bind;
	}
}

static int
draw_command(Drw *drw, int x, int y, struct command *cmd) {
	char buf[256];


@@ 202,8 210,10 @@ draw_command(Drw *drw, int x, int y, struct command *cmd) {
	drw_setscheme(drw, &schemes[SchemeNorm].bind_clr,
		      &schemes[SchemeNorm].bg_clr);

	w = drw_fontset_getwidth(drw, cmd->bind);
	x = drw_text(drw, x+pad, y, w, bh, lpad, cmd->bind, invert);
	const char *bindname = bind_name(cmd->bind);

	w = drw_fontset_getwidth(drw, bindname);
	x = drw_text(drw, x+pad, y, w, bh, lpad, bindname, invert);

	w = sep_width;
	drw_setscheme(drw, &schemes[SchemeNorm].arrow_clr,

M command.c => command.c +8 -1
@@ 8,6 8,13 @@

#include "util.h"

static const char *
bind_name_to_bind(const char *bind) {
	if (strcmp(bind, "STR") == 0)
		return " ";
	return bind;
}

int
command_is_prefix(struct command *cmd) {
	return cmd->nchildren > 0;


@@ 28,7 35,7 @@ command_num_children(struct command *cmd) {
struct command *
command_lookup(struct command *cmd, int ncmds, const char *binding) {
	for (int i = 0; i < ncmds; ++i) {
		if (strcmp(binding, cmd[i].bind) == 0)
		if (strcmp(binding, bind_name_to_bind(cmd[i].bind)) == 0)
			return &cmd[i];
	}