Support Ctrl-arrow word navigation in input
This commit is contained in:
parent
69535eda41
commit
ef3ae4e03a
2 changed files with 22 additions and 3 deletions
|
|
@ -138,6 +138,7 @@ MODE, TOPIC, and INVITE events are shown in the relevant window.
|
||||||
| Key | Action |
|
| Key | Action |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
| `Tab` | complete a `/` command or a nick; press again to cycle matches (recently completed nicks come first) |
|
| `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) |
|
| `ctrl-n` / `ctrl-p` | next / previous window (tree order, wraps around) |
|
||||||
| `PageUp` / `PageDown` | scroll the current window |
|
| `PageUp` / `PageDown` | scroll the current window |
|
||||||
| `ctrl-l` | clear the screen (history stays scrollable) |
|
| `ctrl-l` | clear the screen (history stays scrollable) |
|
||||||
|
|
|
||||||
24
irc9.c
24
irc9.c
|
|
@ -168,6 +168,7 @@ static long accent_color = -1;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
KEY_UP = 256, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
KEY_UP = 256, KEY_DOWN, KEY_LEFT, KEY_RIGHT,
|
||||||
|
KEY_WORD_LEFT, KEY_WORD_RIGHT,
|
||||||
KEY_HOME, KEY_END, KEY_PPAGE, KEY_NPAGE
|
KEY_HOME, KEY_END, KEY_PPAGE, KEY_NPAGE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -2053,6 +2054,18 @@ static void edit_line(int c, char text[MAXINPUT], int *len, int *pos)
|
||||||
}
|
}
|
||||||
if (c == KEY_LEFT) { if (*pos > 0) (*pos)--; 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_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_HOME) { *pos = 0; input_dirty = 1; return; }
|
||||||
if (c == KEY_END) { *pos = *len; input_dirty = 1; return; }
|
if (c == KEY_END) { *pos = *len; input_dirty = 1; return; }
|
||||||
if (((c >= 32 && c < 127) || (c >= 0x80 && c < 0x100)) &&
|
if (((c >= 32 && c < 127) || (c >= 0x80 && c < 0x100)) &&
|
||||||
|
|
@ -2624,7 +2637,7 @@ static void terminal_start(void)
|
||||||
/* Decode both normal and application cursor keys, including split reads. */
|
/* Decode both normal and application cursor keys, including split reads. */
|
||||||
static void terminal_read_keys(void)
|
static void terminal_read_keys(void)
|
||||||
{
|
{
|
||||||
static int state, number, parameters;
|
static int state, number, parameters, modifier;
|
||||||
static struct timespec last_escape;
|
static struct timespec last_escape;
|
||||||
struct timespec now = {0};
|
struct timespec now = {0};
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
@ -2647,15 +2660,19 @@ static void terminal_read_keys(void)
|
||||||
if (c == '[' || c == 'O') {
|
if (c == '[' || c == 'O') {
|
||||||
state = c;
|
state = c;
|
||||||
number = parameters = 0;
|
number = parameters = 0;
|
||||||
|
modifier = -1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
state = 0;
|
state = 0;
|
||||||
} else if (state) {
|
} else if (state) {
|
||||||
if (c >= '0' && c <= '9') {
|
if (c >= '0' && c <= '9') {
|
||||||
if (!parameters && number < 100) number = number * 10 + c - '0';
|
if (!parameters && number < 100) number = number * 10 + c - '0';
|
||||||
|
else if (modifier >= 0 && modifier < 100)
|
||||||
|
modifier = modifier * 10 + c - '0';
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (c >= 0x20 && c <= 0x3f) {
|
if (c >= 0x20 && c <= 0x3f) {
|
||||||
|
modifier = (!parameters && c == ';') ? 0 : -1;
|
||||||
parameters = 1;
|
parameters = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -2670,11 +2687,12 @@ static void terminal_read_keys(void)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sequence == -1) continue;
|
if (sequence == -1) continue;
|
||||||
|
int ctrl_arrow = sequence == '[' && number == 1 && modifier == 5;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'A': c = KEY_UP; break;
|
case 'A': c = KEY_UP; break;
|
||||||
case 'B': c = KEY_DOWN; break;
|
case 'B': c = KEY_DOWN; break;
|
||||||
case 'C': c = KEY_RIGHT; break;
|
case 'C': c = ctrl_arrow ? KEY_WORD_RIGHT : KEY_RIGHT; break;
|
||||||
case 'D': c = KEY_LEFT; break;
|
case 'D': c = ctrl_arrow ? KEY_WORD_LEFT : KEY_LEFT; break;
|
||||||
case 'H': c = KEY_HOME; break;
|
case 'H': c = KEY_HOME; break;
|
||||||
case 'F': c = KEY_END; break;
|
case 'F': c = KEY_END; break;
|
||||||
case '~':
|
case '~':
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue