Skip to content

Commit 8f35c90

Browse files
egmontkobaborodin
authored andcommitted
Ticket #2661: support enable bracketed paste of xterm.
Signed-off-by: Andrew Borodin <[email protected]>
1 parent d87bef7 commit 8f35c90

File tree

7 files changed

+58
-2
lines changed

7 files changed

+58
-2
lines changed

AUTHORS

+3-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ Antonio Palama, DOS port <[email protected]>
6161

6262
Egmont Koblinger <[email protected]>
6363
Support of 256 colors
64-
Support of extended mouse clicks beyond 223
64+
Support of extended mouse clicks beyond 223 column
65+
Support of bracketed paste mode of xterm
66+
(http://invisible-island.net/xterm/ctlseqs/ctlseqs.html#Bracketed%20Paste%20Mode)
6567

6668
Erwin van Eijk <[email protected]>
6769

lib/tty/key.c

+35-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
Norbert Warmuth, 1997
1313
Denys Vlasenko <[email protected]>, 2013
1414
Slava Zanko <[email protected]>, 2013
15+
Egmont Koblinger <[email protected]>, 2013
1516
1617
This file is part of the Midnight Commander.
1718
@@ -92,6 +93,8 @@ int old_esc_mode = 0;
9293
int old_esc_mode_timeout = 1000000; /* settable via env */
9394
int use_8th_bit_as_meta = 0;
9495

96+
gboolean bracketed_pasting_in_progress = FALSE;
97+
9598
/* This table is a mapping between names and the constants we use
9699
* We use this to allow users to define alternate definitions for
97100
* certain keys that may be missing from the terminal database
@@ -275,6 +278,8 @@ typedef int (*ph_pqc_f) (unsigned short, PhCursorInfo_t *);
275278
static key_define_t mc_default_keys[] = {
276279
{ESC_CHAR, ESC_STR, MCKEY_ESCAPE},
277280
{ESC_CHAR, ESC_STR ESC_STR, MCKEY_NOACTION},
281+
{MCKEY_BRACKETED_PASTING_START, ESC_STR "[200~", MCKEY_NOACTION},
282+
{MCKEY_BRACKETED_PASTING_END, ESC_STR "[201~", MCKEY_NOACTION},
278283
{0, NULL, MCKEY_NOACTION},
279284
};
280285

@@ -2145,7 +2150,17 @@ tty_get_event (struct Gpm_Event *event, gboolean redo_event, gboolean block)
21452150
{
21462151
/* Mouse event */
21472152
xmouse_get_event (event, c == MCKEY_EXTENDED_MOUSE);
2148-
return (event->type != 0) ? EV_MOUSE : EV_NONE;
2153+
c = (event->type != 0) ? EV_MOUSE : EV_NONE;
2154+
}
2155+
else if (c == MCKEY_BRACKETED_PASTING_START)
2156+
{
2157+
bracketed_pasting_in_progress = TRUE;
2158+
c = EV_NONE;
2159+
}
2160+
else if (c == MCKEY_BRACKETED_PASTING_END)
2161+
{
2162+
bracketed_pasting_in_progress = FALSE;
2163+
c = EV_NONE;
21492164
}
21502165

21512166
return c;
@@ -2250,3 +2265,22 @@ application_keypad_mode (void)
22502265
}
22512266

22522267
/* --------------------------------------------------------------------------------------------- */
2268+
2269+
void
2270+
enable_bracketed_paste (void)
2271+
{
2272+
printf (ESC_STR "[?2004h");
2273+
fflush (stdout);
2274+
}
2275+
2276+
/* --------------------------------------------------------------------------------------------- */
2277+
2278+
void
2279+
disable_bracketed_paste (void)
2280+
{
2281+
printf (ESC_STR "[?2004l");
2282+
fflush (stdout);
2283+
bracketed_pasting_in_progress = FALSE;
2284+
}
2285+
2286+
/* --------------------------------------------------------------------------------------------- */

lib/tty/key.h

+10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
/* Return code for the extended mouse sequence */
3737
#define MCKEY_EXTENDED_MOUSE -3
3838

39+
/* Return code for brackets of bracketed paste mode */
40+
#define MCKEY_BRACKETED_PASTING_START -4
41+
#define MCKEY_BRACKETED_PASTING_END -5
42+
3943
/*** enums ***************************************************************************************/
4044

4145
/*** structures declarations (and typedefs of structures)*****************************************/
@@ -61,6 +65,8 @@ extern int old_esc_mode;
6165
extern int use_8th_bit_as_meta;
6266
extern int mou_auto_repeat;
6367

68+
extern gboolean bracketed_pasting_in_progress;
69+
6470
/*** declarations of public functions ************************************************************/
6571

6672
gboolean define_sequence (int code, const char *seq, int action);
@@ -101,6 +107,10 @@ int get_key_code (int nodelay);
101107
void numeric_keypad_mode (void);
102108
void application_keypad_mode (void);
103109

110+
/* Bracketed paste mode */
111+
void enable_bracketed_paste (void);
112+
void disable_bracketed_paste (void);
113+
104114
/*** inline functions ****************************************************************************/
105115

106116
static inline gboolean

lib/tty/tty-ncurses.c

+1
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ void
218218
tty_shutdown (void)
219219
{
220220
disable_mouse ();
221+
disable_bracketed_paste ();
221222
tty_reset_shell_mode ();
222223
tty_noraw_mode ();
223224
tty_keypad (FALSE);

lib/tty/tty-slang.c

+1
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ tty_shutdown (void)
347347
char *op_cap;
348348

349349
disable_mouse ();
350+
disable_bracketed_paste ();
350351
tty_reset_shell_mode ();
351352
tty_noraw_mode ();
352353
tty_keypad (FALSE);

src/execute.c

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ edition_post_exec (void)
8888
tty_raw_mode ();
8989
channels_up ();
9090
enable_mouse ();
91+
enable_bracketed_paste ();
9192
if (mc_global.tty.alternate_plus_minus)
9293
application_keypad_mode ();
9394
}
@@ -107,6 +108,7 @@ edition_pre_exec (void)
107108

108109
channels_down ();
109110
disable_mouse ();
111+
disable_bracketed_paste ();
110112

111113
tty_reset_shell_mode ();
112114
tty_keypad (FALSE);
@@ -455,6 +457,7 @@ toggle_panels (void)
455457

456458
channels_down ();
457459
disable_mouse ();
460+
disable_bracketed_paste ();
458461
if (clear_before_exec)
459462
clr_scr ();
460463
if (mc_global.tty.alternate_plus_minus)
@@ -518,6 +521,7 @@ toggle_panels (void)
518521
}
519522

520523
enable_mouse ();
524+
enable_bracketed_paste ();
521525
channels_up ();
522526
if (mc_global.tty.alternate_plus_minus)
523527
application_keypad_mode ();

src/main.c

+4
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,10 @@ main (int argc, char *argv[])
381381
w/o Shift button in subshell in the native console */
382382
init_mouse ();
383383

384+
/* Done after do_enter_ca_mode (tty_init) because in VTE bracketed mode is
385+
separate for the normal and alternate screens */
386+
enable_bracketed_paste ();
387+
384388
/* subshell_prompt is NULL here */
385389
mc_prompt = (geteuid () == 0) ? "# " : "$ ";
386390

0 commit comments

Comments
 (0)