1
0
Fork 0
forked from murx/irc9

Compare commits

..

3 commits

2 changed files with 51 additions and 8 deletions

View file

@ -138,6 +138,7 @@ MODE, TOPIC, and INVITE events are shown in the relevant window.
| Key | Action |
| --- | --- |
| `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-n` / `ctrl-p` | next / previous window (tree order, wraps around) |
| `PageUp` / `PageDown` | scroll the current window |
| `ctrl-l` | clear the screen (history stays scrollable) |
@ -145,6 +146,7 @@ MODE, TOPIC, and INVITE events are shown in the relevant window.
| `ctrl-s` | save the current window’s scrollback to a new plain-text file |
| Up / Down | command history |
| Left / Right, Home / End | edit the input line |
| `Del` | delete the character at the cursor |
At the save prompt, type a path and press Enter, or press Esc or Ctrl-G to
cancel. Existing files are protected from overwrites.

57
irc9.c
View file

@ -168,7 +168,8 @@ static long accent_color = -1;
enum {
KEY_UP = 256, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
KEY_HOME, KEY_END, KEY_PPAGE, KEY_NPAGE
KEY_WORD_LEFT, KEY_WORD_RIGHT,
KEY_HOME, KEY_END, KEY_PPAGE, KEY_NPAGE, KEY_DELETE
};
#ifdef USE_OPENSSL
@ -2039,6 +2040,8 @@ static void save_scrollback(Window *w, const char *path)
else appendf(w, "* saved scrollback to %s", path);
}
static size_t terminal_character(const char *s, size_t available, int *width);
static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
{
if (c == 127 || c == 8) {
@ -2051,8 +2054,32 @@ static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
input_dirty = 1;
return;
}
if (c == KEY_DELETE) {
if (*pos < *len) {
int width;
size_t remaining = (size_t)(*len - *pos);
size_t bytes = terminal_character(text + *pos, remaining, &width);
if (!bytes) bytes = 1;
memmove(text + *pos, text + *pos + bytes, remaining - bytes + 1);
*len -= (int)bytes;
input_dirty = 1;
}
return;
}
if (c == KEY_LEFT) { if (*pos > 0) (*pos)--; input_dirty = 1; return; }
if (c == KEY_RIGHT) { if (*pos < *len) (*pos)++; input_dirty = 1; return; }
if (c == KEY_WORD_LEFT) {
while (*pos > 0 && isspace((unsigned char)text[*pos - 1])) --*pos;
while (*pos > 0 && !isspace((unsigned char)text[*pos - 1])) --*pos;
input_dirty = 1;
return;
}
if (c == KEY_WORD_RIGHT) {
while (*pos < *len && !isspace((unsigned char)text[*pos])) ++*pos;
while (*pos < *len && isspace((unsigned char)text[*pos])) ++*pos;
input_dirty = 1;
return;
}
if (c == KEY_HOME) { *pos = 0; input_dirty = 1; return; }
if (c == KEY_END) { *pos = *len; input_dirty = 1; return; }
if (((c >= 32 && c < 127) || (c >= 0x80 && c < 0x100)) &&
@ -2447,7 +2474,7 @@ static void draw_title(void)
fputs("\033[0m", stdout);
}
/* Use the same topic height for drawing and paging the chat pane. */
/* Include the topic divider when calculating the chat pane height. */
static int layout_topic(int draw)
{
int width = cols - treew - (copy_view ? 0 : 2);
@ -2461,14 +2488,22 @@ static int layout_topic(int draw)
int count = 0;
push_wrapped(rows, &count, MAXWRAPROWS, topic, width);
int limit = mainh > 1 ? mainh - 1 : 1;
int divider = mainh >= 3;
int limit = mainh > 1 ? mainh - 1 - divider : 1;
int left = treew + (copy_view ? 0 : 1);
int height = count < limit ? count : limit;
for (int row = 0; row < count; row++) {
char *text = rows[count - 1 - row];
if (draw && row < height) draw_irc_text(row + 1, treew + (copy_view ? 0 : 1), text, width);
if (draw && row < height) draw_irc_text(row + 1, left, text, width);
free(text);
}
return height;
if (draw && divider) {
terminal_move(height + 1, left);
terminal_accent();
terminal_repeat('-', width);
fputs("\033[0m", stdout);
}
return height + divider;
}
static void draw_main(void)
@ -2624,7 +2659,7 @@ static void terminal_start(void)
/* Decode both normal and application cursor keys, including split reads. */
static void terminal_read_keys(void)
{
static int state, number, parameters;
static int state, number, parameters, modifier;
static struct timespec last_escape;
struct timespec now = {0};
clock_gettime(CLOCK_MONOTONIC, &now);
@ -2647,15 +2682,19 @@ static void terminal_read_keys(void)
if (c == '[' || c == 'O') {
state = c;
number = parameters = 0;
modifier = -1;
continue;
}
state = 0;
} else if (state) {
if (c >= '0' && c <= '9') {
if (!parameters && number < 100) number = number * 10 + c - '0';
else if (modifier >= 0 && modifier < 100)
modifier = modifier * 10 + c - '0';
continue;
}
if (c >= 0x20 && c <= 0x3f) {
modifier = (!parameters && c == ';') ? 0 : -1;
parameters = 1;
continue;
}
@ -2670,16 +2709,18 @@ static void terminal_read_keys(void)
continue;
}
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 'C': c = KEY_RIGHT; break;
case 'D': c = KEY_LEFT; 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;
case 'F': c = KEY_END; break;
case '~':
switch (number) {
case 1: case 7: c = KEY_HOME; break;
case 3: c = KEY_DELETE; break;
case 4: case 8: c = KEY_END; break;
case 5: c = KEY_PPAGE; break;
case 6: c = KEY_NPAGE; break;