diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2018-08-29 09:50:33 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2018-08-29 09:50:33 +0000 |
commit | e210cde9dbe8c566767aa48948cbeb623284a2dd (patch) | |
tree | a8ac93c47ee18841c4ff43901fd15c920fb1dc31 /usr.bin/tmux | |
parent | fdb53d4311fb187bc514e33a669683275ad95df7 (diff) |
Keep any text killed in the command prompt with C-w and yank it with
C-y, only use the top buffer if no text has previously been killed. This
and previous change promped by discussion with kn@.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/server-client.c | 3 | ||||
-rw-r--r-- | usr.bin/tmux/status.c | 46 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
3 files changed, 35 insertions, 17 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 6c348902167..bd1bea079b7 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.258 2018/08/22 20:06:14 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.259 2018/08/29 09:50:32 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -302,6 +302,7 @@ server_client_lost(struct client *c) free(msg); } + free(c->prompt_saved); free(c->prompt_string); free(c->prompt_buffer); diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c index b045518c7e1..eaf4211e73b 100644 --- a/usr.bin/tmux/status.c +++ b/usr.bin/tmux/status.c @@ -1,4 +1,4 @@ -/* $OpenBSD: status.c,v 1.180 2018/08/29 08:56:51 nicm Exp $ */ +/* $OpenBSD: status.c,v 1.181 2018/08/29 09:50:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -766,6 +766,9 @@ status_prompt_clear(struct client *c) free(c->prompt_buffer); c->prompt_buffer = NULL; + free(c->prompt_saved); + c->prompt_saved = NULL; + c->tty.flags &= ~(TTY_NOCURSOR|TTY_FREEZE); c->flags |= CLIENT_ALLREDRAWFLAGS; /* was frozen and may have changed */ @@ -1217,6 +1220,12 @@ process_key: } } + free(c->prompt_saved); + c->prompt_saved = xcalloc(sizeof *c->prompt_buffer, + (c->prompt_index - idx) + 1); + memcpy(c->prompt_saved, c->prompt_buffer + idx, + (c->prompt_index - idx) * sizeof *c->prompt_buffer); + memmove(c->prompt_buffer + idx, c->prompt_buffer + c->prompt_index, (size + 1 - c->prompt_index) * @@ -1290,22 +1299,28 @@ process_key: c->prompt_index = utf8_strlen(c->prompt_buffer); goto changed; case '\031': /* C-y */ - if ((pb = paste_get_top(NULL)) == NULL) - break; - bufdata = paste_buffer_data(pb, &bufsize); - for (n = 0; n < bufsize; n++) { - ch = (u_char)bufdata[n]; - if (ch < 32 || ch >= 127) + if (c->prompt_saved != NULL) { + ud = c->prompt_saved; + n = utf8_strlen(c->prompt_saved); + } else { + if ((pb = paste_get_top(NULL)) == NULL) break; + bufdata = paste_buffer_data(pb, &bufsize); + for (n = 0; n < bufsize; n++) { + ch = (u_char)bufdata[n]; + if (ch < 32 || ch >= 127) + break; + } + ud = xreallocarray(NULL, n, sizeof *ud); + for (idx = 0; idx < n; idx++) + utf8_set(&ud[idx], bufdata[idx]); } c->prompt_buffer = xreallocarray(c->prompt_buffer, size + n + 1, sizeof *c->prompt_buffer); if (c->prompt_index == size) { - for (idx = 0; idx < n; idx++) { - ud = &c->prompt_buffer[c->prompt_index + idx]; - utf8_set(ud, bufdata[idx]); - } + memcpy(c->prompt_buffer + c->prompt_index, ud, + n * sizeof *c->prompt_buffer); c->prompt_index += n; c->prompt_buffer[c->prompt_index].size = 0; } else { @@ -1313,12 +1328,13 @@ process_key: c->prompt_buffer + c->prompt_index, (size + 1 - c->prompt_index) * sizeof *c->prompt_buffer); - for (idx = 0; idx < n; idx++) { - ud = &c->prompt_buffer[c->prompt_index + idx]; - utf8_set(ud, bufdata[idx]); - } + memcpy(c->prompt_buffer + c->prompt_index, ud, + n * sizeof *c->prompt_buffer); c->prompt_index += n; } + + if (ud != c->prompt_saved) + free(ud); goto changed; case '\024': /* C-t */ idx = c->prompt_index; diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 4f2dc35acea..02ed0f287f2 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.844 2018/08/23 15:45:05 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.845 2018/08/29 09:50:32 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1358,6 +1358,7 @@ struct client { void *prompt_data; u_int prompt_hindex; enum { PROMPT_ENTRY, PROMPT_COMMAND } prompt_mode; + struct utf8_data *prompt_saved; #define PROMPT_SINGLE 0x1 #define PROMPT_NUMERIC 0x2 |