Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Bracketed Paste Mode #56

Closed
wants to merge 1 commit into from

2 participants

@stfnm

This patch already existed in the "next" branch, so I cherry-picked the commit from there.
I find this feature extremely useful and thought it would be cool to have it already in the master branch and therefore also have it included in the next PuTTYTray release.

simon Patch from Matsui Nag to implement xterm's "bracketed paste mode", in
which text pasted into the terminal is preceded and followed by
special function-key-like escape sequences ESC[200~ and ESC[201~ so
that the application can identify it and treat it specially (e.g.
disabling auto-indent-same-as-previous-line in text editors). Enabled
and disabled by ESC[?2004h and ESC[?2004l, and of course off by
default.

git-svn-id: svn://svn.tartarus.org/sgt/putty@9412 cda61777-01e9-0310-a592-d414129be87e
Signed-off-by: stfn <stfnmd@gmail.com>
7dbe30e
@FauxFaux FauxFaux referenced this pull request from a commit
simon gh-56: bracketed paste mode
Patch from Matsui Nag to implement xterm's "bracketed paste mode", in
which text pasted into the terminal is preceded and followed by
special function-key-like escape sequences ESC[200~ and ESC[201~ so
that the application can identify it and treat it specially (e.g.
disabling auto-indent-same-as-previous-line in text editors). Enabled
and disabled by ESC[?2004h and ESC[?2004l, and of course off by
default.

Signed-off-by: stfn <stfnmd@gmail.com>
a287285
@FauxFaux
Owner

In p0.62-t013.

@FauxFaux FauxFaux closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 19, 2012
  1. @stfnm

    Patch from Matsui Nag to implement xterm's "bracketed paste mode", in

    simon authored stfnm committed
    which text pasted into the terminal is preceded and followed by
    special function-key-like escape sequences ESC[200~ and ESC[201~ so
    that the application can identify it and treat it specially (e.g.
    disabling auto-indent-same-as-previous-line in text editors). Enabled
    and disabled by ESC[?2004h and ESC[?2004l, and of course off by
    default.
    
    git-svn-id: svn://svn.tartarus.org/sgt/putty@9412 cda61777-01e9-0310-a592-d414129be87e
    Signed-off-by: stfn <stfnmd@gmail.com>
This page is out of date. Refresh to see the latest.
Showing with 18 additions and 1 deletion.
  1. +16 −1 terminal.c
  2. +2 −0  terminal.h
View
17 terminal.c
@@ -1230,6 +1230,7 @@ static void power_on(Terminal *term, int clear)
term_print_finish(term);
term->xterm_mouse = 0;
set_raw_mouse_mode(term->frontend, FALSE);
+ term->bracketed_paste = FALSE;
{
int i;
for (i = 0; i < 256; i++)
@@ -2430,6 +2431,9 @@ static void toggle_mode(Terminal *term, int mode, int query, int state)
save_cursor(term, state);
term->disptop = 0;
break;
+ case 2004: /* xterm bracketed paste */
+ term->bracketed_paste = state ? TRUE : FALSE;
+ break;
} else
switch (mode) {
case 4: /* IRM: set insert mode */
@@ -5706,7 +5710,12 @@ void term_do_paste(Terminal *term)
if (term->paste_buffer)
sfree(term->paste_buffer);
term->paste_pos = term->paste_hold = term->paste_len = 0;
- term->paste_buffer = snewn(len, wchar_t);
+ term->paste_buffer = snewn(len + 12, wchar_t);
+
+ if (term->bracketed_paste) {
+ memcpy(term->paste_buffer, L"\033[200~", 6 * sizeof(wchar_t));
+ term->paste_len += 6;
+ }
p = q = data;
while (p < data + len) {
@@ -5730,6 +5739,12 @@ void term_do_paste(Terminal *term)
q = p;
}
+ if (term->bracketed_paste) {
+ memcpy(term->paste_buffer + term->paste_len,
+ L"\033[201~", 6 * sizeof(wchar_t));
+ term->paste_len += 6;
+ }
+
/* Assume a small paste will be OK in one go. */
if (term->paste_len < 256) {
if (term->ldisc)
View
2  terminal.h
@@ -154,6 +154,8 @@ struct terminal_tag {
int xterm_mouse; /* send mouse messages to host */
int mouse_is_down; /* used while tracking mouse buttons */
+ int bracketed_paste;
+
int cset_attr[2];
/*
Something went wrong with that request. Please try again.