summaryrefslogtreecommitdiffstats
path: root/input.c
diff options
context:
space:
mode:
Diffstat (limited to 'input.c')
-rw-r--r--input.c329
1 files changed, 245 insertions, 84 deletions
diff --git a/input.c b/input.c
index 693b6f3..eb421b2 100644
--- a/input.c
+++ b/input.c
@@ -135,6 +135,7 @@ static void input_set_state(struct input_ctx *,
static void input_reset_cell(struct input_ctx *);
static void input_osc_4(struct input_ctx *, const char *);
+static void input_osc_8(struct input_ctx *, const char *);
static void input_osc_10(struct input_ctx *, const char *);
static void input_osc_11(struct input_ctx *, const char *);
static void input_osc_12(struct input_ctx *, const char *);
@@ -143,6 +144,7 @@ static void input_osc_104(struct input_ctx *, const char *);
static void input_osc_110(struct input_ctx *, const char *);
static void input_osc_111(struct input_ctx *, const char *);
static void input_osc_112(struct input_ctx *, const char *);
+static void input_osc_133(struct input_ctx *, const char *);
/* Transition entry/exit handlers. */
static void input_clear(struct input_ctx *);
@@ -167,6 +169,7 @@ static void input_csi_dispatch_rm(struct input_ctx *);
static void input_csi_dispatch_rm_private(struct input_ctx *);
static void input_csi_dispatch_sm(struct input_ctx *);
static void input_csi_dispatch_sm_private(struct input_ctx *);
+static void input_csi_dispatch_sm_graphics(struct input_ctx *);
static void input_csi_dispatch_winops(struct input_ctx *);
static void input_csi_dispatch_sgr_256(struct input_ctx *, int, u_int *);
static void input_csi_dispatch_sgr_rgb(struct input_ctx *, int, u_int *);
@@ -201,7 +204,7 @@ enum input_esc_type {
INPUT_ESC_SCSG0_ON,
INPUT_ESC_SCSG1_OFF,
INPUT_ESC_SCSG1_ON,
- INPUT_ESC_ST,
+ INPUT_ESC_ST
};
/* Escape command table. */
@@ -257,11 +260,12 @@ enum input_csi_type {
INPUT_CSI_SGR,
INPUT_CSI_SM,
INPUT_CSI_SM_PRIVATE,
+ INPUT_CSI_SM_GRAPHICS,
INPUT_CSI_SU,
INPUT_CSI_TBC,
INPUT_CSI_VPA,
INPUT_CSI_WINOPS,
- INPUT_CSI_XDA,
+ INPUT_CSI_XDA
};
/* Control (CSI) command table. */
@@ -281,6 +285,7 @@ static const struct input_table_entry input_csi_table[] = {
{ 'M', "", INPUT_CSI_DL },
{ 'P', "", INPUT_CSI_DCH },
{ 'S', "", INPUT_CSI_SU },
+ { 'S', "?", INPUT_CSI_SM_GRAPHICS },
{ 'T', "", INPUT_CSI_SD },
{ 'X', "", INPUT_CSI_ECH },
{ 'Z', "", INPUT_CSI_CBT },
@@ -304,7 +309,7 @@ static const struct input_table_entry input_csi_table[] = {
{ 'r', "", INPUT_CSI_DECSTBM },
{ 's', "", INPUT_CSI_SCP },
{ 't', "", INPUT_CSI_WINOPS },
- { 'u', "", INPUT_CSI_RCP },
+ { 'u', "", INPUT_CSI_RCP }
};
/* Input transition. */
@@ -970,6 +975,10 @@ input_parse_buffer(struct window_pane *wp, u_char *buf, size_t len)
window_update_activity(wp->window);
wp->flags |= PANE_CHANGED;
+ /* Flag new input while in a mode. */
+ if (!TAILQ_EMPTY(&wp->modes))
+ wp->flags |= PANE_UNSEENCHANGES;
+
/* NULL wp if there is a mode set as don't want to update the tty. */
if (TAILQ_EMPTY(&wp->modes))
screen_write_start_pane(sctx, wp, &wp->base);
@@ -1085,6 +1094,7 @@ input_reply(struct input_ctx *ictx, const char *fmt, ...)
xvasprintf(&reply, fmt, ap);
va_end(ap);
+ log_debug("%s: %s", __func__, reply);
bufferevent_write(bev, reply, strlen(reply));
free(reply);
}
@@ -1344,8 +1354,8 @@ input_csi_dispatch(struct input_ctx *ictx)
if (ictx->flags & INPUT_DISCARD)
return (0);
- log_debug("%s: '%c' \"%s\" \"%s\"",
- __func__, ictx->ch, ictx->interm_buf, ictx->param_buf);
+ log_debug("%s: '%c' \"%s\" \"%s\"", __func__, ictx->ch,
+ ictx->interm_buf, ictx->param_buf);
if (input_split(ictx) != 0)
return (0);
@@ -1436,7 +1446,11 @@ input_csi_dispatch(struct input_ctx *ictx)
case -1:
break;
case 0:
+#ifdef ENABLE_SIXEL
+ input_reply(ictx, "\033[?1;2;4c");
+#else
input_reply(ictx, "\033[?1;2c");
+#endif
break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
@@ -1588,6 +1602,9 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_SM_PRIVATE:
input_csi_dispatch_sm_private(ictx);
break;
+ case INPUT_CSI_SM_GRAPHICS:
+ input_csi_dispatch_sm_graphics(ictx);
+ break;
case INPUT_CSI_SU:
n = input_get(ictx, 0, 1, 1);
if (n != -1)
@@ -1754,7 +1771,6 @@ static void
input_csi_dispatch_sm_private(struct input_ctx *ictx)
{
struct screen_write_ctx *sctx = &ictx->ctx;
- struct window_pane *wp = ictx->wp;
struct grid_cell *gc = &ictx->cell.cell;
u_int i;
@@ -1796,17 +1812,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
screen_write_mode_set(sctx, MODE_MOUSE_ALL);
break;
case 1004:
- if (sctx->s->mode & MODE_FOCUSON)
- break;
screen_write_mode_set(sctx, MODE_FOCUSON);
- if (wp == NULL)
- break;
- if (!options_get_number(global_options, "focus-events"))
- break;
- if (wp->flags & PANE_FOCUSED)
- bufferevent_write(wp->event, "\033[I", 3);
- else
- bufferevent_write(wp->event, "\033[O", 3);
break;
case 1005:
screen_write_mode_set(sctx, MODE_MOUSE_UTF8);
@@ -1831,6 +1837,26 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
}
}
+/* Handle CSI graphics SM. */
+static void
+input_csi_dispatch_sm_graphics(struct input_ctx *ictx)
+{
+#ifdef ENABLE_SIXEL
+ int n, m, o;
+
+ if (ictx->param_list_len > 3)
+ return;
+ n = input_get(ictx, 0, 0, 0);
+ m = input_get(ictx, 1, 0, 0);
+ o = input_get(ictx, 2, 0, 0);
+
+ if (n == 1 && (m == 1 || m == 2 || m == 4))
+ input_reply(ictx, "\033[?%d;0;%uS", n, SIXEL_COLOUR_REGISTERS);
+ else
+ input_reply(ictx, "\033[?%d;3;%dS", n, o);
+#endif
+}
+
/* Handle CSI window operations. */
static void
input_csi_dispatch_winops(struct input_ctx *ictx)
@@ -1838,9 +1864,13 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
struct screen_write_ctx *sctx = &ictx->ctx;
struct screen *s = sctx->s;
struct window_pane *wp = ictx->wp;
+ struct window *w = NULL;
u_int x = screen_size_x(s), y = screen_size_y(s);
int n, m;
+ if (wp != NULL)
+ w = wp->window;
+
m = 0;
while ((n = input_get(ictx, m, 0, -1)) != -1) {
switch (n) {
@@ -1851,8 +1881,6 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
case 7:
case 11:
case 13:
- case 14:
- case 19:
case 20:
case 21:
case 24:
@@ -1870,6 +1898,30 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
if (input_get(ictx, m, 0, -1) == -1)
return;
break;
+ case 14:
+ if (w == NULL)
+ break;
+ input_reply(ictx, "\033[4;%u;%ut", y * w->ypixel,
+ x * w->xpixel);
+ break;
+ case 15:
+ if (w == NULL)
+ break;
+ input_reply(ictx, "\033[5;%u;%ut", y * w->ypixel,
+ x * w->xpixel);
+ break;
+ case 16:
+ if (w == NULL)
+ break;
+ input_reply(ictx, "\033[6;%u;%ut", w->ypixel,
+ w->xpixel);
+ break;
+ case 18:
+ input_reply(ictx, "\033[8;%u;%ut", y, x);
+ break;
+ case 19:
+ input_reply(ictx, "\033[9;%u;%ut", y, x);
+ break;
case 22:
m++;
switch (input_get(ictx, m, 0, -1)) {
@@ -1892,14 +1944,11 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
if (wp == NULL)
break;
notify_pane("pane-title-changed", wp);
- server_redraw_window_borders(wp->window);
- server_status_window(wp->window);
+ server_redraw_window_borders(w);
+ server_status_window(w);
break;
}
break;
- case 18:
- input_reply(ictx, "\033[8;%u;%ut", x, y);
- break;
default:
log_debug("%s: unknown '%c'", __func__, ictx->ch);
break;
@@ -2070,7 +2119,7 @@ static void
input_csi_dispatch_sgr(struct input_ctx *ictx)
{
struct grid_cell *gc = &ictx->cell.cell;
- u_int i;
+ u_int i, link;
int n;
if (ictx->param_list_len == 0) {
@@ -2102,7 +2151,9 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
switch (n) {
case 0:
+ link = gc->link;
memcpy(gc, &grid_default_cell, sizeof *gc);
+ gc->link = link;
break;
case 1:
gc->attr |= GRID_ATTR_BRIGHT;
@@ -2188,7 +2239,7 @@ input_csi_dispatch_sgr(struct input_ctx *ictx)
gc->attr &= ~GRID_ATTR_OVERLINE;
break;
case 59:
- gc->us = 0;
+ gc->us = 8;
break;
case 90:
case 91:
@@ -2246,17 +2297,38 @@ input_dcs_dispatch(struct input_ctx *ictx)
size_t len = ictx->input_len;
const char prefix[] = "tmux;";
const u_int prefixlen = (sizeof prefix) - 1;
+ long long allow_passthrough = 0;
+#ifdef ENABLE_SIXEL
+ struct window *w;
+ struct sixel_image *si;
+#endif
if (wp == NULL)
return (0);
- if (ictx->flags & INPUT_DISCARD)
+
+ if (ictx->flags & INPUT_DISCARD) {
+ log_debug("%s: %zu bytes (discard)", __func__, len);
return (0);
- if (!options_get_number(ictx->wp->options, "allow-passthrough"))
+ }
+
+#ifdef ENABLE_SIXEL
+ w = wp->window;
+ if (buf[0] == 'q') {
+ si = sixel_parse(buf, len, w->xpixel, w->ypixel);
+ if (si != NULL)
+ screen_write_sixelimage(sctx, si, ictx->cell.cell.bg);
+ }
+#endif
+
+ allow_passthrough = options_get_number(wp->options, "allow-passthrough");
+ if (!allow_passthrough)
return (0);
log_debug("%s: \"%s\"", __func__, buf);
- if (len >= prefixlen && strncmp(buf, prefix, prefixlen) == 0)
- screen_write_rawstring(sctx, buf + prefixlen, len - prefixlen);
+ if (len >= prefixlen && strncmp(buf, prefix, prefixlen) == 0) {
+ screen_write_rawstring(sctx, buf + prefixlen, len - prefixlen,
+ allow_passthrough == 2);
+ }
return (0);
}
@@ -2292,6 +2364,8 @@ input_exit_osc(struct input_ctx *ictx)
option = 0;
while (*p >= '0' && *p <= '9')
option = option * 10 + *p++ - '0';
+ if (*p != ';' && *p != '\0')
+ return;
if (*p == ';')
p++;
@@ -2316,6 +2390,9 @@ input_exit_osc(struct input_ctx *ictx)
}
}
break;
+ case 8:
+ input_osc_8(ictx, p);
+ break;
case 10:
input_osc_10(ictx, p);
break;
@@ -2340,6 +2417,9 @@ input_exit_osc(struct input_ctx *ictx)
case 112:
input_osc_112(ictx, p);
break;
+ case 133:
+ input_osc_133(ictx, p);
+ break;
default:
log_debug("%s: unknown '%u'", __func__, option);
break;
@@ -2456,47 +2536,6 @@ input_top_bit_set(struct input_ctx *ictx)
return (0);
}
-/* Parse colour from OSC. */
-static int
-input_osc_parse_colour(const char *p)
-{
- double c, m, y, k = 0;
- u_int r, g, b;
- size_t len = strlen(p);
- int colour = -1;
- char *copy;
-
- if ((len == 12 && sscanf(p, "rgb:%02x/%02x/%02x", &r, &g, &b) == 3) ||
- (len == 7 && sscanf(p, "#%02x%02x%02x", &r, &g, &b) == 3) ||
- sscanf(p, "%d,%d,%d", &r, &g, &b) == 3)
- colour = colour_join_rgb(r, g, b);
- else if ((len == 18 &&
- sscanf(p, "rgb:%04x/%04x/%04x", &r, &g, &b) == 3) ||
- (len == 13 && sscanf(p, "#%04x%04x%04x", &r, &g, &b) == 3))
- colour = colour_join_rgb(r >> 8, g >> 8, b >> 8);
- else if ((sscanf(p, "cmyk:%lf/%lf/%lf/%lf", &c, &m, &y, &k) == 4 ||
- sscanf(p, "cmy:%lf/%lf/%lf", &c, &m, &y) == 3) &&
- c >= 0 && c <= 1 && m >= 0 && m <= 1 &&
- y >= 0 && y <= 1 && k >= 0 && k <= 1) {
- colour = colour_join_rgb(
- (1 - c) * (1 - k) * 255,
- (1 - m) * (1 - k) * 255,
- (1 - y) * (1 - k) * 255);
- } else {
- while (len != 0 && *p == ' ') {
- p++;
- len--;
- }
- while (len != 0 && p[len - 1] == ' ')
- len--;
- copy = xstrndup(p, len);
- colour = colour_byname(copy);
- free(copy);
- }
- log_debug("%s: %s = %s", __func__, p, colour_tostring(colour));
- return (colour);
-}
-
/* Reply to a colour request. */
static void
input_osc_colour_reply(struct input_ctx *ictx, u_int n, int c)
@@ -2545,7 +2584,7 @@ input_osc_4(struct input_ctx *ictx, const char *p)
input_osc_colour_reply(ictx, 4, c);
continue;
}
- if ((c = input_osc_parse_colour(s)) == -1) {
+ if ((c = colour_parseX11(s)) == -1) {
s = next;
continue;
}
@@ -2560,6 +2599,88 @@ input_osc_4(struct input_ctx *ictx, const char *p)
free(copy);
}
+/* Handle the OSC 8 sequence for embedding hyperlinks. */
+static void
+input_osc_8(struct input_ctx *ictx, const char *p)
+{
+ struct hyperlinks *hl = ictx->ctx.s->hyperlinks;
+ struct grid_cell *gc = &ictx->cell.cell;
+ const char *start, *end, *uri;
+ char *id = NULL;
+
+ for (start = p; (end = strpbrk(start, ":;")) != NULL; start = end + 1) {
+ if (end - start >= 4 && strncmp(start, "id=", 3) == 0) {
+ if (id != NULL)
+ goto bad;
+ id = xstrndup(start + 3, end - start - 3);
+ }
+
+ /* The first ; is the end of parameters and start of the URI. */
+ if (*end == ';')
+ break;
+ }
+ if (end == NULL || *end != ';')
+ goto bad;
+ uri = end + 1;
+ if (*uri == '\0') {
+ gc->link = 0;
+ free(id);
+ return;
+ }
+ gc->link = hyperlinks_put(hl, uri, id);
+ if (id == NULL)
+ log_debug("hyperlink (anonymous) %s = %u", uri, gc->link);
+ else
+ log_debug("hyperlink (id=%s) %s = %u", id, uri, gc->link);
+ free(id);
+ return;
+
+bad:
+ log_debug("bad OSC 8 %s", p);
+ free(id);
+}
+
+/*
+ * Get a client with a foreground for the pane. There isn't much to choose
+ * between them so just use the first.
+ */
+static int
+input_get_fg_client(struct window_pane *wp)
+{
+ struct window *w = wp->window;
+ struct client *loop;
+
+ TAILQ_FOREACH(loop, &clients, entry) {
+ if (loop->flags & CLIENT_UNATTACHEDFLAGS)
+ continue;
+ if (loop->session == NULL || !session_has(loop->session, w))
+ continue;
+ if (loop->tty.fg == -1)
+ continue;
+ return (loop->tty.fg);
+ }
+ return (-1);
+}
+
+/* Get a client with a background for the pane. */
+static int
+input_get_bg_client(struct window_pane *wp)
+{
+ struct window *w = wp->window;
+ struct client *loop;
+
+ TAILQ_FOREACH(loop, &clients, entry) {
+ if (loop->flags & CLIENT_UNATTACHEDFLAGS)
+ continue;
+ if (loop->session == NULL || !session_has(loop->session, w))
+ continue;
+ if (loop->tty.bg == -1)
+ continue;
+ return (loop->tty.bg);
+ }
+ return (-1);
+}
+
/* Handle the OSC 10 sequence for setting and querying foreground colour. */
static void
input_osc_10(struct input_ctx *ictx, const char *p)
@@ -2569,14 +2690,18 @@ input_osc_10(struct input_ctx *ictx, const char *p)
int c;
if (strcmp(p, "?") == 0) {
- if (wp != NULL) {
- tty_default_colours(&defaults, wp);
- input_osc_colour_reply(ictx, 10, defaults.fg);
- }
+ if (wp == NULL)
+ return;
+ tty_default_colours(&defaults, wp);
+ if (COLOUR_DEFAULT(defaults.fg))
+ c = input_get_fg_client(wp);
+ else
+ c = defaults.fg;
+ input_osc_colour_reply(ictx, 10, c);
return;
}
- if ((c = input_osc_parse_colour(p)) == -1) {
+ if ((c = colour_parseX11(p)) == -1) {
log_debug("bad OSC 10: %s", p);
return;
}
@@ -2613,14 +2738,18 @@ input_osc_11(struct input_ctx *ictx, const char *p)
int c;
if (strcmp(p, "?") == 0) {
- if (wp != NULL) {
- tty_default_colours(&defaults, wp);
- input_osc_colour_reply(ictx, 11, defaults.bg);
- }
+ if (wp == NULL)
+ return;
+ tty_default_colours(&defaults, wp);
+ if (COLOUR_DEFAULT(defaults.bg))
+ c = input_get_bg_client(wp);
+ else
+ c = defaults.bg;
+ input_osc_colour_reply(ictx, 11, c);
return;
}
- if ((c = input_osc_parse_colour(p)) == -1) {
+ if ((c = colour_parseX11(p)) == -1) {
log_debug("bad OSC 11: %s", p);
return;
}
@@ -2665,7 +2794,7 @@ input_osc_12(struct input_ctx *ictx, const char *p)
return;
}
- if ((c = input_osc_parse_colour(p)) == -1) {
+ if ((c = colour_parseX11(p)) == -1) {
log_debug("bad OSC 12: %s", p);
return;
}
@@ -2680,6 +2809,27 @@ input_osc_112(struct input_ctx *ictx, const char *p)
screen_set_cursor_colour(ictx->ctx.s, -1);
}
+/* Handle the OSC 133 sequence. */
+static void
+input_osc_133(struct input_ctx *ictx, const char *p)
+{
+ struct grid *gd = ictx->ctx.s->grid;
+ u_int line = ictx->ctx.s->cy + gd->hsize;
+ struct grid_line *gl;
+
+ if (line > gd->hsize + gd->sy - 1)
+ return;
+ gl = grid_get_line(gd, line);
+
+ switch (*p) {
+ case 'A':
+ gl->flags |= GRID_LINE_START_PROMPT;
+ break;
+ case 'C':
+ gl->flags |= GRID_LINE_START_OUTPUT;
+ break;
+ }
+}
/* Handle the OSC 52 sequence for setting the clipboard. */
static void
@@ -2693,6 +2843,9 @@ input_osc_52(struct input_ctx *ictx, const char *p)
int outlen, state;
struct screen_write_ctx ctx;
struct paste_buffer *pb;
+ const char* allow = "cpqs01234567";
+ char flags[sizeof "cpqs01234567"] = "";
+ u_int i, j = 0;
if (wp == NULL)
return;
@@ -2707,6 +2860,12 @@ input_osc_52(struct input_ctx *ictx, const char *p)
return;
log_debug("%s: %s", __func__, end);
+ for (i = 0; p + i != end; i++) {
+ if (strchr(allow, p[i]) != NULL && strchr(flags, p[i]) == NULL)
+ flags[j++] = p[i];
+ }
+ log_debug("%s: %.*s %s", __func__, (int)(end - p - 1), p, flags);
+
if (strcmp(end, "?") == 0) {
if ((pb = paste_get_top(NULL)) != NULL)
buf = paste_buffer_data(pb, &len);
@@ -2728,7 +2887,7 @@ input_osc_52(struct input_ctx *ictx, const char *p)
}
screen_write_start_pane(&ctx, wp, NULL);
- screen_write_setselection(&ctx, out, outlen);
+ screen_write_setselection(&ctx, flags, out, outlen);
screen_write_stop(&ctx);
notify_pane("pane-set-clipboard", wp);
@@ -2777,9 +2936,11 @@ input_reply_clipboard(struct bufferevent *bev, const char *buf, size_t len,
const char *end)
{
char *out = NULL;
- size_t outlen = 0;
+ int outlen = 0;
if (buf != NULL && len != 0) {
+ if (len >= ((size_t)INT_MAX * 3 / 4) - 1)
+ return;
outlen = 4 * ((len + 2) / 3) + 1;
out = xmalloc(outlen);
if ((outlen = b64_ntop(buf, len, out, outlen)) == -1) {