Keep active and sticky chats visible and fix unread counts
This commit is contained in:
parent
d01cc258e3
commit
847886a879
2 changed files with 89 additions and 38 deletions
|
|
@ -150,7 +150,9 @@ The left column is a tree: each server and its windows (channels and private
|
||||||
message windows). Channels appear before private message windows, with
|
message windows). Channels appear before private message windows, with
|
||||||
uppercase names sorting before lowercase names in each group. An unread window
|
uppercase names sorting before lowercase names in each group. An unread window
|
||||||
shows `(n)` next to its name. Each server shows its total unread count after
|
shows `(n)` next to its name. Each server shows its total unread count after
|
||||||
its name, including when folded. `*` marks a connected server. The selected server or window is shown bold and underlined. Highlights use the
|
its name, including when folded. The server count appears after startup channel
|
||||||
|
joins finish. Unread counts include chat messages, actions, and chat notices.
|
||||||
|
`*` marks a connected server. The selected server or window is shown bold and underlined. Highlights use the
|
||||||
terminal's default background so transparency is preserved where supported.
|
terminal's default background so transparency is preserved where supported.
|
||||||
Channel topics wrap to the chat pane width and stay at the top while you scroll.
|
Channel topics wrap to the chat pane width and stay at the top while you scroll.
|
||||||
On short terminals, the topic leaves room for at least one chat line when possible.
|
On short terminals, the topic leaves room for at least one chat line when possible.
|
||||||
|
|
@ -174,8 +176,8 @@ MODE, TOPIC, and INVITE events are shown in the relevant window.
|
||||||
| `Ctrl+Left` / `Ctrl+Right` | move to the previous / next word in the input line |
|
| `Ctrl+Left` / `Ctrl+Right` | move to the previous / next word in the input line |
|
||||||
| `Ctrl+Up` / `Ctrl+Down` | scroll the channel tree by one row |
|
| `Ctrl+Up` / `Ctrl+Down` | scroll the channel tree by one row |
|
||||||
| `ctrl-n` / `ctrl-p` | next / previous visible window (tree order, wraps around) |
|
| `ctrl-n` / `ctrl-p` | next / previous visible window (tree order, wraps around) |
|
||||||
| Enter | fold or unfold the selected server when the input line is empty |
|
| Enter | with empty input, fold or unfold a server, or toggle a chat’s sticky status (`*` after its name) |
|
||||||
| `Ctrl+H` | toggle hiding channels and private chats with no unread messages. They reappear when they have unread messages and their server is unfolded |
|
| `Ctrl+H` | toggle hiding inactive channels and private chats with no unread messages. Active and sticky chats stay visible when their server is unfolded |
|
||||||
| `PageUp` / `PageDown` | scroll the current window |
|
| `PageUp` / `PageDown` | scroll the current window |
|
||||||
| `ctrl-l` | clear the screen (history stays scrollable) |
|
| `ctrl-l` | clear the screen (history stays scrollable) |
|
||||||
| `ctrl-t` | toggle copy view, which hides the tree, chat timestamps, and sender names |
|
| `ctrl-t` | toggle copy view, which hides the tree, chat timestamps, and sender names |
|
||||||
|
|
|
||||||
107
irc9.c
107
irc9.c
|
|
@ -92,6 +92,7 @@ typedef struct Window {
|
||||||
int query_offline;
|
int query_offline;
|
||||||
int nlines;
|
int nlines;
|
||||||
int unread;
|
int unread;
|
||||||
|
int sticky;
|
||||||
int scroll;
|
int scroll;
|
||||||
int syncing;
|
int syncing;
|
||||||
struct timespec join_ts;
|
struct timespec join_ts;
|
||||||
|
|
@ -104,7 +105,7 @@ typedef struct AutojoinChannel {
|
||||||
char *commands;
|
char *commands;
|
||||||
const char *next_command;
|
const char *next_command;
|
||||||
int joined;
|
int joined;
|
||||||
struct timespec command_at;
|
struct timespec due_at;
|
||||||
struct AutojoinChannel *next;
|
struct AutojoinChannel *next;
|
||||||
} AutojoinChannel;
|
} AutojoinChannel;
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -371,7 +372,7 @@ static int window_visible_in_tree(const Window *w)
|
||||||
{
|
{
|
||||||
if (w->type == W_SERVER) return 1;
|
if (w->type == W_SERVER) return 1;
|
||||||
return !w->srv->tree_folded &&
|
return !w->srv->tree_folded &&
|
||||||
(!hide_read_windows || w->unread);
|
(!hide_read_windows || w == curwin || w->sticky || w->unread);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Window *next_visible_window(Window *w)
|
static Window *next_visible_window(Window *w)
|
||||||
|
|
@ -388,8 +389,7 @@ static void position_tree(int delta, int reveal_current)
|
||||||
int count = 0, current = -1;
|
int count = 0, current = -1;
|
||||||
for (Server *s = servers; s; s = s->next)
|
for (Server *s = servers; s; s = s->next)
|
||||||
for (Window *w = s->windows; w; w = next_visible_window(w), count++)
|
for (Window *w = s->windows; w; w = next_visible_window(w), count++)
|
||||||
if (curwin && (w == curwin ||
|
if (w == curwin) current = count;
|
||||||
(current < 0 && w == curwin->srv->windows))) current = count;
|
|
||||||
|
|
||||||
int offset = tree_offset + delta;
|
int offset = tree_offset + delta;
|
||||||
if (reveal_current && current >= 0) {
|
if (reveal_current && current >= 0) {
|
||||||
|
|
@ -498,7 +498,6 @@ static void win_append_raw(Window *w, const char *text, int keep_formatting, siz
|
||||||
w->lines[w->nlines++] = (ScrollLine){line, strlen(stamp) + body_offset};
|
w->lines[w->nlines++] = (ScrollLine){line, strlen(stamp) + body_offset};
|
||||||
free(clean);
|
free(clean);
|
||||||
if (w->scroll > 0 && w->scroll < scrollback_limit * MAXWRAPROWS) w->scroll++;
|
if (w->scroll > 0 && w->scroll < scrollback_limit * MAXWRAPROWS) w->scroll++;
|
||||||
if (w != curwin) w->unread++;
|
|
||||||
dirty = 1;
|
dirty = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -568,9 +567,9 @@ static void switch_window(int dir)
|
||||||
if (t->windows) { target = t->windows; break; }
|
if (t->windows) { target = t->windows; break; }
|
||||||
} else {
|
} else {
|
||||||
for (Server *s = servers; s; s = s->next)
|
for (Server *s = servers; s; s = s->next)
|
||||||
for (Window *w = s->windows; w; w = w->next) {
|
for (Window *w = s->windows; w; w = next_visible_window(w)) {
|
||||||
if (w == curwin) goto found;
|
if (w == curwin) goto found;
|
||||||
if (window_visible_in_tree(w)) target = w;
|
target = w;
|
||||||
}
|
}
|
||||||
found:;
|
found:;
|
||||||
if (!target)
|
if (!target)
|
||||||
|
|
@ -1158,14 +1157,12 @@ static void send_autojoin(Server *s)
|
||||||
AutojoinChannel *channel = s->autojoin;
|
AutojoinChannel *channel = s->autojoin;
|
||||||
s->autojoin = channel->next;
|
s->autojoin = channel->next;
|
||||||
sendf(s, "JOIN %s", channel->name);
|
sendf(s, "JOIN %s", channel->name);
|
||||||
if (channel->commands) {
|
|
||||||
AutojoinChannel **pending = &s->pending_autojoin;
|
AutojoinChannel **pending = &s->pending_autojoin;
|
||||||
while (*pending) pending = &(*pending)->next;
|
while (*pending) pending = &(*pending)->next;
|
||||||
channel->next = NULL;
|
channel->next = NULL;
|
||||||
|
channel->due_at = now;
|
||||||
|
channel->due_at.tv_sec += 30;
|
||||||
*pending = channel;
|
*pending = channel;
|
||||||
} else {
|
|
||||||
free(channel);
|
|
||||||
}
|
|
||||||
s->next_autojoin = now;
|
s->next_autojoin = now;
|
||||||
s->next_autojoin.tv_sec += 2;
|
s->next_autojoin.tv_sec += 2;
|
||||||
}
|
}
|
||||||
|
|
@ -1297,6 +1294,12 @@ static int parse_irc(char *line, char **prefix, char **cmd, char **argv, int max
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mark_unread_message(Window *w)
|
||||||
|
{
|
||||||
|
if (w != curwin && w->type != W_SERVER && w->unread < INT_MAX)
|
||||||
|
w->unread++;
|
||||||
|
}
|
||||||
|
|
||||||
/* Returns 1 when the message was CTCP and has been dealt with. */
|
/* Returns 1 when the message was CTCP and has been dealt with. */
|
||||||
static int handle_ctcp(Server *s, const char *nick, char *text,
|
static int handle_ctcp(Server *s, const char *nick, char *text,
|
||||||
Window *w, int is_reply)
|
Window *w, int is_reply)
|
||||||
|
|
@ -1318,6 +1321,7 @@ static int handle_ctcp(Server *s, const char *nick, char *text,
|
||||||
if (is_reply) {
|
if (is_reply) {
|
||||||
append_nickf(w, "* ", nick, " ", "CTCP %s: %s", cmd, arg);
|
append_nickf(w, "* ", nick, " ", "CTCP %s: %s", cmd, arg);
|
||||||
} else if (strcasecmp(cmd, "ACTION") == 0) {
|
} else if (strcasecmp(cmd, "ACTION") == 0) {
|
||||||
|
mark_unread_message(w);
|
||||||
append_nickf(w, "* ", nick, " ", "%s", arg);
|
append_nickf(w, "* ", nick, " ", "%s", arg);
|
||||||
} else if (strcasecmp(cmd, "VERSION") == 0) {
|
} else if (strcasecmp(cmd, "VERSION") == 0) {
|
||||||
sendf(s, "NOTICE %s :\001VERSION irc9\001", nick);
|
sendf(s, "NOTICE %s :\001VERSION irc9\001", nick);
|
||||||
|
|
@ -1387,8 +1391,8 @@ static void run_autojoin_command(AutojoinChannel **link, Window *w)
|
||||||
take_configured_command(&channel->next_command, line);
|
take_configured_command(&channel->next_command, line);
|
||||||
|
|
||||||
if (channel->next_command) {
|
if (channel->next_command) {
|
||||||
clock_gettime(CLOCK_MONOTONIC, &channel->command_at);
|
clock_gettime(CLOCK_MONOTONIC, &channel->due_at);
|
||||||
channel->command_at.tv_sec += 2;
|
channel->due_at.tv_sec += 2;
|
||||||
} else {
|
} else {
|
||||||
*link = channel->next;
|
*link = channel->next;
|
||||||
free(channel->commands);
|
free(channel->commands);
|
||||||
|
|
@ -1397,15 +1401,34 @@ static void run_autojoin_command(AutojoinChannel **link, Window *w)
|
||||||
do_command(w, line);
|
do_command(w, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void remove_pending_autojoin(AutojoinChannel **link)
|
||||||
|
{
|
||||||
|
AutojoinChannel *channel = *link;
|
||||||
|
*link = channel->next;
|
||||||
|
free(channel->commands);
|
||||||
|
free(channel);
|
||||||
|
dirty = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static AutojoinChannel **find_pending_join(Server *s, const char *name)
|
||||||
|
{
|
||||||
|
AutojoinChannel **link = &s->pending_autojoin;
|
||||||
|
while (*link && ((*link)->joined || strcasecmp((*link)->name, name) != 0))
|
||||||
|
link = &(*link)->next;
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|
||||||
static void confirm_autojoin(Window *w)
|
static void confirm_autojoin(Window *w)
|
||||||
{
|
{
|
||||||
AutojoinChannel **link = &w->srv->pending_autojoin;
|
AutojoinChannel **link = find_pending_join(w->srv, w->name);
|
||||||
while (*link && ((*link)->joined || strcasecmp((*link)->name, w->name) != 0))
|
|
||||||
link = &(*link)->next;
|
|
||||||
if (!*link) return;
|
if (!*link) return;
|
||||||
|
|
||||||
(*link)->joined = 1;
|
(*link)->joined = 1;
|
||||||
|
dirty = 1;
|
||||||
|
if ((*link)->next_command)
|
||||||
run_autojoin_command(link, w);
|
run_autojoin_command(link, w);
|
||||||
|
else
|
||||||
|
remove_pending_autojoin(link);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void run_pending_autojoin_commands(Server *s)
|
static void run_pending_autojoin_commands(Server *s)
|
||||||
|
|
@ -1415,15 +1438,13 @@ static void run_pending_autojoin_commands(Server *s)
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
for (AutojoinChannel **link = &s->pending_autojoin; *link; link = &(*link)->next) {
|
for (AutojoinChannel **link = &s->pending_autojoin; *link; link = &(*link)->next) {
|
||||||
AutojoinChannel *channel = *link;
|
AutojoinChannel *channel = *link;
|
||||||
if (!channel->joined || !command_due(now, channel->command_at)) continue;
|
if (!command_due(now, channel->due_at)) continue;
|
||||||
|
|
||||||
Window *w = window_find(s, channel->name);
|
Window *w = channel->joined ? window_find(s, channel->name) : NULL;
|
||||||
if (w) {
|
if (w) {
|
||||||
run_autojoin_command(link, w);
|
run_autojoin_command(link, w);
|
||||||
} else {
|
} else {
|
||||||
*link = channel->next;
|
remove_pending_autojoin(link);
|
||||||
free(channel->commands);
|
|
||||||
free(channel);
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1517,6 +1538,7 @@ static void handle_line(Server *s, char *line)
|
||||||
if (w->type == W_QUERY && hostmask && strchr(hostmask, '!'))
|
if (w->type == W_QUERY && hostmask && strchr(hostmask, '!'))
|
||||||
snprintf(w->hostmask, sizeof w->hostmask, "%s", hostmask);
|
snprintf(w->hostmask, sizeof w->hostmask, "%s", hostmask);
|
||||||
if (narg > 1 && handle_ctcp(s, nick, arg[1], w, notice)) return;
|
if (narg > 1 && handle_ctcp(s, nick, arg[1], w, notice)) return;
|
||||||
|
mark_unread_message(w);
|
||||||
if (notice) append_nickf(w, "-", *nick ? nick : "server", "- ", "%s", text);
|
if (notice) append_nickf(w, "-", *nick ? nick : "server", "- ", "%s", text);
|
||||||
else append_nickf(w, "<", *nick ? nick : "server", "> ", "%s", text);
|
else append_nickf(w, "<", *nick ? nick : "server", "> ", "%s", text);
|
||||||
return;
|
return;
|
||||||
|
|
@ -1864,6 +1886,15 @@ static void handle_line(Server *s, char *line)
|
||||||
if (narg > 0) appendf(sw, "* %s", arg[narg - 1]);
|
if (narg > 0) appendf(sw, "* %s", arg[narg - 1]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#ifdef USE_AUTOJOIN
|
||||||
|
if (narg >= 2 && (strcmp(cmd, "403") == 0 || strcmp(cmd, "405") == 0 ||
|
||||||
|
strcmp(cmd, "471") == 0 || strcmp(cmd, "473") == 0 ||
|
||||||
|
strcmp(cmd, "474") == 0 || strcmp(cmd, "475") == 0 ||
|
||||||
|
strcmp(cmd, "476") == 0 || strcmp(cmd, "477") == 0)) {
|
||||||
|
AutojoinChannel **link = find_pending_join(s, arg[1]);
|
||||||
|
if (*link) remove_pending_autojoin(link);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
if (strcmp(cmd, "461") == 0 || strcmp(cmd, "403") == 0 ||
|
if (strcmp(cmd, "461") == 0 || strcmp(cmd, "403") == 0 ||
|
||||||
strcmp(cmd, "404") == 0 || strcmp(cmd, "405") == 0 ||
|
strcmp(cmd, "404") == 0 || strcmp(cmd, "405") == 0 ||
|
||||||
strcmp(cmd, "482") == 0 ||
|
strcmp(cmd, "482") == 0 ||
|
||||||
|
|
@ -2535,8 +2566,11 @@ static void handle_key(int c)
|
||||||
|
|
||||||
|
|
||||||
if (c == '\n' || c == '\r') {
|
if (c == '\n' || c == '\r') {
|
||||||
if (!*input && curwin && curwin->type == W_SERVER) {
|
if (!*input && curwin) {
|
||||||
|
if (curwin->type == W_SERVER)
|
||||||
curwin->srv->tree_folded = !curwin->srv->tree_folded;
|
curwin->srv->tree_folded = !curwin->srv->tree_folded;
|
||||||
|
else
|
||||||
|
curwin->sticky = !curwin->sticky;
|
||||||
hist_cur = -1;
|
hist_cur = -1;
|
||||||
position_tree(0, 1);
|
position_tree(0, 1);
|
||||||
dirty = 1;
|
dirty = 1;
|
||||||
|
|
@ -2767,6 +2801,19 @@ static int irc_to_ansi_color(int color)
|
||||||
return color >= 0 && color < 16 ? map[color] : 9;
|
return color >= 0 && color < 16 ? map[color] : 9;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long long server_unread_messages(const Server *s)
|
||||||
|
{
|
||||||
|
#ifdef USE_AUTOJOIN
|
||||||
|
if (s->autojoin) return 0;
|
||||||
|
for (const AutojoinChannel *channel = s->pending_autojoin; channel; channel = channel->next)
|
||||||
|
if (!channel->joined) return 0;
|
||||||
|
#endif
|
||||||
|
long long unread = 0;
|
||||||
|
for (const Window *w = s->windows; w; w = w->next)
|
||||||
|
unread += w->unread;
|
||||||
|
return unread;
|
||||||
|
}
|
||||||
|
|
||||||
static void draw_tree(void)
|
static void draw_tree(void)
|
||||||
{
|
{
|
||||||
int bottom = lines - 3;
|
int bottom = lines - 3;
|
||||||
|
|
@ -2800,9 +2847,7 @@ static void draw_tree(void)
|
||||||
fputs(w == curwin ? (terminal_color ? "\033[1;4m" : "\033[7m") : "\033[1m", stdout);
|
fputs(w == curwin ? (terminal_color ? "\033[1;4m" : "\033[7m") : "\033[1m", stdout);
|
||||||
putchar(s->connected ? '*' : ' ');
|
putchar(s->connected ? '*' : ' ');
|
||||||
if (s->tree_folded) putchar('+');
|
if (s->tree_folded) putchar('+');
|
||||||
long long unread = 0;
|
long long unread = server_unread_messages(s);
|
||||||
for (Window *child = s->windows; child; child = child->next)
|
|
||||||
unread += child->unread;
|
|
||||||
int columns = treew - 3 - s->tree_folded;
|
int columns = treew - 3 - s->tree_folded;
|
||||||
char count[32] = "";
|
char count[32] = "";
|
||||||
int count_width = unread ? snprintf(count, sizeof count, " (%lld)", unread) : 0;
|
int count_width = unread ? snprintf(count, sizeof count, " (%lld)", unread) : 0;
|
||||||
|
|
@ -2813,9 +2858,6 @@ static void draw_tree(void)
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
char label[CHANLEN + 16];
|
|
||||||
if (w->unread) snprintf(label, sizeof label, "%s(%d)", w->name, w->unread);
|
|
||||||
else snprintf(label, sizeof label, "%s", w->name);
|
|
||||||
if (treew > 5) {
|
if (treew > 5) {
|
||||||
terminal_move(y, 2);
|
terminal_move(y, 2);
|
||||||
terminal_accent();
|
terminal_accent();
|
||||||
|
|
@ -2824,7 +2866,14 @@ static void draw_tree(void)
|
||||||
if (w == curwin) fputs(terminal_color ? "\033[1;4m" : "\033[7m", stdout);
|
if (w == curwin) fputs(terminal_color ? "\033[1;4m" : "\033[7m", stdout);
|
||||||
if (colored_nicks && terminal_color && w->type == W_QUERY)
|
if (colored_nicks && terminal_color && w->type == W_QUERY)
|
||||||
printf("\033[%dm", 30 + irc_to_ansi_color(nick_color(s, w->name, strlen(w->name))));
|
printf("\033[%dm", 30 + irc_to_ansi_color(nick_color(s, w->name, strlen(w->name))));
|
||||||
terminal_text(label, treew - 6);
|
int columns = treew - 6;
|
||||||
|
char suffix[32] = "";
|
||||||
|
if (w->unread) snprintf(suffix, sizeof suffix, "%s(%d)", w->sticky ? "*" : "", w->unread);
|
||||||
|
else if (w->sticky) strcpy(suffix, "*");
|
||||||
|
int suffix_width = (int)strlen(suffix);
|
||||||
|
if (suffix_width > columns) suffix_width = w->sticky && columns > 0 ? 1 : 0;
|
||||||
|
terminal_text(w->name, columns - suffix_width);
|
||||||
|
if (suffix_width) fwrite(suffix, 1, (size_t)suffix_width, stdout);
|
||||||
fputs("\033[0m", stdout);
|
fputs("\033[0m", stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue