Restyle the terminal interface with ASCII borders

This commit is contained in:
Johannes Findeisen 2026-11-27 02:42:18 +01:00
commit c3287f08c6
2 changed files with 35 additions and 34 deletions

View file

@ -73,29 +73,26 @@ Build yours by copying `irc9rc-example` to `irc9rc` next to the binary (or to
## Layout ## Layout
``` ```
irc.example / #general [irc9] irc.example / #general
┌────────────────┬──────────────────────────────────────────┐ /----------------------\
│* irc.example │ [10:21] <alice> hello there │ |* irc.example |
│ #general │ [10:22] <bob> hi │ | |-#general |
│ #help(3) │ [10:22] * alice!u@host joined #help │ | |-#help(3) | [10:21] <alice> hello there
│ alice │ │ | \-alice | [10:22] <bob> hi
│* irc.other │ │ |* irc.other | [10:22] * alice!u@host joined #help
│ │ │ \______________________/
├────────────────┴──────────────────────────────────────────┤ ----------------------------------------------------------------
│ me@irc.example #general (3) connected TLS 10:23 │ [10:23] (me@irc.example:6697 [TLS])
│> your message here │ > your message here
└────────────────────────────────────────────────────────────┘
``` ```
The left column is a tree: each server and its windows (channels and private 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 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 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.
The The right pane shows the current window's scrollback with `[HH:MM]` timestamps.
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 Joins, parts and quits include the full hostmask; joins and parts also name the
channel. The status line above the input shows your nick, server, current channel. The status line above the input shows the time, nick, server, port, TLS state, and user modes.
window, member count, connection state (including `TLS`), and the time.
Joining a channel prints its nicklist; `/n` and `/names` print it again. Joining a channel prints its nicklist; `/n` and `/names` print it again.
CTCP `ACTION`, `VERSION`, `PING`, `TIME`, and `USERINFO` are understood; KICK, CTCP `ACTION`, `VERSION`, `PING`, `TIME`, and `USERINFO` are understood; KICK,
MODE, TOPIC, and INVITE events are shown in the relevant window. MODE, TOPIC, and INVITE events are shown in the relevant window.

38
irc9.c
View file

@ -2061,22 +2061,22 @@ static void push_wrapped(char **rows, int *nr, int maxrows, const char *s, int w
static void draw_tree(void) static void draw_tree(void)
{ {
if (treew < 2 || mainh < 2) return; if (treew < 2 || mainh < 2) return;
fputs("\033(0", stdout); if (terminal_color) fputs("\033[36m", stdout);
terminal_move(1, 0); terminal_move(1, 0);
putchar('l'); putchar('/');
terminal_repeat('q', treew - 2); terminal_repeat('-', treew - 2);
putchar('k'); putchar('\\');
for (int row = 2; row < mainh; row++) { for (int row = 2; row < mainh; row++) {
terminal_move(row, 0); terminal_move(row, 0);
putchar('x'); putchar('|');
terminal_move(row, treew - 1); terminal_move(row, treew - 1);
putchar('x'); putchar('|');
} }
terminal_move(mainh, 0); terminal_move(mainh, 0);
putchar('m'); putchar('\\');
terminal_repeat('q', treew - 2); terminal_repeat('_', treew - 2);
putchar('j'); putchar('/');
fputs("\033(B", stdout); fputs("\033[0m", stdout);
int y = 1; int y = 1;
for (Server *s = servers; s; s = s->next) { for (Server *s = servers; s; s = s->next) {
if (y >= mainh - 1) break; if (y >= mainh - 1) break;
@ -2095,9 +2095,12 @@ static void draw_tree(void)
if (w->unread) snprintf(label, sizeof label, "%s(%d)", w->name, w->unread); if (w->unread) snprintf(label, sizeof label, "%s(%d)", w->name, w->unread);
else snprintf(label, sizeof label, "%s", w->name); else snprintf(label, sizeof label, "%s", w->name);
if (treew > 5) { if (treew > 5) {
terminal_move(y, 3); terminal_move(y, 2);
if (terminal_color) fputs("\033[36m", stdout);
fputs(w->next ? "|-" : "\\-", stdout);
fputs("\033[0m", stdout);
if (w == curwin) fputs(terminal_color ? "\033[1;4m" : "\033[7m", stdout); if (w == curwin) fputs(terminal_color ? "\033[1;4m" : "\033[7m", stdout);
terminal_text(label, treew - 5); terminal_text(label, treew - 6);
fputs("\033[0m", stdout); fputs("\033[0m", stdout);
} }
y++; y++;
@ -2172,8 +2175,9 @@ static void draw_title(void)
fputs(terminal_color ? "\033[1m" : "\033[7m", stdout); fputs(terminal_color ? "\033[1m" : "\033[7m", stdout);
terminal_move(0, 0); terminal_move(0, 0);
terminal_repeat(' ', cols); terminal_repeat(' ', cols);
terminal_move(0, 0);
if (curwin) { if (curwin) {
int margin = cols > 24;
terminal_move(0, margin);
char head[MAXLINE]; char head[MAXLINE];
if (curwin->type == W_SERVER) if (curwin->type == W_SERVER)
snprintf(head, sizeof head, "[irc9] (status) %s%s", curwin->srv->host, snprintf(head, sizeof head, "[irc9] (status) %s%s", curwin->srv->host,
@ -2184,7 +2188,7 @@ static void draw_title(void)
else else
snprintf(head, sizeof head, "[irc9] %s / %s%s", curwin->srv->host, curwin->name, snprintf(head, sizeof head, "[irc9] %s / %s%s", curwin->srv->host, curwin->name,
curwin->scroll > 0 ? " [scroll]" : ""); curwin->scroll > 0 ? " [scroll]" : "");
terminal_text(head, cols); terminal_text(head, cols - margin);
} }
fputs("\033[0m", stdout); fputs("\033[0m", stdout);
} }
@ -2226,9 +2230,9 @@ static void draw_input(void)
{ {
if (lines < 4) return; if (lines < 4) return;
terminal_move(lines - 3, 0); terminal_move(lines - 3, 0);
fputs("\033(0", stdout); if (terminal_color) fputs("\033[36m", stdout);
terminal_repeat('q', cols); terminal_repeat('-', cols);
fputs("\033(B", stdout); fputs("\033[0m", stdout);
fputs(terminal_color ? "\033[1m" : "\033[7m", stdout); fputs(terminal_color ? "\033[1m" : "\033[7m", stdout);
terminal_move(lines - 2, 0); terminal_move(lines - 2, 0);
terminal_repeat(' ', cols); terminal_repeat(' ', cols);