summaryrefslogtreecommitdiff
path: root/src/commands.c
blob: e8ad9d6b9b4305b7cd0a1c4a6b2a374578b39ea3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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 cmumble_context *ctx)
{
	struct cmumble_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 cmumble_context *ctx)
{
	rl_already_prompted = 1;
	g_main_loop_quit(ctx->loop);
}

static void
clear(struct cmumble_context *ctx)
{
	rl_clear_screen(0,0);
	rl_reset_line_state();
	g_print("\n");
}

static void
help(struct cmumble_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[] = {
	{ "lu", 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 cmumble_context *ctx)
{
	ctx->commands = commands;
}