summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2016-10-12 13:03:28 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2016-10-12 13:03:28 +0000
commit037da74cc00781c7c7f815e9914b096cf59701c5 (patch)
tree425d0d3c2d3053460498808e712926ae14f94a99
parentf703d9bfe498b762e723e7bcb8e23a4962484401 (diff)
The repeat prompt in both emacs and vi (and the old one in tmux) doesn't
support line editing and instead executes a command as soon as a non-number key is pressed. Add a -N flag to command-prompt for the same in copy mode. Reported by Theo Buehler.
-rw-r--r--usr.bin/tmux/cmd-command-prompt.c8
-rw-r--r--usr.bin/tmux/key-bindings.c40
-rw-r--r--usr.bin/tmux/server-client.c9
-rw-r--r--usr.bin/tmux/status.c78
-rw-r--r--usr.bin/tmux/tmux.18
-rw-r--r--usr.bin/tmux/tmux.h5
6 files changed, 84 insertions, 64 deletions
diff --git a/usr.bin/tmux/cmd-command-prompt.c b/usr.bin/tmux/cmd-command-prompt.c
index 4b6ae959650..e5ed4d9bc85 100644
--- a/usr.bin/tmux/cmd-command-prompt.c
+++ b/usr.bin/tmux/cmd-command-prompt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmd-command-prompt.c,v 1.35 2016/10/11 07:23:34 nicm Exp $ */
+/* $OpenBSD: cmd-command-prompt.c,v 1.36 2016/10/12 13:03:27 nicm Exp $ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -38,8 +38,8 @@ const struct cmd_entry cmd_command_prompt_entry = {
.name = "command-prompt",
.alias = NULL,
- .args = { "1I:p:t:", 0, 1 },
- .usage = "[-1] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
+ .args = { "1I:Np:t:", 0, 1 },
+ .usage = "[-1N] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE " "
"[template]",
.tflag = CMD_CLIENT,
@@ -112,6 +112,8 @@ cmd_command_prompt_exec(struct cmd *self, struct cmd_q *cmdq)
flags = 0;
if (args_has(args, '1'))
flags |= PROMPT_SINGLE;
+ else if (args_has(args, 'N'))
+ flags |= PROMPT_NUMERIC;
status_prompt_set(c, prompt, input, cmd_command_prompt_callback,
cmd_command_prompt_free, cdata, flags);
free(prompt);
diff --git a/usr.bin/tmux/key-bindings.c b/usr.bin/tmux/key-bindings.c
index 8660fcc86fc..7ef7a5b8a54 100644
--- a/usr.bin/tmux/key-bindings.c
+++ b/usr.bin/tmux/key-bindings.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: key-bindings.c,v 1.59 2016/10/11 09:30:36 nicm Exp $ */
+/* $OpenBSD: key-bindings.c,v 1.60 2016/10/12 13:03:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -271,15 +271,15 @@ key_bindings_init(void)
"bind -Tcopy-mode Down send -X cursor-down",
"bind -Tcopy-mode Left send -X cursor-left",
"bind -Tcopy-mode Right send -X cursor-right",
- "bind -Tcopy-mode M-1 command-prompt -p'repeat' -I1 \"send -N '%%'\"",
- "bind -Tcopy-mode M-2 command-prompt -p'repeat' -I2 \"send -N '%%'\"",
- "bind -Tcopy-mode M-3 command-prompt -p'repeat' -I3 \"send -N '%%'\"",
- "bind -Tcopy-mode M-4 command-prompt -p'repeat' -I4 \"send -N '%%'\"",
- "bind -Tcopy-mode M-5 command-prompt -p'repeat' -I5 \"send -N '%%'\"",
- "bind -Tcopy-mode M-6 command-prompt -p'repeat' -I6 \"send -N '%%'\"",
- "bind -Tcopy-mode M-7 command-prompt -p'repeat' -I7 \"send -N '%%'\"",
- "bind -Tcopy-mode M-8 command-prompt -p'repeat' -I8 \"send -N '%%'\"",
- "bind -Tcopy-mode M-9 command-prompt -p'repeat' -I9 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-1 command-prompt -Np'repeat' -I1 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-2 command-prompt -Np'repeat' -I2 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-3 command-prompt -Np'repeat' -I3 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-4 command-prompt -Np'repeat' -I4 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-5 command-prompt -Np'repeat' -I5 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-6 command-prompt -Np'repeat' -I6 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-7 command-prompt -Np'repeat' -I7 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-8 command-prompt -Np'repeat' -I8 \"send -N '%%'\"",
+ "bind -Tcopy-mode M-9 command-prompt -Np'repeat' -I9 \"send -N '%%'\"",
"bind -Tcopy-mode M-< send -X history-top",
"bind -Tcopy-mode M-> send -X history-bottom",
"bind -Tcopy-mode M-R send -X top-line",
@@ -313,17 +313,17 @@ key_bindings_init(void)
"bind -Tcopy-mode-vi , send -X jump-reverse",
"bind -Tcopy-mode-vi / command-prompt -p'search down' \"send -X search-forward '%%'\"",
"bind -Tcopy-mode-vi 0 send -X start-of-line",
- "bind -Tcopy-mode-vi 1 command-prompt -p'repeat' -I1 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 2 command-prompt -p'repeat' -I2 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 3 command-prompt -p'repeat' -I3 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 4 command-prompt -p'repeat' -I4 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 5 command-prompt -p'repeat' -I5 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 6 command-prompt -p'repeat' -I6 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 7 command-prompt -p'repeat' -I7 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 8 command-prompt -p'repeat' -I8 \"send -N '%%'\"",
- "bind -Tcopy-mode-vi 9 command-prompt -p'repeat' -I9 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 1 command-prompt -Np'repeat' -I1 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 2 command-prompt -Np'repeat' -I2 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 3 command-prompt -Np'repeat' -I3 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 4 command-prompt -Np'repeat' -I4 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 5 command-prompt -Np'repeat' -I5 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 6 command-prompt -Np'repeat' -I6 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 7 command-prompt -Np'repeat' -I7 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 8 command-prompt -Np'repeat' -I8 \"send -N '%%'\"",
+ "bind -Tcopy-mode-vi 9 command-prompt -Np'repeat' -I9 \"send -N '%%'\"",
"bind -Tcopy-mode-vi : command-prompt -p'goto line' \"send -X goto-line '%%'\"",
- "bind -Tcopy-mode-vi \\; send -X jump-again"
+ "bind -Tcopy-mode-vi \\; send -X jump-again",
"bind -Tcopy-mode-vi ? command-prompt -p'search up' \"send -X search-backward '%%'\"",
"bind -Tcopy-mode-vi A send -X append-selection-and-cancel",
"bind -Tcopy-mode-vi B send -X previous-space",
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c
index 4394b90c36b..149fba0e2d3 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.192 2016/10/11 09:30:36 nicm Exp $ */
+/* $OpenBSD: server-client.c,v 1.193 2016/10/12 13:03:27 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -727,9 +727,10 @@ server_client_handle_key(struct client *c, key_code key)
server_clear_identify(c, NULL);
}
if (c->prompt_string != NULL) {
- if (!(c->flags & CLIENT_READONLY))
- status_prompt_key(c, key);
- return;
+ if (c->flags & CLIENT_READONLY)
+ return;
+ if (status_prompt_key(c, key) == 0)
+ return;
}
/* Check for mouse keys. */
diff --git a/usr.bin/tmux/status.c b/usr.bin/tmux/status.c
index e927907d2c4..494f0e40d9e 100644
--- a/usr.bin/tmux/status.c
+++ b/usr.bin/tmux/status.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: status.c,v 1.153 2016/10/11 07:23:34 nicm Exp $ */
+/* $OpenBSD: status.c,v 1.154 2016/10/12 13:03:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -855,7 +855,7 @@ status_prompt_space(const struct utf8_data *ud)
}
/* Handle keys in prompt. */
-void
+int
status_prompt_key(struct client *c, key_code key)
{
struct options *oo = c->session->options;
@@ -867,6 +867,17 @@ status_prompt_key(struct client *c, key_code key)
struct utf8_data tmp, *first, *last, *ud;
size = utf8_strlen(c->prompt_buffer);
+
+ if (c->prompt_flags & PROMPT_NUMERIC) {
+ if (key >= '0' && key <= '9')
+ goto append_key;
+ s = utf8_tocstr(c->prompt_buffer);
+ c->prompt_callbackfn(c->prompt_data, s);
+ status_prompt_clear(c);
+ free(s);
+ return (1);
+ }
+
switch (mode_key_lookup(&c->prompt_mdata, key)) {
case MODEKEYEDIT_CURSORLEFT:
if (c->prompt_index > 0) {
@@ -1185,41 +1196,44 @@ status_prompt_key(struct client *c, key_code key)
status_prompt_clear(c);
break;
case MODEKEY_OTHER:
- if (key <= 0x1f || key >= KEYC_BASE)
- break;
- if (utf8_split(key, &tmp) != UTF8_DONE)
- break;
+ break;
+ default:
+ return (0);
+ }
- c->prompt_buffer = xreallocarray(c->prompt_buffer, size + 2,
- sizeof *c->prompt_buffer);
+append_key:
+ if (key <= 0x1f || key >= KEYC_BASE)
+ return (0);
+ if (utf8_split(key, &tmp) != UTF8_DONE)
+ return (0);
- if (c->prompt_index == size) {
- utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp);
- c->prompt_index++;
- c->prompt_buffer[c->prompt_index].size = 0;
- } else {
- memmove(c->prompt_buffer + c->prompt_index + 1,
- c->prompt_buffer + c->prompt_index,
- (size + 1 - c->prompt_index) *
- sizeof *c->prompt_buffer);
- utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp);
- c->prompt_index++;
- }
+ c->prompt_buffer = xreallocarray(c->prompt_buffer, size + 2,
+ sizeof *c->prompt_buffer);
- if (c->prompt_flags & PROMPT_SINGLE) {
- s = utf8_tocstr(c->prompt_buffer);
- if (strlen(s) != 1)
- status_prompt_clear(c);
- else if (c->prompt_callbackfn(c->prompt_data, s) == 0)
- status_prompt_clear(c);
- free(s);
- }
+ if (c->prompt_index == size) {
+ utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp);
+ c->prompt_index++;
+ c->prompt_buffer[c->prompt_index].size = 0;
+ } else {
+ memmove(c->prompt_buffer + c->prompt_index + 1,
+ c->prompt_buffer + c->prompt_index,
+ (size + 1 - c->prompt_index) *
+ sizeof *c->prompt_buffer);
+ utf8_copy(&c->prompt_buffer[c->prompt_index], &tmp);
+ c->prompt_index++;
+ }
- c->flags |= CLIENT_STATUS;
- break;
- default:
- break;
+ if (c->prompt_flags & PROMPT_SINGLE) {
+ s = utf8_tocstr(c->prompt_buffer);
+ if (strlen(s) != 1)
+ status_prompt_clear(c);
+ else if (c->prompt_callbackfn(c->prompt_data, s) == 0)
+ status_prompt_clear(c);
+ free(s);
}
+
+ c->flags |= CLIENT_STATUS;
+ return (0);
}
/* Get previous line from the history. */
diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1
index 3f2392bde61..baa85064f95 100644
--- a/usr.bin/tmux/tmux.1
+++ b/usr.bin/tmux/tmux.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tmux.1,v 1.498 2016/10/11 09:30:36 nicm Exp $
+.\" $OpenBSD: tmux.1,v 1.499 2016/10/12 13:03:27 nicm Exp $
.\"
.\" Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
.\"
@@ -14,7 +14,7 @@
.\" IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
.\" OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: October 11 2016 $
+.Dd $Mdocdate: October 12 2016 $
.Dt TMUX 1
.Os
.Sh NAME
@@ -3748,7 +3748,7 @@ session option.
Commands related to the status line are as follows:
.Bl -tag -width Ds
.It Xo Ic command-prompt
-.Op Fl 1
+.Op Fl 1N
.Op Fl I Ar inputs
.Op Fl p Ar prompts
.Op Fl t Ar target-client
@@ -3802,6 +3802,8 @@ to
.Fl 1
makes the prompt only accept one key press, in this case the resulting input
is a single character.
+.Fl N
+accepts only numbers and exit the prompt on any other key press.
.It Xo Ic confirm-before
.Op Fl p Ar prompt
.Op Fl t Ar target-client
diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h
index f6896aba3d5..057c8f2ac2f 100644
--- a/usr.bin/tmux/tmux.h
+++ b/usr.bin/tmux/tmux.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: tmux.h,v 1.655 2016/10/11 13:45:47 nicm Exp $ */
+/* $OpenBSD: tmux.h,v 1.656 2016/10/12 13:03:27 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1269,6 +1269,7 @@ struct client {
u_int prompt_hindex;
#define PROMPT_SINGLE 0x1
+#define PROMPT_NUMERIC 0x2
int prompt_flags;
struct mode_key_data prompt_mdata;
@@ -1920,7 +1921,7 @@ void status_prompt_set(struct client *, const char *, const char *,
int (*)(void *, const char *), void (*)(void *), void *, int);
void status_prompt_clear(struct client *);
int status_prompt_redraw(struct client *);
-void status_prompt_key(struct client *, key_code);
+int status_prompt_key(struct client *, key_code);
void status_prompt_update(struct client *, const char *, const char *);
void status_prompt_load_history(void);
void status_prompt_save_history(void);