1
0
Fork 0
forked from murx/irc9

Pin channel topics above chat scrollback

This commit is contained in:
Johannes Findeisen 2026-11-27 23:02:57 +01:00
commit b1e89cf5d7
2 changed files with 35 additions and 8 deletions

View file

@ -104,7 +104,7 @@ Build yours by copying `irc9rc-example` to `irc9rc` next to the binary (or to
```
[irc9] irc.example / #general
/----------------------\
/----------------------\ Topic: General discussion
|* irc.example |
| |-#general |
| |-#help(3) |
@ -120,6 +120,7 @@ The left column is a tree: each server and its windows (channels and private
message windows). An unread window shows `(n)` next to its name. `*` 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.
Channel topics stay at the top of the chat pane while you scroll.
The right pane shows the current window's scrollback with `[HH:MM]` timestamps.
Joins, parts and quits include the full hostmask; joins and parts also name the
channel. The status line above the input shows the time, nick, server, port, TLS state, and user modes.

40
irc9.c
View file

@ -68,6 +68,7 @@ typedef struct Member {
typedef struct Window {
char name[CHANLEN];
char hostmask[128];
char topic[MAXLINE];
Wintype type;
struct Server *srv;
struct Window *next;
@ -372,6 +373,15 @@ static char *strip_ircfmt(const char *s)
return out;
}
static void set_channel_topic(Window *w, const char *topic)
{
if (!w || w->type != W_CHANNEL) return;
char *plain = strip_formatting ? strip_ircfmt(topic) : NULL;
snprintf(w->topic, sizeof w->topic, "%s", plain ? plain : topic);
free(plain);
dirty = 1;
}
static void win_append_raw(Window *w, const char *text)
{
if (w->nlines == MAXSCROLL) {
@ -1243,6 +1253,7 @@ static void handle_line(Server *s, char *line)
if (strcasecmp(cmd, "TOPIC") == 0 && narg >= 2) {
Window *w = window_get(s, arg[0], W_CHANNEL);
set_channel_topic(w, arg[1]);
appendf(w, "* %s changed topic of %s: %s", *nick ? nick : "server",
arg[0], arg[1]);
return;
@ -1366,11 +1377,13 @@ static void handle_line(Server *s, char *line)
}
/* Replies for /topic, /who, /list and the informational commands. */
if (strcmp(cmd, "331") == 0 && narg >= 3) {
if (strcmp(cmd, "331") == 0 && narg >= 2) {
set_channel_topic(window_find(s, arg[1]), "");
appendf(reply_window(s), "* no topic for %s", arg[1]);
return;
}
if (strcmp(cmd, "332") == 0 && narg >= 3) {
set_channel_topic(window_find(s, arg[1]), arg[2]);
appendf(reply_window(s), "* topic for %s: %s", arg[1], arg[2]);
return;
}
@ -1994,6 +2007,11 @@ static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
}
}
static int topic_rows(void)
{
return curwin && curwin->type == W_CHANNEL && mainh > 0 && cols - treew >= 3;
}
static void handle_key(int c)
{
if (saving) {
@ -2019,7 +2037,7 @@ static void handle_key(int c)
if (c == 0x0e) { switch_window(1); return; } /* ctrl-n */
if (c == 0x10) { switch_window(-1); return; } /* ctrl-p */
if (c == 0x0c) { /* ctrl-l */
if (curwin) { curwin->scroll = -mainh; dirty = 1; }
if (curwin) { curwin->scroll = -(mainh - topic_rows()); dirty = 1; }
return;
}
@ -2030,7 +2048,8 @@ static void handle_key(int c)
if (c == KEY_DOWN) { history_browse(1); dirty = 1; return; }
if (c == KEY_PPAGE) {
if (curwin) {
int step = mainh > 1 ? mainh - 1 : 1;
int height = mainh - topic_rows();
int step = height > 1 ? height - 1 : 1;
if (curwin->scroll < 0) curwin->scroll = 0;
if (curwin->scroll > MAXSCROLLROWS - step)
curwin->scroll = MAXSCROLLROWS;
@ -2042,7 +2061,8 @@ static void handle_key(int c)
}
if (c == KEY_NPAGE) {
if (curwin) {
curwin->scroll -= mainh > 1 ? mainh - 1 : 1;
int height = mainh - topic_rows();
curwin->scroll -= height > 1 ? height - 1 : 1;
if (curwin->scroll < 0) curwin->scroll = 0;
dirty = 1;
}
@ -2368,8 +2388,14 @@ static void draw_main(void)
if (curwin && mainh > 0 && width >= 3) {
int ww = width - 2;
if (ww < 1) ww = 1;
int h = mainh;
int header = topic_rows();
if (header) {
const char *topic = curwin->topic[0] ? curwin->topic : "(no topic)";
draw_irc_text(1, treew + 1, "Topic:", ww);
if (ww > 7) draw_irc_text(1, treew + 8, topic, ww - 7);
}
int h = mainh - header;
if (h == 0) return;
long long need_ll = (long long)h + curwin->scroll;
if (need_ll < 0) need_ll = 0;
size_t need = (size_t)need_ll;
@ -2388,7 +2414,7 @@ static void draw_main(void)
for (int r = 0; r < h; r++) {
int idx = curwin->scroll + (h - 1 - r);
if (idx >= 0 && idx < nr && rows[idx])
draw_irc_text(r + 1, treew + 1, rows[idx], ww);
draw_irc_text(r + 1 + header, treew + 1, rows[idx], ww);
}
for (int i = 0; i < nr; i++) free(rows[i]);
free(rows);