Use Unicode box borders in the terminal interface
This commit is contained in:
parent
8c240c1c74
commit
c94aa7f9f6
2 changed files with 45 additions and 32 deletions
16
README.md
16
README.md
|
|
@ -134,14 +134,14 @@ Build yours by copying `irc9rc-example` to `irc9rc` next to the binary (or to
|
||||||
|
|
||||||
```
|
```
|
||||||
[irc9] irc.example / #general
|
[irc9] irc.example / #general
|
||||||
/----------------------\/--------------------------------------\
|
┌──────────────────────┐┌───────────────────────────────────────┐
|
||||||
|*irc.example | General discussion
|
│*irc.example ││ General discussion │
|
||||||
| |-#general |---------------------------------------|
|
| |-#general |├───────────────────────────────────────┤
|
||||||
| |-#help(3) |
|
│ |-#help(3) ││ │
|
||||||
| \-alice | [10:21] <alice> hello there
|
│ \-alice ││ [10:21] <alice> hello there │
|
||||||
|*irc.other | [10:22] <bob> hi
|
│*irc.other ││ [10:22] <bob> hi │
|
||||||
| | [10:22] * alice!u@host joined #help
|
│ ││ [10:22] * alice!u@host joined #help │
|
||||||
\----------------------/\--------------------------------------/
|
└──────────────────────┘└───────────────────────────────────────┘
|
||||||
[10:23] (me@irc.example:6697 [TLS])
|
[10:23] (me@irc.example:6697 [TLS])
|
||||||
> your message here
|
> your message here
|
||||||
```
|
```
|
||||||
|
|
|
||||||
61
irc9.c
61
irc9.c
|
|
@ -2621,7 +2621,7 @@ static void handle_key(int c)
|
||||||
static void layout(void)
|
static void layout(void)
|
||||||
{
|
{
|
||||||
treew = cols >= 60 ? TREEW : (cols >= 30 ? 16 : 8);
|
treew = cols >= 60 ? TREEW : (cols >= 30 ? 16 : 8);
|
||||||
if (copy_view) treew = 0;
|
if (copy_view || lines < 6) treew = 0;
|
||||||
else if (treew > cols / 2) treew = cols / 2;
|
else if (treew > cols / 2) treew = cols / 2;
|
||||||
chat_top = lines >= 7 ? 2 : 1;
|
chat_top = lines >= 7 ? 2 : 1;
|
||||||
mainh = lines >= 5 ? lines - 3 - chat_top : 0;
|
mainh = lines >= 5 ? lines - 3 - chat_top : 0;
|
||||||
|
|
@ -2814,26 +2814,35 @@ static long long server_unread_messages(const Server *s)
|
||||||
return unread;
|
return unread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void draw_horizontal_border(int row, int left, int width,
|
||||||
|
const char *opening, const char *closing)
|
||||||
|
{
|
||||||
|
terminal_move(row, left);
|
||||||
|
terminal_accent();
|
||||||
|
if (width > 1) {
|
||||||
|
fputs(opening, stdout);
|
||||||
|
for (int i = 0; i < width - 2; i++) fputs("─", stdout);
|
||||||
|
fputs(closing, stdout);
|
||||||
|
} else if (width == 1) {
|
||||||
|
fputs("─", stdout);
|
||||||
|
}
|
||||||
|
fputs("\033[0m", stdout);
|
||||||
|
}
|
||||||
|
|
||||||
static void draw_tree(void)
|
static void draw_tree(void)
|
||||||
{
|
{
|
||||||
int bottom = lines - 3;
|
int bottom = lines - 3;
|
||||||
if (treew < 2 || lines < 6) return;
|
if (treew < 2 || lines < 6) return;
|
||||||
|
draw_horizontal_border(1, 0, treew, "┌", "┐");
|
||||||
terminal_accent();
|
terminal_accent();
|
||||||
terminal_move(1, 0);
|
|
||||||
putchar('/');
|
|
||||||
terminal_repeat('-', treew - 2);
|
|
||||||
putchar('\\');
|
|
||||||
for (int row = 2; row < bottom; row++) {
|
for (int row = 2; row < bottom; row++) {
|
||||||
terminal_move(row, 0);
|
terminal_move(row, 0);
|
||||||
putchar('|');
|
fputs("│", stdout);
|
||||||
terminal_move(row, treew - 1);
|
terminal_move(row, treew - 1);
|
||||||
putchar('|');
|
fputs("│", stdout);
|
||||||
}
|
}
|
||||||
terminal_move(bottom, 0);
|
|
||||||
putchar('\\');
|
|
||||||
terminal_repeat('-', treew - 2);
|
|
||||||
putchar('/');
|
|
||||||
fputs("\033[0m", stdout);
|
fputs("\033[0m", stdout);
|
||||||
|
draw_horizontal_border(bottom, 0, treew, "└", "┘");
|
||||||
position_tree(0, 0);
|
position_tree(0, 0);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Server *s = servers; s; s = s->next) {
|
for (Server *s = servers; s; s = s->next) {
|
||||||
|
|
@ -2959,18 +2968,21 @@ static void draw_title(void)
|
||||||
fputs("\033[0m", stdout);
|
fputs("\033[0m", stdout);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_pane_divider(int row, int opening, int closing)
|
static void draw_pane_divider(int row, const char *opening, const char *closing)
|
||||||
{
|
{
|
||||||
int left = lines > 5 && treew >= 2 ? treew : 0;
|
int left = treew >= 2 ? treew : 0;
|
||||||
terminal_move(row, left);
|
draw_horizontal_border(row, left, cols - left, opening, closing);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void draw_pane_sides(void)
|
||||||
|
{
|
||||||
|
if (copy_view || cols - treew < 2 || mainh < 1) return;
|
||||||
terminal_accent();
|
terminal_accent();
|
||||||
int width = cols - left;
|
for (int row = chat_top; row < chat_top + mainh; row++) {
|
||||||
if (width > 1) {
|
terminal_move(row, treew);
|
||||||
putchar(opening);
|
fputs("│", stdout);
|
||||||
terminal_repeat('-', width - 2);
|
terminal_move(row, cols - 1);
|
||||||
putchar(closing);
|
fputs("│", stdout);
|
||||||
} else if (width == 1) {
|
|
||||||
putchar('-');
|
|
||||||
}
|
}
|
||||||
fputs("\033[0m", stdout);
|
fputs("\033[0m", stdout);
|
||||||
}
|
}
|
||||||
|
|
@ -2996,7 +3008,7 @@ static int layout_topic(int draw)
|
||||||
if (draw && row < height) draw_irc_text(chat_top + row, left, text, width);
|
if (draw && row < height) draw_irc_text(chat_top + row, left, text, width);
|
||||||
free(text);
|
free(text);
|
||||||
}
|
}
|
||||||
if (draw && divider) draw_pane_divider(chat_top + height, '-', '|');
|
if (draw && divider) draw_pane_divider(chat_top + height, copy_view ? "─" : "├", copy_view ? "─" : "┤");
|
||||||
return height + divider;
|
return height + divider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3104,9 +3116,10 @@ static void redraw(void)
|
||||||
fputs("\033[?25l\033[0m\033[2J", stdout);
|
fputs("\033[?25l\033[0m\033[2J", stdout);
|
||||||
draw_title();
|
draw_title();
|
||||||
draw_tree();
|
draw_tree();
|
||||||
if (chat_top > 1) draw_pane_divider(1, '/', '\\');
|
if (chat_top > 1) draw_pane_divider(1, "┌", "┐");
|
||||||
|
draw_pane_sides();
|
||||||
draw_main();
|
draw_main();
|
||||||
if (lines >= 4) draw_pane_divider(lines - 3, '\\', '/');
|
if (lines >= 4) draw_pane_divider(lines - 3, "└", "┘");
|
||||||
draw_status();
|
draw_status();
|
||||||
draw_input();
|
draw_input();
|
||||||
fputs("\033[?25h", stdout);
|
fputs("\033[?25h", stdout);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue