commit 67c2d14481b1b0301f229aad75005fca19047537
parent 6d6075d17b3445d952d1cd26f0a0a118702bdee4
Author: hhvn <dev@hhvn.uk>
Date: Tue, 26 Oct 2021 00:08:07 +0100
ui.c main.c hirc.h: windowlist
Diffstat:
M | hirc.h | | | 4 | +++- |
M | main.c | | | 12 | ++++++++---- |
M | ui.c | | | 45 | +++++++++++++++++++++++++++++++++++++++++++-- |
3 files changed, 54 insertions(+), 7 deletions(-)
diff --git a/hirc.h b/hirc.h
@@ -91,10 +91,11 @@ void handle_NICK(char *msg, char **params, struct Server *server, time_t timest
/* ui.c */
void ui_init(void);
-void ui_read(void);
+void ui_read(int refresh);
void ui_redraw(void);
void ui_draw_input(void);
void ui_draw_nicklist(void);
+void ui_draw_winlist(void);
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__);
@@ -112,6 +113,7 @@ void ui_tls_error_(char *file, int line, struct tls *ctx, char *str);
void command_eval(char *str);
/* main.c */
+extern struct Server *servers;
extern struct HistInfo *main_buf;
/* ui.c */
diff --git a/main.c b/main.c
@@ -179,7 +179,7 @@ main(int argc, char **argv) {
struct Selected oldselected;
struct Server *sp;
FILE *file;
- int i;
+ int i, refreshed;
struct pollfd fds[] = {
{ .fd = fileno(stdin), .events = POLLIN },
};
@@ -229,8 +229,10 @@ main(int argc, char **argv) {
}
if (oldselected.channel != selected.channel || oldselected.server != selected.server) {
- windows[Win_nicklist].redraw = 1;
- windows[Win_winlist].redraw = 1;
+ if (windows[Win_nicklist].location)
+ windows[Win_nicklist].redraw = 1;
+ if (windows[Win_winlist].location)
+ windows[Win_winlist].redraw = 1;
}
oldselected.channel = selected.channel;
@@ -238,16 +240,18 @@ main(int argc, char **argv) {
oldselected.history = selected.history;
oldselected.name = selected.name;
+ refreshed = 0;
for (i=0; i < Win_last; i++) {
if (windows[i].redraw) {
if (windows[i].handler)
windows[i].handler();
wrefresh(windows[i].window);
windows[i].redraw = 0;
+ refreshed = 1;
}
}
- ui_read();
+ ui_read(refreshed);
}
return 0;
diff --git a/ui.c b/ui.c
@@ -14,7 +14,7 @@ struct Window windows[Win_last] = {
[Win_main] = {.handler = NULL},
[Win_input] = {.handler = ui_draw_input},
[Win_nicklist] = {.handler = ui_draw_nicklist},
- [Win_winlist] = {.handler = NULL},
+ [Win_winlist] = {.handler = ui_draw_winlist},
};
struct Selected selected;
@@ -111,12 +111,14 @@ ui_placewindow(struct Window *window) {
}
void
-ui_read(void) {
+ui_read(int refresh) {
int key;
switch (key = wgetch(stdscr)) {
case ERR:
/* this happens due to nodelay */
+ if (refreshalways)
+ wrefresh(window[Win_input].window);
return;
case KEY_RESIZE:
ui_redraw();
@@ -253,6 +255,45 @@ ui_draw_nicklist(void) {
}
void
+ui_draw_winlist(void) {
+ struct Server *sp;
+ struct Channel *chp;
+ int i = 0, len, tmp;
+
+ wclear(windows[Win_winlist].window);
+ if (!windows[Win_winlist].location)
+ return;
+
+ if (selected.history == main_buf)
+ wattron(windows[Win_winlist].window, A_BOLD);
+ len = wprintw(windows[Win_winlist].window, "%02d: %s\n", i++, "hirc");
+ wattroff(windows[Win_winlist].window, A_BOLD);
+
+ for (sp = servers; sp; sp = sp->next) {
+ if (selected.server == sp && !selected.channel)
+ wattron(windows[Win_winlist].window, A_BOLD);
+ else if (sp->status != ConnStatus_connected)
+ wattron(windows[Win_winlist].window, A_DIM);
+
+ len = wprintw(windows[Win_winlist].window, "%02d: %c- %s\n", i++, sp->next ? '|' : '`', sp->name);
+ wattroff(windows[Win_winlist].window, A_BOLD);
+ wattroff(windows[Win_winlist].window, A_DIM);
+
+ for (chp = sp->channels; chp; chp = chp->next) {
+ if (selected.channel == chp)
+ wattron(windows[Win_winlist].window, A_BOLD);
+ else if (chp->old)
+ wattron(windows[Win_winlist].window, A_DIM);
+
+ len = wprintw(windows[Win_winlist].window, "%02d: %c %c- %s\n", i++,
+ sp->next ? '|' : ' ', chp->next ? '|' : '`', chp->name);
+ wattroff(windows[Win_winlist].window, A_BOLD);
+ wattroff(windows[Win_winlist].window, A_DIM);
+ }
+ }
+}
+
+void
ui_select(struct Server *server, struct Channel *channel) {
selected.channel = channel;
selected.server = server;