diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-11 19:14:57 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-07-11 19:14:57 +0000 |
commit | 2fa427e9046595c8e4f632d5100f5ff089fbacc4 (patch) | |
tree | b3bee8f6fdfc61c57aa38a1fbf411bbce941d2e6 | |
parent | deeaba118282b268d101d4585e48d8782fdf9bca (diff) |
When pasting, translate \n into \r. This matches xterm and putty's behaviour,
and makes emacs happy when pasting into some modes. A new -r (raw) flag to
paste-buffer pastes without the translation.
From Kalle Olavi Niemitalo, thanks!
-rw-r--r-- | usr.bin/tmux/cmd-generic.c | 14 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-paste-buffer.c | 37 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 9 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 3 |
4 files changed, 52 insertions, 11 deletions
diff --git a/usr.bin/tmux/cmd-generic.c b/usr.bin/tmux/cmd-generic.c index 5518588b0e4..1da7ae62009 100644 --- a/usr.bin/tmux/cmd-generic.c +++ b/usr.bin/tmux/cmd-generic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-generic.c,v 1.1 2009/06/01 22:58:49 nicm Exp $ */ +/* $OpenBSD: cmd-generic.c,v 1.2 2009/07/11 19:14:56 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net> @@ -23,9 +23,9 @@ #include "tmux.h" -#define CMD_FLAGS "adDgkuU" +#define CMD_FLAGS "adDgkruU" #define CMD_FLAGMASK (CMD_AFLAG|CMD_DFLAG|CMD_BIGDFLAG|CMD_GFLAG|CMD_KFLAG| \ - CMD_UFLAG|CMD_BIGUFLAG) + CMD_RFLAG|CMD_UFLAG|CMD_BIGUFLAG) int cmd_do_flags(int, int, int *); size_t cmd_print_flags(char *, size_t, size_t, int); @@ -73,6 +73,12 @@ cmd_do_flags(int opt, int iflags, int *oflags) return (0); } return (-1); + case 'r': + if (iflags & CMD_RFLAG) { + (*oflags) |= CMD_RFLAG; + return (0); + } + return (-1); case 'u': if (iflags & CMD_UFLAG) { (*oflags) |= CMD_UFLAG; @@ -107,6 +113,8 @@ cmd_print_flags(char *buf, size_t len, size_t off, int flags) off += xsnprintf(buf + off, len - off, "g"); if (off < len && flags & CMD_KFLAG) off += xsnprintf(buf + off, len - off, "k"); + if (off < len && flags & CMD_RFLAG) + off += xsnprintf(buf + off, len - off, "r"); if (off < len && flags & CMD_UFLAG) off += xsnprintf(buf + off, len - off, "u"); if (off < len && flags & CMD_BIGUFLAG) diff --git a/usr.bin/tmux/cmd-paste-buffer.c b/usr.bin/tmux/cmd-paste-buffer.c index 4147e6a1c25..5801fa45ac5 100644 --- a/usr.bin/tmux/cmd-paste-buffer.c +++ b/usr.bin/tmux/cmd-paste-buffer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-paste-buffer.c,v 1.2 2009/07/02 16:15:43 nicm Exp $ */ +/* $OpenBSD: cmd-paste-buffer.c,v 1.3 2009/07/11 19:14:56 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -27,11 +27,12 @@ */ int cmd_paste_buffer_exec(struct cmd *, struct cmd_ctx *); +void cmd_paste_buffer_lf2cr(struct buffer *, const char *, size_t); const struct cmd_entry cmd_paste_buffer_entry = { "paste-buffer", "pasteb", - "[-d] " CMD_BUFFER_WINDOW_USAGE, - CMD_DFLAG, + "[-dr] " CMD_BUFFER_WINDOW_USAGE, + CMD_DFLAG|CMD_RFLAG, cmd_buffer_init, cmd_buffer_parse, cmd_paste_buffer_exec, @@ -63,8 +64,16 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) } } - if (pb != NULL && *pb->data != '\0') - buffer_write(w->active->out, pb->data, strlen(pb->data)); + if (pb != NULL && *pb->data != '\0') { + /* -r means raw data without LF->CR conversion. */ + if (data->flags & CMD_RFLAG) { + buffer_write( + w->active->out, pb->data, strlen(pb->data)); + } else { + cmd_paste_buffer_lf2cr( + w->active->out, pb->data, strlen(pb->data)); + } + } /* Delete the buffer if -d. */ if (data->flags & CMD_DFLAG) { @@ -76,3 +85,21 @@ cmd_paste_buffer_exec(struct cmd *self, struct cmd_ctx *ctx) return (0); } + +/* Add bytes to a buffer but change every '\n' to '\r'. */ +void +cmd_paste_buffer_lf2cr(struct buffer *b, const char *data, size_t size) +{ + const char *end = data + size; + const char *lf; + + while ((lf = memchr(data, '\n', end - data)) != NULL) { + if (lf != data) + buffer_write(b, data, lf - data); + buffer_write8(b, '\r'); + data = lf + 1; + } + + if (end != data) + buffer_write(b, data, end - data); +} diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index b0362064e3e..ec221b67348 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.23 2009/07/10 19:01:40 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.24 2009/07/11 19:14:56 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -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: July 10 2009 $ +.Dd $Mdocdate: July 11 2009 $ .Dt TMUX 1 .Os .Sh NAME @@ -897,6 +897,11 @@ Insert the contents of a paste buffer into the current window. With .Fl d , also delete the paste buffer from the stack. +When output, any linefeed (LF) characters in the paste buffer are replaced with +carriage returns (CR). +This translation may be disabled with the +.Fl r +flag. .It Xo Ic previous-window .Op Fl a .Op Fl t Ar target-session diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index c75750a2aa2..f9d6babc0b1 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.20 2009/07/10 05:50:54 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.21 2009/07/11 19:14:56 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -858,6 +858,7 @@ struct cmd_entry { #define CMD_UFLAG 0x100 #define CMD_BIGDFLAG 0x200 #define CMD_BIGUFLAG 0x400 +#define CMD_RFLAG 0x800 int flags; |