Toggle server tree folding with Enter

This commit is contained in:
Johannes Findeisen 2026-12-02 00:32:00 +01:00
commit b488fdad57
2 changed files with 28 additions and 8 deletions

View file

@ -172,7 +172,8 @@ MODE, TOPIC, and INVITE events are shown in the relevant window.
| `Tab` | complete a `/` command or a nick; press again to cycle matches (recently completed nicks come first) |
| `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-n` / `ctrl-p` | next / previous 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 |
| `PageUp` / `PageDown` | scroll the current window |
| `ctrl-l` | clear the screen (history stays scrollable) |
| `ctrl-t` | toggle copy view, which hides the tree, chat timestamps, and sender names |

33
irc9.c
View file

@ -130,6 +130,7 @@ typedef struct Server {
char inbuf[INBUF];
size_t inlen;
Window *windows;
int tree_folded;
Window *reply_win; /* where command replies are printed */
int tls;
int sasl;
@ -365,12 +366,17 @@ static Window *window_get(Server *s, const char *name, Wintype type)
return w;
}
static Window *next_visible_window(Window *w)
{
return w->srv->tree_folded ? NULL : w->next;
}
static void position_tree(int delta, int reveal_current)
{
int height = lines > 5 ? lines - 5 : 1;
int count = 0, current = -1;
for (Server *s = servers; s; s = s->next)
for (Window *w = s->windows; w; w = w->next, count++)
for (Window *w = s->windows; w; w = next_visible_window(w), count++)
if (w == curwin) current = count;
int offset = tree_offset + delta;
@ -388,6 +394,7 @@ static void focus_window(Window *w)
{
if (!w || w == curwin) return;
curwin = w;
if (w->type != W_SERVER) w->srv->tree_folded = 0;
position_tree(0, 1);
curwin->scroll = 0;
curwin->unread = 0;
@ -540,7 +547,7 @@ static void switch_window(int dir)
Window *target = NULL;
if (dir > 0) {
target = curwin->next;
target = next_visible_window(curwin);
if (!target)
for (Server *s = curwin->srv->next; s; s = s->next)
if (s->windows) { target = s->windows; break; }
@ -549,7 +556,7 @@ static void switch_window(int dir)
if (t->windows) { target = t->windows; break; }
} else {
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;
target = w;
}
@ -558,7 +565,8 @@ static void switch_window(int dir)
for (Server *s = servers; s; s = s->next)
if (s->windows) {
Window *last = s->windows;
while (last->next) last = last->next;
for (Window *w = next_visible_window(last); w; w = next_visible_window(w))
last = w;
target = last;
}
}
@ -2508,7 +2516,17 @@ static void handle_key(int c)
}
if (c == '\n' || c == '\r') { submit_input(); return; }
if (c == '\n' || c == '\r') {
if (!*input && curwin && curwin->type == W_SERVER) {
curwin->srv->tree_folded = !curwin->srv->tree_folded;
hist_cur = -1;
position_tree(0, 1);
dirty = 1;
} else {
submit_input();
}
return;
}
if (c == KEY_UP) { history_browse(-1); input_dirty = 1; return; }
if (c == KEY_DOWN) { history_browse(1); input_dirty = 1; return; }
@ -2754,7 +2772,7 @@ static void draw_tree(void)
position_tree(0, 0);
int index = 0;
for (Server *s = servers; s; s = s->next) {
for (Window *w = s->windows; w; w = w->next, index++) {
for (Window *w = s->windows; w; w = next_visible_window(w), index++) {
if (index < tree_offset) continue;
int y = 2 + index - tree_offset;
if (y >= bottom) return;
@ -2763,7 +2781,8 @@ static void draw_tree(void)
terminal_move(y, 1);
fputs(w == curwin ? (terminal_color ? "\033[1;4m" : "\033[7m") : "\033[1m", stdout);
putchar(s->connected ? '*' : ' ');
terminal_text(s->name ? s->name : s->host, treew - 3);
if (s->tree_folded) putchar('+');
terminal_text(s->name ? s->name : s->host, treew - 3 - s->tree_folded);
fputs("\033[0m", stdout);
}
continue;