commit ef575beb487d5cffe517f3b5dbbcb501e7f0d9b3
parent aca519f147fe93e9efe0ad4038ff04a023b3fa55
Author: hhvn <dev@hhvn.uk>
Date: Wed, 27 Oct 2021 22:01:43 +0100
ui.c commands.c hirc.h: /select for selecting buffers
Diffstat:
3 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/commands.c b/commands.c
@@ -6,6 +6,7 @@
void
command_eval(char *str) {
char msg[512];
+ char *s;
if (*str != '/' || strncmp(str, "/ /", sizeof("/ /")) == 0) {
if (strncmp(str, "/ /", sizeof("/ /")) == 0)
@@ -27,6 +28,14 @@ command_eval(char *str) {
exit(0);
}
+ if (strncmp(str, "/select", strlen("/select")) == 0) {
+ if ((s = strchr(str, ' ')) != NULL) {
+ s++;
+ ui_buflist_select(atoi(s));
+ return;
+ }
+ }
+
str++;
ircprintf(selected.server, "%s\r\n", str);
}
diff --git a/hirc.h b/hirc.h
@@ -97,6 +97,7 @@ void ui_draw_input(void);
void ui_draw_nicklist(void);
void ui_draw_buflist(void);
int ui_buflist_count(int *ret_servers, int *ret_channels);
+void ui_buflist_select(int num);
void ui_select(struct Server *server, struct Channel *channel);
void ui_error_(char *file, int line, char *format, ...);
#define ui_error(format, ...) ui_error_(__FILE__, __LINE__, format, __VA_ARGS__);
diff --git a/ui.c b/ui.c
@@ -282,6 +282,32 @@ ui_buflist_count(int *ret_servers, int *ret_channels) {
}
void
+ui_buflist_select(int num) {
+ struct Server *sp;
+ struct Channel *chp;
+ int i;
+
+ if (num == 0) {
+ ui_select(NULL, NULL);
+ return;
+ }
+
+ for (i = 1, sp = servers; sp; sp = sp->next, i++) {
+ if (i == num) {
+ ui_select(sp, NULL);
+ return;
+ }
+
+ for (i++, chp = sp->channels; chp; chp = chp->next, i++) {
+ if (i == num) {
+ ui_select(sp, chp);
+ return;
+ }
+ }
+ }
+}
+
+void
ui_draw_buflist(void) {
struct Server *sp;
struct Channel *chp;