mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-23 00:23:08 +01:00
Add word movement and editing command for command prompt editing, from
Ben Boeckel.
This commit is contained in:
parent
fd25d35868
commit
fc5f8804ec
23
mode-key.c
23
mode-key.c
@ -49,11 +49,15 @@ const struct mode_key_cmdstr mode_key_cmdstr_edit[] = {
|
||||
{ MODEKEYEDIT_DELETE, "delete" },
|
||||
{ MODEKEYEDIT_DELETELINE, "delete-line" },
|
||||
{ MODEKEYEDIT_DELETETOENDOFLINE, "delete-end-of-line" },
|
||||
{ MODEKEYEDIT_DELETEWORD, "delete-word" },
|
||||
{ MODEKEYEDIT_ENDOFLINE, "end-of-line" },
|
||||
{ MODEKEYEDIT_ENTER, "enter" },
|
||||
{ MODEKEYEDIT_HISTORYDOWN, "history-down" },
|
||||
{ MODEKEYEDIT_HISTORYUP, "history-up" },
|
||||
{ MODEKEYEDIT_NEXTWORD, "next-word" },
|
||||
{ MODEKEYEDIT_NEXTWORDEND, "next-word-end" },
|
||||
{ MODEKEYEDIT_PASTE, "paste" },
|
||||
{ MODEKEYEDIT_PREVIOUSWORD, "previous-word" },
|
||||
{ MODEKEYEDIT_STARTOFLINE, "start-of-line" },
|
||||
{ MODEKEYEDIT_SWITCHMODE, "switch-mode" },
|
||||
{ MODEKEYEDIT_SWITCHMODEAPPEND, "switch-mode-append" },
|
||||
@ -127,7 +131,8 @@ const struct mode_key_entry mode_key_vi_edit[] = {
|
||||
{ '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL },
|
||||
{ '\010' /* C-h */, 0, MODEKEYEDIT_BACKSPACE },
|
||||
{ '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE },
|
||||
{ '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
|
||||
{ '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
|
||||
{ '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD },
|
||||
{ '\033' /* Escape */, 0, MODEKEYEDIT_SWITCHMODE },
|
||||
{ '\r', 0, MODEKEYEDIT_ENTER },
|
||||
{ KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE },
|
||||
@ -145,13 +150,16 @@ const struct mode_key_entry mode_key_vi_edit[] = {
|
||||
{ '\r', 1, MODEKEYEDIT_ENTER },
|
||||
{ '^', 1, MODEKEYEDIT_STARTOFLINE },
|
||||
{ 'a', 1, MODEKEYEDIT_SWITCHMODEAPPEND },
|
||||
{ 'b', 1, MODEKEYEDIT_PREVIOUSWORD },
|
||||
{ 'd', 1, MODEKEYEDIT_DELETELINE },
|
||||
{ 'e', 1, MODEKEYEDIT_NEXTWORDEND },
|
||||
{ 'h', 1, MODEKEYEDIT_CURSORLEFT },
|
||||
{ 'i', 1, MODEKEYEDIT_SWITCHMODE },
|
||||
{ 'j', 1, MODEKEYEDIT_HISTORYDOWN },
|
||||
{ 'k', 1, MODEKEYEDIT_HISTORYUP },
|
||||
{ 'l', 1, MODEKEYEDIT_CURSORRIGHT },
|
||||
{ 'p', 1, MODEKEYEDIT_PASTE },
|
||||
{ 'w', 1, MODEKEYEDIT_NEXTWORD },
|
||||
{ KEYC_BSPACE, 1, MODEKEYEDIT_BACKSPACE },
|
||||
{ KEYC_DC, 1, MODEKEYEDIT_DELETE },
|
||||
{ KEYC_DOWN, 1, MODEKEYEDIT_HISTORYDOWN },
|
||||
@ -259,18 +267,21 @@ const struct mode_key_entry mode_key_emacs_edit[] = {
|
||||
{ '\002' /* C-b */, 0, MODEKEYEDIT_CURSORLEFT },
|
||||
{ '\003' /* C-c */, 0, MODEKEYEDIT_CANCEL },
|
||||
{ '\004' /* C-d */, 0, MODEKEYEDIT_DELETE },
|
||||
{ '\005' /* C-e */, 0, MODEKEYEDIT_ENDOFLINE },
|
||||
{ '\005' /* C-e */, 0, MODEKEYEDIT_ENDOFLINE },
|
||||
{ '\006' /* C-f */, 0, MODEKEYEDIT_CURSORRIGHT },
|
||||
{ '\010' /* C-H */, 0, MODEKEYEDIT_BACKSPACE },
|
||||
{ '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE },
|
||||
{ '\013' /* C-k */, 0, MODEKEYEDIT_DELETETOENDOFLINE },
|
||||
{ '\010' /* C-H */, 0, MODEKEYEDIT_BACKSPACE },
|
||||
{ '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE },
|
||||
{ '\013' /* C-k */, 0, MODEKEYEDIT_DELETETOENDOFLINE },
|
||||
{ '\016' /* C-n */, 0, MODEKEYEDIT_HISTORYDOWN },
|
||||
{ '\020' /* C-p */, 0, MODEKEYEDIT_HISTORYUP },
|
||||
{ '\024' /* C-t */, 0, MODEKEYEDIT_TRANSPOSECHARS },
|
||||
{ '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
|
||||
{ '\025' /* C-u */, 0, MODEKEYEDIT_DELETELINE },
|
||||
{ '\027' /* C-w */, 0, MODEKEYEDIT_DELETEWORD },
|
||||
{ '\031' /* C-y */, 0, MODEKEYEDIT_PASTE },
|
||||
{ '\033' /* Escape */, 0, MODEKEYEDIT_CANCEL },
|
||||
{ '\r', 0, MODEKEYEDIT_ENTER },
|
||||
{ 'b' | KEYC_ESCAPE, 0, MODEKEYEDIT_PREVIOUSWORD },
|
||||
{ 'f' | KEYC_ESCAPE, 0, MODEKEYEDIT_NEXTWORDEND },
|
||||
{ 'm' | KEYC_ESCAPE, 0, MODEKEYEDIT_STARTOFLINE },
|
||||
{ KEYC_BSPACE, 0, MODEKEYEDIT_BACKSPACE },
|
||||
{ KEYC_DC, 0, MODEKEYEDIT_DELETE },
|
||||
|
101
status.c
101
status.c
@ -973,9 +973,12 @@ status_prompt_redraw(struct client *c)
|
||||
void
|
||||
status_prompt_key(struct client *c, int key)
|
||||
{
|
||||
struct session *sess = c->session;
|
||||
struct options *oo = &sess->options;
|
||||
struct paste_buffer *pb;
|
||||
char *s, *first, *last, word[64], swapc;
|
||||
const char *histstr;
|
||||
char *s, *first, *last, word[64], swapc;
|
||||
const char *histstr;
|
||||
const char *wsep;
|
||||
u_char ch;
|
||||
size_t size, n, off, idx;
|
||||
|
||||
@ -1092,11 +1095,103 @@ status_prompt_key(struct client *c, int key)
|
||||
c->flags |= CLIENT_STATUS;
|
||||
}
|
||||
break;
|
||||
case MODEKEYEDIT_DELETEWORD:
|
||||
wsep = options_get_string(oo, "word-separators");
|
||||
idx = c->prompt_index;
|
||||
|
||||
/* Find a non-separator. */
|
||||
while (idx != 0) {
|
||||
idx--;
|
||||
if (!strchr(wsep, c->prompt_buffer[idx]))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Find the separator at the beginning of the word. */
|
||||
while (idx != 0) {
|
||||
idx--;
|
||||
if (strchr(wsep, c->prompt_buffer[idx])) {
|
||||
/* Go back to the word. */
|
||||
idx++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
memmove(c->prompt_buffer + idx,
|
||||
c->prompt_buffer + c->prompt_index,
|
||||
size + 1 - c->prompt_index);
|
||||
memset(c->prompt_buffer + size - (c->prompt_index - idx),
|
||||
'\0', c->prompt_index - idx);
|
||||
c->prompt_index = idx;
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
case MODEKEYEDIT_NEXTWORD:
|
||||
wsep = options_get_string(oo, "word-separators");
|
||||
|
||||
/* Find a separator. */
|
||||
while (c->prompt_index != size) {
|
||||
c->prompt_index++;
|
||||
if (strchr(wsep, c->prompt_buffer[c->prompt_index]))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Find the word right after the separation. */
|
||||
while (c->prompt_index != size) {
|
||||
c->prompt_index++;
|
||||
if (!strchr(wsep, c->prompt_buffer[c->prompt_index]))
|
||||
break;
|
||||
}
|
||||
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
case MODEKEYEDIT_NEXTWORDEND:
|
||||
wsep = options_get_string(oo, "word-separators");
|
||||
|
||||
/* Find a word. */
|
||||
while (c->prompt_index != size) {
|
||||
c->prompt_index++;
|
||||
if (!strchr(wsep, c->prompt_buffer[c->prompt_index]))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Find the separator at the end of the word. */
|
||||
while (c->prompt_index != size) {
|
||||
c->prompt_index++;
|
||||
if (strchr(wsep, c->prompt_buffer[c->prompt_index])) {
|
||||
/* Go back to the word. */
|
||||
c->prompt_index--;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
case MODEKEYEDIT_PREVIOUSWORD:
|
||||
wsep = options_get_string(oo, "word-separators");
|
||||
|
||||
/* Find a non-separator. */
|
||||
while (c->prompt_index != 0) {
|
||||
c->prompt_index--;
|
||||
if (!strchr(wsep, c->prompt_buffer[c->prompt_index]))
|
||||
break;
|
||||
}
|
||||
|
||||
/* Find the separator at the beginning of the word. */
|
||||
while (c->prompt_index != 0) {
|
||||
c->prompt_index--;
|
||||
if (strchr(wsep, c->prompt_buffer[c->prompt_index])) {
|
||||
/* Go back to the word. */
|
||||
c->prompt_index++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
c->flags |= CLIENT_STATUS;
|
||||
break;
|
||||
case MODEKEYEDIT_HISTORYUP:
|
||||
histstr = status_prompt_up_history(&c->prompt_hindex);
|
||||
if (histstr == NULL)
|
||||
break;
|
||||
xfree(c->prompt_buffer);
|
||||
xfree(c->prompt_buffer);
|
||||
c->prompt_buffer = xstrdup(histstr);
|
||||
c->prompt_index = strlen(c->prompt_buffer);
|
||||
c->flags |= CLIENT_STATUS;
|
||||
|
4
tmux.h
4
tmux.h
@ -442,11 +442,15 @@ enum mode_key_cmd {
|
||||
MODEKEYEDIT_DELETE,
|
||||
MODEKEYEDIT_DELETELINE,
|
||||
MODEKEYEDIT_DELETETOENDOFLINE,
|
||||
MODEKEYEDIT_DELETEWORD,
|
||||
MODEKEYEDIT_ENDOFLINE,
|
||||
MODEKEYEDIT_ENTER,
|
||||
MODEKEYEDIT_HISTORYDOWN,
|
||||
MODEKEYEDIT_HISTORYUP,
|
||||
MODEKEYEDIT_NEXTWORD,
|
||||
MODEKEYEDIT_NEXTWORDEND,
|
||||
MODEKEYEDIT_PASTE,
|
||||
MODEKEYEDIT_PREVIOUSWORD,
|
||||
MODEKEYEDIT_STARTOFLINE,
|
||||
MODEKEYEDIT_SWITCHMODE,
|
||||
MODEKEYEDIT_SWITCHMODEAPPEND,
|
||||
|
Loading…
Reference in New Issue
Block a user