From 7c3ed0c61d22c2e4ae91275b13c3962e03c70d08 Mon Sep 17 00:00:00 2001 From: Tim Kourt Date: Wed, 12 Apr 2017 13:04:49 -0700 Subject: [PATCH] client: Command display functions --- client/display.c | 32 ++++++++++++++++++++++++++++++++ client/display.h | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/client/display.c b/client/display.c index 6f7db4f1..375cd54a 100644 --- a/client/display.c +++ b/client/display.c @@ -29,6 +29,7 @@ #include #include +#include "command.h" #include "display.h" #define IWD_PROMPT COLOR_GREEN "[iwd]" COLOR_OFF "# " @@ -143,6 +144,37 @@ void display_table_footer(void) display_text("\n"); } +void display_command_line(const char *command_family, + const struct command *cmd) +{ + char *cmd_line = l_strdup_printf("%s%s%s%s%s %s", + command_family ? : "", + command_family ? " " : "", + cmd->entity ? : "", + cmd->entity ? " " : "", + cmd->cmd, + cmd->arg ? : "", + cmd->arg ? " " : ""); + + display(MARGIN "%-*s%s\n", 50, cmd_line, cmd->desc ? : ""); + + l_free(cmd_line); +} + +void display_command(const struct command_family *family, const char *cmd_name) +{ + size_t i; + + for (i = 0; family->command_list[i].cmd; i++) { + if (!strcmp(family->command_list[i].cmd, cmd_name)) { + display_command_line(family->name, + &family->command_list[i]); + + return; + } + } +} + static void readline_callback(char *prompt) { l_free(prompt); diff --git a/client/display.h b/client/display.h index eeed75e2..25eecac8 100644 --- a/client/display.h +++ b/client/display.h @@ -20,6 +20,9 @@ * */ +struct command; +struct command_family; + #define COLOR_BOLDGRAY "\x1B[1;30m" #define COLOR_GRAY "\x1b[37m" #define COLOR_GREEN "\x1b[32m" @@ -33,6 +36,9 @@ void display(const char *format, ...); void display_table_header(const char *caption, const char *fmt, ...); void display_table_footer(void); void display_error(const char *error); +void display_command(const struct command_family *family, const char *cmd_name); +void display_command_line(const char *command_family, + const struct command *cmd); void display_enable_cmd_prompt(void); void display_disable_cmd_prompt(void);