From 37b1600d9cf7076498760372dcc20f021e4c181a Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 2 Sep 2020 13:46:35 +0000 Subject: Add a -w flag to set- and load-buffer to send to clipboard using OSC 52. GitHub issue 2363. --- tty.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'tty.c') diff --git a/tty.c b/tty.c index 14b770e2..148b1d2d 100644 --- a/tty.c +++ b/tty.c @@ -1896,19 +1896,27 @@ tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx) void tty_cmd_setselection(struct tty *tty, const struct tty_ctx *ctx) { - char *buf; - size_t off; + tty_set_selection(tty, ctx->ptr, ctx->num); +} + +void +tty_set_selection(struct tty *tty, const char *buf, size_t len) +{ + char *encoded; + size_t size; if (!tty_term_has(tty->term, TTYC_MS)) return; + if (~tty->flags & TTY_STARTED) + return; - off = 4 * ((ctx->num + 2) / 3) + 1; /* storage for base64 */ - buf = xmalloc(off); + size = 4 * ((len + 2) / 3) + 1; /* storage for base64 */ + encoded = xmalloc(size); - b64_ntop(ctx->ptr, ctx->num, buf, off); - tty_putcode_ptr2(tty, TTYC_MS, "", buf); + b64_ntop(buf, len, encoded, size); + tty_putcode_ptr2(tty, TTYC_MS, "", encoded); - free(buf); + free(encoded); } void -- cgit From e538bef7576456911cd8cf76d3e4ff2ef97bd671 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 2 Sep 2020 17:19:58 +0000 Subject: Check started flag before looking for capability. --- tty.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tty.c') diff --git a/tty.c b/tty.c index 148b1d2d..30b94e04 100644 --- a/tty.c +++ b/tty.c @@ -1905,10 +1905,10 @@ tty_set_selection(struct tty *tty, const char *buf, size_t len) char *encoded; size_t size; - if (!tty_term_has(tty->term, TTYC_MS)) - return; if (~tty->flags & TTY_STARTED) return; + if (!tty_term_has(tty->term, TTYC_MS)) + return; size = 4 * ((len + 2) / 3) + 1; /* storage for base64 */ encoded = xmalloc(size); -- cgit From c8f3736b07a0ae4c73bd6517ab8c8596d74c1c67 Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 5 Oct 2020 09:53:01 +0000 Subject: Use the setal capability as well as (tmux's) Setulc. --- tty.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'tty.c') diff --git a/tty.c b/tty.c index 30b94e04..bcbccca6 100644 --- a/tty.c +++ b/tty.c @@ -2543,7 +2543,7 @@ tty_colours_fg(struct tty *tty, const struct grid_cell *gc) /* Is this a 24-bit or 256-colour colour? */ if (gc->fg & COLOUR_FLAG_RGB || gc->fg & COLOUR_FLAG_256) { if (tty_try_colour(tty, gc->fg, "38") == 0) - goto save_fg; + goto save; /* Should not get here, already converted in tty_check_fg. */ return; } @@ -2555,13 +2555,13 @@ tty_colours_fg(struct tty *tty, const struct grid_cell *gc) tty_puts(tty, s); } else tty_putcode1(tty, TTYC_SETAF, gc->fg - 90 + 8); - goto save_fg; + goto save; } /* Otherwise set the foreground colour. */ tty_putcode1(tty, TTYC_SETAF, gc->fg); -save_fg: +save: /* Save the new values in the terminal current cell. */ tc->fg = gc->fg; } @@ -2575,7 +2575,7 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc) /* Is this a 24-bit or 256-colour colour? */ if (gc->bg & COLOUR_FLAG_RGB || gc->bg & COLOUR_FLAG_256) { if (tty_try_colour(tty, gc->bg, "48") == 0) - goto save_bg; + goto save; /* Should not get here, already converted in tty_check_bg. */ return; } @@ -2587,13 +2587,13 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc) tty_puts(tty, s); } else tty_putcode1(tty, TTYC_SETAB, gc->bg - 90 + 8); - goto save_bg; + goto save; } /* Otherwise set the background colour. */ tty_putcode1(tty, TTYC_SETAB, gc->bg); -save_bg: +save: /* Save the new values in the terminal current cell. */ tc->bg = gc->bg; } @@ -2605,20 +2605,34 @@ tty_colours_us(struct tty *tty, const struct grid_cell *gc) u_int c; u_char r, g, b; + /* Clear underline colour. */ + if (gc->us == 0) { + tty_putcode(tty, TTYC_OL); + goto save; + } + /* Must be an RGB colour - this should never happen. */ if (~gc->us & COLOUR_FLAG_RGB) return; /* - * Setulc follows the ncurses(3) one argument "direct colour" + * Setulc and setal follows the ncurses(3) one argument "direct colour" * capability format. Calculate the colour value. */ colour_split_rgb(gc->us, &r, &g, &b); c = (65536 * r) + (256 * g) + b; - /* Write the colour. */ - tty_putcode1(tty, TTYC_SETULC, c); + /* + * Write the colour. Only use setal if the RGB flag is set because the + * non-RGB version may be wrong. + */ + if (tty_term_has(tty->term, TTYC_SETULC)) + tty_putcode1(tty, TTYC_SETULC, c); + else if (tty_term_has(tty->term, TTYC_SETAL) && + tty_term_has(tty->term, TTYC_RGB)) + tty_putcode1(tty, TTYC_SETAL, c); +save: /* Save the new values in the terminal current cell. */ tc->us = gc->us; } -- cgit