diff options
Diffstat (limited to 'src/commands.c')
-rw-r--r-- | src/commands.c | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/commands.c b/src/commands.c new file mode 100644 index 0000000..be78a69 --- /dev/null +++ b/src/commands.c @@ -0,0 +1,60 @@ +#include "../config.h" +#include "commands.h" +#include "cmumble.h" + +#include <glib.h> + +#include <readline/readline.h> +#include <readline/history.h> + +static void +list_users(struct context *ctx) +{ + struct user *user = NULL; + GList *l; + + for (l = ctx->users; l; l = l->next) { + user = l->data; + + g_print("%4d: %s\n", user->user_id, user->name); + } +} + +static void +quit(struct context *ctx) +{ + rl_already_prompted = 1; + g_main_loop_quit(ctx->loop); +} + +static void +clear(struct context *ctx) +{ + rl_clear_screen(0,0); + rl_reset_line_state(); + g_print("\n"); +} + +static void +help(struct context *ctx) +{ + int i; + + for (i = 0; ctx->commands[i].name; ++i) + g_print("%s\t%s\n", + ctx->commands[i].name, ctx->commands[i].description); +} + +static const struct cmumble_command commands[] = { + { "ls", list_users, "list users" }, + { "clear", clear, "clear screen" }, + { "help", help, "show this help" }, + { "quit", quit, "quit " PACKAGE }, + { NULL, NULL , NULL} +}; + +void +cmumble_commands_init(struct context *ctx) +{ + ctx->commands = commands; +} |