Add channel tree scrolling and follow window switches
This commit is contained in:
parent
9b5e837e3c
commit
7e57211260
2 changed files with 50 additions and 23 deletions
|
|
@ -144,6 +144,7 @@ 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) |
|
||||
| `PageUp` / `PageDown` | scroll the current window |
|
||||
| `ctrl-l` | clear the screen (history stays scrollable) |
|
||||
|
|
|
|||
72
irc9.c
72
irc9.c
|
|
@ -160,6 +160,7 @@ static int dirty = 1;
|
|||
static int input_dirty;
|
||||
static time_t status_minute;
|
||||
static int cols = 80, lines = 24;
|
||||
static int tree_offset;
|
||||
static int treew = TREEW, mainh = 1, chat_top = 1;
|
||||
static struct termios saved_terminal;
|
||||
static int terminal_active;
|
||||
|
|
@ -170,7 +171,7 @@ static long accent_color = -1;
|
|||
|
||||
enum {
|
||||
KEY_UP = 256, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||
KEY_WORD_LEFT, KEY_WORD_RIGHT,
|
||||
KEY_WORD_LEFT, KEY_WORD_RIGHT, KEY_TREE_UP, KEY_TREE_DOWN,
|
||||
KEY_HOME, KEY_END, KEY_PPAGE, KEY_NPAGE, KEY_DELETE
|
||||
};
|
||||
|
||||
|
|
@ -327,10 +328,30 @@ static Window *window_get(Server *s, const char *name, Wintype type)
|
|||
return w;
|
||||
}
|
||||
|
||||
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++)
|
||||
if (w == curwin) current = count;
|
||||
|
||||
int offset = tree_offset + delta;
|
||||
if (reveal_current && current >= 0) {
|
||||
if (current < offset) offset = current;
|
||||
if (current >= offset + height) offset = current - height + 1;
|
||||
}
|
||||
int limit = count > height ? count - height : 0;
|
||||
if (offset < 0) offset = 0;
|
||||
if (offset > limit) offset = limit;
|
||||
tree_offset = offset;
|
||||
}
|
||||
|
||||
static void focus_window(Window *w)
|
||||
{
|
||||
if (!w || w == curwin) return;
|
||||
curwin = w;
|
||||
position_tree(0, 1);
|
||||
curwin->scroll = 0;
|
||||
curwin->unread = 0;
|
||||
dirty = 1;
|
||||
|
|
@ -503,12 +524,7 @@ static void switch_window(int dir)
|
|||
target = last;
|
||||
}
|
||||
}
|
||||
if (target && target != curwin) {
|
||||
curwin = target;
|
||||
curwin->scroll = 0;
|
||||
curwin->unread = 0;
|
||||
dirty = 1;
|
||||
}
|
||||
focus_window(target);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
|
@ -2068,6 +2084,7 @@ static void do_command(Window *window, char *line)
|
|||
appendf(t, " /voice /devoice /ban /unban /raw /close /wc /clear");
|
||||
appendf(t, " /reconnect /quit /help");
|
||||
appendf(t, "keys: ctrl-n / ctrl-p switch windows, pgup/pgdn scroll, ctrl-l clear screen");
|
||||
appendf(t, " ctrl-up / ctrl-down scroll the channel tree");
|
||||
appendf(t, " ctrl-s save scrollback, ctrl-t toggle copy view");
|
||||
} else {
|
||||
if (window) appendf(window, "* unknown command: /%s", cmd);
|
||||
|
|
@ -2214,6 +2231,13 @@ static void handle_key(int c)
|
|||
|
||||
if (c == KEY_UP) { history_browse(-1); input_dirty = 1; return; }
|
||||
if (c == KEY_DOWN) { history_browse(1); input_dirty = 1; return; }
|
||||
if (c == KEY_TREE_UP || c == KEY_TREE_DOWN) {
|
||||
if (treew >= 2 && lines >= 6) {
|
||||
position_tree(c == KEY_TREE_UP ? -1 : 1, 0);
|
||||
dirty = 1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (c == KEY_PPAGE) {
|
||||
if (curwin) {
|
||||
int height = mainh - layout_topic(0);
|
||||
|
|
@ -2443,20 +2467,23 @@ static void draw_tree(void)
|
|||
terminal_repeat('_', treew - 2);
|
||||
putchar('/');
|
||||
fputs("\033[0m", stdout);
|
||||
int y = 2;
|
||||
position_tree(0, 0);
|
||||
int index = 0;
|
||||
for (Server *s = servers; s; s = s->next) {
|
||||
if (y >= bottom) break;
|
||||
int selected = (serverwin(s) == curwin);
|
||||
if (treew > 3) {
|
||||
terminal_move(y, 1);
|
||||
fputs(selected ? (terminal_color ? "\033[1;4m" : "\033[7m") : "\033[1m", stdout);
|
||||
putchar(s->connected ? '*' : ' ');
|
||||
terminal_text(s->name ? s->name : s->host, treew - 3);
|
||||
fputs("\033[0m", stdout);
|
||||
}
|
||||
y++;
|
||||
for (Window *w = s->windows->next; w; w = w->next) {
|
||||
if (y >= bottom) break;
|
||||
for (Window *w = s->windows; w; w = w->next, index++) {
|
||||
if (index < tree_offset) continue;
|
||||
int y = 2 + index - tree_offset;
|
||||
if (y >= bottom) return;
|
||||
if (w == s->windows) {
|
||||
if (treew > 3) {
|
||||
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);
|
||||
fputs("\033[0m", stdout);
|
||||
}
|
||||
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);
|
||||
|
|
@ -2471,7 +2498,6 @@ static void draw_tree(void)
|
|||
terminal_text(label, treew - 6);
|
||||
fputs("\033[0m", stdout);
|
||||
}
|
||||
y++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -2799,8 +2825,8 @@ static void terminal_read_keys(void)
|
|||
if (sequence == -1) continue;
|
||||
int ctrl_arrow = sequence == '[' && number == 1 && modifier == 5;
|
||||
switch (c) {
|
||||
case 'A': c = KEY_UP; break;
|
||||
case 'B': c = KEY_DOWN; break;
|
||||
case 'A': c = ctrl_arrow ? KEY_TREE_UP : KEY_UP; break;
|
||||
case 'B': c = ctrl_arrow ? KEY_TREE_DOWN : KEY_DOWN; break;
|
||||
case 'C': c = ctrl_arrow ? KEY_WORD_RIGHT : KEY_RIGHT; break;
|
||||
case 'D': c = ctrl_arrow ? KEY_WORD_LEFT : KEY_LEFT; break;
|
||||
case 'H': c = KEY_HOME; break;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue