diff --git a/AUTHORS b/AUTHORS index a4b3bce90..bb85c83c3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -61,7 +61,9 @@ Antonio Palama, DOS port Egmont Koblinger Support of 256 colors - Support of extended mouse clicks beyond 223 + Support of extended mouse clicks beyond 223 column + Support of bracketed paste mode of xterm + (http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Bracketed%20Paste%20Mode) Erwin van Eijk diff --git a/lib/tty/key.c b/lib/tty/key.c index a38cb259e..9db45f402 100644 --- a/lib/tty/key.c +++ b/lib/tty/key.c @@ -12,6 +12,7 @@ Norbert Warmuth, 1997 Denys Vlasenko , 2013 Slava Zanko , 2013 + Egmont Koblinger , 2013 This file is part of the Midnight Commander. @@ -92,6 +93,8 @@ int old_esc_mode = 0; int old_esc_mode_timeout = 1000000; /* settable via env */ int use_8th_bit_as_meta = 0; +gboolean bracketed_pasting_in_progress = FALSE; + /* This table is a mapping between names and the constants we use * We use this to allow users to define alternate definitions for * certain keys that may be missing from the terminal database @@ -275,6 +278,8 @@ typedef int (*ph_pqc_f) (unsigned short, PhCursorInfo_t *); static key_define_t mc_default_keys[] = { {ESC_CHAR, ESC_STR, MCKEY_ESCAPE}, {ESC_CHAR, ESC_STR ESC_STR, MCKEY_NOACTION}, + {MCKEY_BRACKETED_PASTING_START, ESC_STR "[200~", MCKEY_NOACTION}, + {MCKEY_BRACKETED_PASTING_END, ESC_STR "[201~", MCKEY_NOACTION}, {0, NULL, MCKEY_NOACTION}, }; @@ -2145,7 +2150,17 @@ tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block) { /* Mouse event */ xmouse_get_event (event, c == MCKEY_EXTENDED_MOUSE); - return (event->type != 0) ? EV_MOUSE : EV_NONE; + c = (event->type != 0) ? EV_MOUSE : EV_NONE; + } + else if (c == MCKEY_BRACKETED_PASTING_START) + { + bracketed_pasting_in_progress = TRUE; + c = EV_NONE; + } + else if (c == MCKEY_BRACKETED_PASTING_END) + { + bracketed_pasting_in_progress = FALSE; + c = EV_NONE; } return c; @@ -2250,3 +2265,22 @@ application_keypad_mode (void) } /* --------------------------------------------------------------------------------------------- */ + +void +enable_bracketed_paste (void) +{ + printf (ESC_STR "[?2004h"); + fflush (stdout); +} + +/* --------------------------------------------------------------------------------------------- */ + +void +disable_bracketed_paste (void) +{ + printf (ESC_STR "[?2004l"); + fflush (stdout); + bracketed_pasting_in_progress = FALSE; +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/lib/tty/key.h b/lib/tty/key.h index 8365395f0..7b866aced 100644 --- a/lib/tty/key.h +++ b/lib/tty/key.h @@ -36,6 +36,10 @@ /* Return code for the extended mouse sequence */ #define MCKEY_EXTENDED_MOUSE -3 +/* Return code for brackets of bracketed paste mode */ +#define MCKEY_BRACKETED_PASTING_START -4 +#define MCKEY_BRACKETED_PASTING_END -5 + /*** enums ***************************************************************************************/ /*** structures declarations (and typedefs of structures)*****************************************/ @@ -61,6 +65,8 @@ extern int old_esc_mode; extern int use_8th_bit_as_meta; extern int mou_auto_repeat; +extern gboolean bracketed_pasting_in_progress; + /*** declarations of public functions ************************************************************/ gboolean define_sequence (int code, const char *seq, int action); @@ -101,6 +107,10 @@ int get_key_code (int nodelay); void numeric_keypad_mode (void); void application_keypad_mode (void); +/* Bracketed paste mode */ +void enable_bracketed_paste (void); +void disable_bracketed_paste (void); + /*** inline functions ****************************************************************************/ static inline gboolean diff --git a/lib/tty/tty-ncurses.c b/lib/tty/tty-ncurses.c index 9fab86d2a..af544cfe4 100644 --- a/lib/tty/tty-ncurses.c +++ b/lib/tty/tty-ncurses.c @@ -218,6 +218,7 @@ void tty_shutdown (void) { disable_mouse (); + disable_bracketed_paste (); tty_reset_shell_mode (); tty_noraw_mode (); tty_keypad (FALSE); diff --git a/lib/tty/tty-slang.c b/lib/tty/tty-slang.c index c74db6093..14c1aae9f 100644 --- a/lib/tty/tty-slang.c +++ b/lib/tty/tty-slang.c @@ -347,6 +347,7 @@ tty_shutdown (void) char *op_cap; disable_mouse (); + disable_bracketed_paste (); tty_reset_shell_mode (); tty_noraw_mode (); tty_keypad (FALSE); diff --git a/src/execute.c b/src/execute.c index d61fe345b..de3401a1f 100644 --- a/src/execute.c +++ b/src/execute.c @@ -88,6 +88,7 @@ edition_post_exec (void) tty_raw_mode (); channels_up (); enable_mouse (); + enable_bracketed_paste (); if (mc_global.tty.alternate_plus_minus) application_keypad_mode (); } @@ -107,6 +108,7 @@ edition_pre_exec (void) channels_down (); disable_mouse (); + disable_bracketed_paste (); tty_reset_shell_mode (); tty_keypad (FALSE); @@ -455,6 +457,7 @@ toggle_panels (void) channels_down (); disable_mouse (); + disable_bracketed_paste (); if (clear_before_exec) clr_scr (); if (mc_global.tty.alternate_plus_minus) @@ -518,6 +521,7 @@ toggle_panels (void) } enable_mouse (); + enable_bracketed_paste (); channels_up (); if (mc_global.tty.alternate_plus_minus) application_keypad_mode (); diff --git a/src/main.c b/src/main.c index 21588ff4d..8938ad628 100644 --- a/src/main.c +++ b/src/main.c @@ -381,6 +381,10 @@ main (int argc, char *argv[]) w/o Shift button in subshell in the native console */ init_mouse (); + /* Done after do_enter_ca_mode (tty_init) because in VTE bracketed mode is + separate for the normal and alternate screens */ + enable_bracketed_paste (); + /* subshell_prompt is NULL here */ mc_prompt = (geteuid () == 0) ? "# " : "$ ";