Skip to content

Commit 75d49b6

Browse files
author
Yorhel
committed
Send bracketed paste mode code to stderr + workaround for screen
For some reset the reset code wasn't caught when send to stdout. The workaround for screen was found while looking through the weechat code to figure out why the reset code didn't work.
1 parent 505b387 commit 75d49b6

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/main.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -504,9 +504,7 @@ int main(int argc, char **argv) {
504504
erase();
505505
refresh();
506506
endwin();
507-
508-
// reset bracketed paste mode
509-
printf("\x1b[?2004l"); // http://www.xfree86.org/current/ctlseqs.html#C1%20%288-Bit%29%20Control%20Characters
507+
ui_set_bracketed_paste(0);
510508

511509
printf("Flushing unsaved data to disk...");
512510
fflush(stdout);

src/ui.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,21 @@ void ui_tab_incprio(ui_tab_t *tab, int prio) {
245245
}
246246

247247

248+
// Based on gui_window_set_bracketed_paste_mode() in weechat's gui/curses/gui-curses-window.c
249+
void ui_set_bracketed_paste(int enable) {
250+
char *env = getenv("TMUX");
251+
int tmux = env && *env;
252+
env = getenv("TERM");
253+
int screen = env && (strncmp(env, "screen", 6) == 0) && !tmux;
254+
255+
fprintf(stderr, "%s\033[?2004%c%s",
256+
screen ? "\033P" : "",
257+
enable ? 'h' : 'l',
258+
screen ? "\033\\" : "");
259+
fflush(stderr);
260+
}
261+
262+
248263
void ui_init() {
249264
// init curses
250265
initscr();
@@ -257,9 +272,7 @@ void ui_init() {
257272
// ensure curses is init'd before event-keys defined before events happen
258273
define_key("\x1b[200~", KEY_BRACKETED_PASTE_START);
259274
define_key("\x1b[201~", KEY_BRACKETED_PASTE_END);
260-
261-
const char paste_mode[] = "\x1b[?2004h";
262-
write(STDOUT_FILENO, paste_mode, sizeof(paste_mode)-1);
275+
ui_set_bracketed_paste(1);
263276

264277
// global textinput field
265278
ui_global_textinput = ui_textinput_create(TRUE, cmd_suggest);

0 commit comments

Comments
 (0)