From d2ce420ae24cbdd2c61f38342bdabc19c2358947 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 9 Jul 2018 17:43:46 -0700 Subject: it works yo --- cmdtree.c | 5 +++-- command.c | 11 +++++++++-- command.h | 3 +++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/cmdtree.c b/cmdtree.c index 68e8a02..07720a8 100644 --- a/cmdtree.c +++ b/cmdtree.c @@ -292,8 +292,9 @@ run(Drw *drw) { rootcmds = cmd->children; draw_tree(drw, 0, 0, mw, mh); } - else // TODO: launch command - done = 1; + else { + command_exec(cmd); + } } break; diff --git a/command.c b/command.c index accf212..ee31b05 100644 --- a/command.c +++ b/command.c @@ -4,6 +4,8 @@ #include "ccan/tal/tal.h" #include "ccan/tal/str/str.h" #include "ccan/str/str.h" +#include +#include #include "util.h" @@ -18,6 +20,11 @@ command_is_prefix(struct command *cmd) { return count > 0; } +void +command_exec(struct command *cmd) { + execlp(cmd->name, cmd->name, (char *)NULL); + err(1, "executing command %s", cmd->name); +} struct command * command_lookup(struct command *cmd, const char *binding) { @@ -33,7 +40,7 @@ command_lookup(struct command *cmd, const char *binding) { static const struct command examples[] = { { .bind = "f", .name = "firefox" }, { .bind = "m", .name = "misc" }, - { .bind = "e", .name = "spacemacs" }, + { .bind = "e", .name = "emacs" }, { .bind = "N", .name = "networking" }, }; @@ -57,7 +64,7 @@ test_root_commands(tal_t *ctx) { } child = cmds[i].children = tal_arr(cmds, struct command, i % 2); for (j = 0; j < tal_count(child); j++) { - child[j].name = tal_fmt(child, "child-%d-%d", (int)i, (int)j); + child[j].name = "sayhi"; child[j].bind = tal_fmt(child, "%c", (int)(c+j)); child[j].children = NULL; } diff --git a/command.h b/command.h index 750f109..770d3a7 100644 --- a/command.h +++ b/command.h @@ -15,6 +15,9 @@ struct command { void command_init(struct command *cmd); +void +command_exec(struct command *cmd); + struct command * command_lookup(struct command *cmd, const char *binding); -- cgit v1.2.3