mirror of
https://github.com/tmate-io/tmate.git
synced 2024-11-23 08:33:17 +01:00
Add word movement and editing command for command prompt editing, from
Ben Boeckel.
This commit is contained in:
parent
fd25d35868
commit
fc5f8804ec
11
mode-key.c
11
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" },
|
||||
@ -128,6 +132,7 @@ const struct mode_key_entry mode_key_vi_edit[] = {
|
||||
{ '\010' /* C-h */, 0, MODEKEYEDIT_BACKSPACE },
|
||||
{ '\011' /* Tab */, 0, MODEKEYEDIT_COMPLETE },
|
||||
{ '\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 },
|
||||
@ -268,9 +276,12 @@ const struct mode_key_entry mode_key_emacs_edit[] = {
|
||||
{ '\020' /* C-p */, 0, MODEKEYEDIT_HISTORYUP },
|
||||
{ '\024' /* C-t */, 0, MODEKEYEDIT_TRANSPOSECHARS },
|
||||
{ '\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 },
|
||||
|
95
status.c
95
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;
|
||||
const char *wsep;
|
||||
u_char ch;
|
||||
size_t size, n, off, idx;
|
||||
|
||||
@ -1092,6 +1095,98 @@ 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)
|
||||
|
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