Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2019-03-12 20:02:38 +00:00
commit ba4a884d75
3 changed files with 87 additions and 78 deletions

153
input.c
View File

@ -801,16 +801,17 @@ void
input_reset(struct window_pane *wp, int clear) input_reset(struct window_pane *wp, int clear)
{ {
struct input_ctx *ictx = wp->ictx; struct input_ctx *ictx = wp->ictx;
struct screen_write_ctx *sctx = &ictx->ctx;
input_reset_cell(ictx); input_reset_cell(ictx);
if (clear) { if (clear) {
if (TAILQ_EMPTY(&wp->modes)) if (TAILQ_EMPTY(&wp->modes))
screen_write_start(&ictx->ctx, wp, &wp->base); screen_write_start(sctx, wp, &wp->base);
else else
screen_write_start(&ictx->ctx, NULL, &wp->base); screen_write_start(sctx, NULL, &wp->base);
screen_write_reset(&ictx->ctx); screen_write_reset(sctx);
screen_write_stop(&ictx->ctx); screen_write_stop(sctx);
} }
input_clear(ictx); input_clear(ictx);
@ -846,6 +847,7 @@ void
input_parse(struct window_pane *wp) input_parse(struct window_pane *wp)
{ {
struct input_ctx *ictx = wp->ictx; struct input_ctx *ictx = wp->ictx;
struct screen_write_ctx *sctx = &ictx->ctx;
const struct input_transition *itr; const struct input_transition *itr;
struct evbuffer *evb = wp->event->input; struct evbuffer *evb = wp->event->input;
u_char *buf; u_char *buf;
@ -862,9 +864,9 @@ input_parse(struct window_pane *wp)
* update the tty. * update the tty.
*/ */
if (TAILQ_EMPTY(&wp->modes)) if (TAILQ_EMPTY(&wp->modes))
screen_write_start(&ictx->ctx, wp, &wp->base); screen_write_start(sctx, wp, &wp->base);
else else
screen_write_start(&ictx->ctx, NULL, &wp->base); screen_write_start(sctx, NULL, &wp->base);
ictx->wp = wp; ictx->wp = wp;
buf = EVBUFFER_DATA(evb); buf = EVBUFFER_DATA(evb);
@ -900,7 +902,7 @@ input_parse(struct window_pane *wp)
* be the minority. * be the minority.
*/ */
if (itr->handler != input_print) if (itr->handler != input_print)
screen_write_collect_end(&ictx->ctx); screen_write_collect_end(sctx);
/* /*
* Execute the handler, if any. Don't switch state if it * Execute the handler, if any. Don't switch state if it
@ -919,7 +921,7 @@ input_parse(struct window_pane *wp)
} }
/* Close the screen. */ /* Close the screen. */
screen_write_stop(&ictx->ctx); screen_write_stop(sctx);
evbuffer_drain(evb, len); evbuffer_drain(evb, len);
} }
@ -1048,7 +1050,8 @@ input_ground(struct input_ctx *ictx)
static int static int
input_print(struct input_ctx *ictx) input_print(struct input_ctx *ictx)
{ {
int set; struct screen_write_ctx *sctx = &ictx->ctx;
int set;
ictx->utf8started = 0; /* can't be valid UTF-8 */ ictx->utf8started = 0; /* can't be valid UTF-8 */
@ -1059,7 +1062,7 @@ input_print(struct input_ctx *ictx)
ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET; ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET;
utf8_set(&ictx->cell.cell.data, ictx->ch); utf8_set(&ictx->cell.cell.data, ictx->ch);
screen_write_collect_add(&ictx->ctx, &ictx->cell.cell); screen_write_collect_add(sctx, &ictx->cell.cell);
ictx->last = ictx->ch; ictx->last = ictx->ch;
ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET; ictx->cell.cell.attr &= ~GRID_ATTR_CHARSET;
@ -1444,7 +1447,7 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_HPA: case INPUT_CSI_HPA:
n = input_get(ictx, 0, 1, 1); n = input_get(ictx, 0, 1, 1);
if (n != -1) if (n != -1)
screen_write_cursormove(sctx, n - 1, s->cy); screen_write_cursormove(sctx, n - 1, -1);
break; break;
case INPUT_CSI_ICH: case INPUT_CSI_ICH:
n = input_get(ictx, 0, 1, 1); n = input_get(ictx, 0, 1, 1);
@ -1516,7 +1519,7 @@ input_csi_dispatch(struct input_ctx *ictx)
case INPUT_CSI_VPA: case INPUT_CSI_VPA:
n = input_get(ictx, 0, 1, 1); n = input_get(ictx, 0, 1, 1);
if (n != -1) if (n != -1)
screen_write_cursormove(sctx, s->cx, n - 1); screen_write_cursormove(sctx, -1, n - 1);
break; break;
case INPUT_CSI_DECSCUSR: case INPUT_CSI_DECSCUSR:
n = input_get(ictx, 0, 0, 0); n = input_get(ictx, 0, 0, 0);
@ -1533,17 +1536,18 @@ input_csi_dispatch(struct input_ctx *ictx)
static void static void
input_csi_dispatch_rm(struct input_ctx *ictx) input_csi_dispatch_rm(struct input_ctx *ictx)
{ {
u_int i; struct screen_write_ctx *sctx = &ictx->ctx;
u_int i;
for (i = 0; i < ictx->param_list_len; i++) { for (i = 0; i < ictx->param_list_len; i++) {
switch (input_get(ictx, i, 0, -1)) { switch (input_get(ictx, i, 0, -1)) {
case -1: case -1:
break; break;
case 4: /* IRM */ case 4: /* IRM */
screen_write_mode_clear(&ictx->ctx, MODE_INSERT); screen_write_mode_clear(sctx, MODE_INSERT);
break; break;
case 34: case 34:
screen_write_mode_set(&ictx->ctx, MODE_BLINKING); screen_write_mode_set(sctx, MODE_BLINKING);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
@ -1556,6 +1560,7 @@ input_csi_dispatch_rm(struct input_ctx *ictx)
static void static void
input_csi_dispatch_rm_private(struct input_ctx *ictx) input_csi_dispatch_rm_private(struct input_ctx *ictx)
{ {
struct screen_write_ctx *sctx = &ictx->ctx;
struct window_pane *wp = ictx->wp; struct window_pane *wp = ictx->wp;
u_int i; u_int i;
@ -1564,40 +1569,39 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
case -1: case -1:
break; break;
case 1: /* DECCKM */ case 1: /* DECCKM */
screen_write_mode_clear(&ictx->ctx, MODE_KCURSOR); screen_write_mode_clear(sctx, MODE_KCURSOR);
break; break;
case 3: /* DECCOLM */ case 3: /* DECCOLM */
screen_write_cursormove(&ictx->ctx, 0, 0); screen_write_cursormove(sctx, 0, 0);
screen_write_clearscreen(&ictx->ctx, screen_write_clearscreen(sctx, ictx->cell.cell.bg);
ictx->cell.cell.bg);
break; break;
case 6: /* DECOM */ case 6: /* DECOM */
screen_write_mode_clear(&ictx->ctx, MODE_ORIGIN); screen_write_mode_clear(sctx, MODE_ORIGIN);
screen_write_cursormove(&ictx->ctx, 0, 0); screen_write_cursormove(sctx, 0, 0);
break; break;
case 7: /* DECAWM */ case 7: /* DECAWM */
screen_write_mode_clear(&ictx->ctx, MODE_WRAP); screen_write_mode_clear(sctx, MODE_WRAP);
break; break;
case 12: case 12:
screen_write_mode_clear(&ictx->ctx, MODE_BLINKING); screen_write_mode_clear(sctx, MODE_BLINKING);
break; break;
case 25: /* TCEM */ case 25: /* TCEM */
screen_write_mode_clear(&ictx->ctx, MODE_CURSOR); screen_write_mode_clear(sctx, MODE_CURSOR);
break; break;
case 1000: case 1000:
case 1001: case 1001:
case 1002: case 1002:
case 1003: case 1003:
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
break; break;
case 1004: case 1004:
screen_write_mode_clear(&ictx->ctx, MODE_FOCUSON); screen_write_mode_clear(sctx, MODE_FOCUSON);
break; break;
case 1005: case 1005:
screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_UTF8); screen_write_mode_clear(sctx, MODE_MOUSE_UTF8);
break; break;
case 1006: case 1006:
screen_write_mode_clear(&ictx->ctx, MODE_MOUSE_SGR); screen_write_mode_clear(sctx, MODE_MOUSE_SGR);
break; break;
case 47: case 47:
case 1047: case 1047:
@ -1607,7 +1611,7 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
window_pane_alternate_off(wp, &ictx->cell.cell, 1); window_pane_alternate_off(wp, &ictx->cell.cell, 1);
break; break;
case 2004: case 2004:
screen_write_mode_clear(&ictx->ctx, MODE_BRACKETPASTE); screen_write_mode_clear(sctx, MODE_BRACKETPASTE);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
@ -1620,17 +1624,18 @@ input_csi_dispatch_rm_private(struct input_ctx *ictx)
static void static void
input_csi_dispatch_sm(struct input_ctx *ictx) input_csi_dispatch_sm(struct input_ctx *ictx)
{ {
u_int i; struct screen_write_ctx *sctx = &ictx->ctx;
u_int i;
for (i = 0; i < ictx->param_list_len; i++) { for (i = 0; i < ictx->param_list_len; i++) {
switch (input_get(ictx, i, 0, -1)) { switch (input_get(ictx, i, 0, -1)) {
case -1: case -1:
break; break;
case 4: /* IRM */ case 4: /* IRM */
screen_write_mode_set(&ictx->ctx, MODE_INSERT); screen_write_mode_set(sctx, MODE_INSERT);
break; break;
case 34: case 34:
screen_write_mode_clear(&ictx->ctx, MODE_BLINKING); screen_write_mode_clear(sctx, MODE_BLINKING);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
@ -1643,6 +1648,7 @@ input_csi_dispatch_sm(struct input_ctx *ictx)
static void static void
input_csi_dispatch_sm_private(struct input_ctx *ictx) input_csi_dispatch_sm_private(struct input_ctx *ictx)
{ {
struct screen_write_ctx *sctx = &ictx->ctx;
struct window_pane *wp = ictx->wp; struct window_pane *wp = ictx->wp;
u_int i; u_int i;
@ -1651,49 +1657,48 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
case -1: case -1:
break; break;
case 1: /* DECCKM */ case 1: /* DECCKM */
screen_write_mode_set(&ictx->ctx, MODE_KCURSOR); screen_write_mode_set(sctx, MODE_KCURSOR);
break; break;
case 3: /* DECCOLM */ case 3: /* DECCOLM */
screen_write_cursormove(&ictx->ctx, 0, 0); screen_write_cursormove(sctx, 0, 0);
screen_write_clearscreen(&ictx->ctx, screen_write_clearscreen(sctx, ictx->cell.cell.bg);
ictx->cell.cell.bg);
break; break;
case 6: /* DECOM */ case 6: /* DECOM */
screen_write_mode_set(&ictx->ctx, MODE_ORIGIN); screen_write_mode_set(sctx, MODE_ORIGIN);
screen_write_cursormove(&ictx->ctx, 0, 0); screen_write_cursormove(sctx, 0, 0);
break; break;
case 7: /* DECAWM */ case 7: /* DECAWM */
screen_write_mode_set(&ictx->ctx, MODE_WRAP); screen_write_mode_set(sctx, MODE_WRAP);
break; break;
case 12: case 12:
screen_write_mode_set(&ictx->ctx, MODE_BLINKING); screen_write_mode_set(sctx, MODE_BLINKING);
break; break;
case 25: /* TCEM */ case 25: /* TCEM */
screen_write_mode_set(&ictx->ctx, MODE_CURSOR); screen_write_mode_set(sctx, MODE_CURSOR);
break; break;
case 1000: case 1000:
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_STANDARD); screen_write_mode_set(sctx, MODE_MOUSE_STANDARD);
break; break;
case 1002: case 1002:
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_BUTTON); screen_write_mode_set(sctx, MODE_MOUSE_BUTTON);
break; break;
case 1003: case 1003:
screen_write_mode_clear(&ictx->ctx, ALL_MOUSE_MODES); screen_write_mode_clear(sctx, ALL_MOUSE_MODES);
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_ALL); screen_write_mode_set(sctx, MODE_MOUSE_ALL);
break; break;
case 1004: case 1004:
if (ictx->ctx.s->mode & MODE_FOCUSON) if (sctx->s->mode & MODE_FOCUSON)
break; break;
screen_write_mode_set(&ictx->ctx, MODE_FOCUSON); screen_write_mode_set(sctx, MODE_FOCUSON);
wp->flags |= PANE_FOCUSPUSH; /* force update */ wp->flags |= PANE_FOCUSPUSH; /* force update */
break; break;
case 1005: case 1005:
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_UTF8); screen_write_mode_set(sctx, MODE_MOUSE_UTF8);
break; break;
case 1006: case 1006:
screen_write_mode_set(&ictx->ctx, MODE_MOUSE_SGR); screen_write_mode_set(sctx, MODE_MOUSE_SGR);
break; break;
case 47: case 47:
case 1047: case 1047:
@ -1703,7 +1708,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
window_pane_alternate_on(wp, &ictx->cell.cell, 1); window_pane_alternate_on(wp, &ictx->cell.cell, 1);
break; break;
case 2004: case 2004:
screen_write_mode_set(&ictx->ctx, MODE_BRACKETPASTE); screen_write_mode_set(sctx, MODE_BRACKETPASTE);
break; break;
default: default:
log_debug("%s: unknown '%c'", __func__, ictx->ch); log_debug("%s: unknown '%c'", __func__, ictx->ch);
@ -1716,6 +1721,7 @@ input_csi_dispatch_sm_private(struct input_ctx *ictx)
static void static void
input_csi_dispatch_winops(struct input_ctx *ictx) input_csi_dispatch_winops(struct input_ctx *ictx)
{ {
struct screen_write_ctx *sctx = &ictx->ctx;
struct window_pane *wp = ictx->wp; struct window_pane *wp = ictx->wp;
int n, m; int n, m;
@ -1755,7 +1761,7 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
return; return;
case 0: case 0:
case 2: case 2:
screen_push_title(ictx->ctx.s); screen_push_title(sctx->s);
break; break;
} }
break; break;
@ -1766,7 +1772,7 @@ input_csi_dispatch_winops(struct input_ctx *ictx)
return; return;
case 0: case 0:
case 2: case 2:
screen_pop_title(ictx->ctx.s); screen_pop_title(sctx->s);
server_status_window(ictx->wp->window); server_status_window(ictx->wp->window);
break; break;
} }
@ -2089,20 +2095,19 @@ input_enter_dcs(struct input_ctx *ictx)
static int static int
input_dcs_dispatch(struct input_ctx *ictx) input_dcs_dispatch(struct input_ctx *ictx)
{ {
const char prefix[] = "tmux;"; struct screen_write_ctx *sctx = &ictx->ctx;
const u_int prefix_len = (sizeof prefix) - 1; u_char *buf = ictx->input_buf;
size_t len = ictx->input_len;
const char prefix[] = "tmux;";
const u_int prefixlen = (sizeof prefix) - 1;
if (ictx->flags & INPUT_DISCARD) if (ictx->flags & INPUT_DISCARD)
return (0); return (0);
log_debug("%s: \"%s\"", __func__, ictx->input_buf); log_debug("%s: \"%s\"", __func__, buf);
/* Check for tmux prefix. */ if (len >= prefixlen && strncmp(buf, prefix, prefixlen) == 0)
if (ictx->input_len >= prefix_len && screen_write_rawstring(sctx, buf + prefixlen, len - prefixlen);
strncmp(ictx->input_buf, prefix, prefix_len) == 0) {
screen_write_rawstring(&ictx->ctx,
ictx->input_buf + prefix_len, ictx->input_len - prefix_len);
}
return (0); return (0);
} }
@ -2122,8 +2127,9 @@ input_enter_osc(struct input_ctx *ictx)
static void static void
input_exit_osc(struct input_ctx *ictx) input_exit_osc(struct input_ctx *ictx)
{ {
u_char *p = ictx->input_buf; struct screen_write_ctx *sctx = &ictx->ctx;
u_int option; u_char *p = ictx->input_buf;
u_int option;
if (ictx->flags & INPUT_DISCARD) if (ictx->flags & INPUT_DISCARD)
return; return;
@ -2143,7 +2149,7 @@ input_exit_osc(struct input_ctx *ictx)
case 0: case 0:
case 2: case 2:
if (utf8_isvalid(p)) { if (utf8_isvalid(p)) {
screen_set_title(ictx->ctx.s, p); screen_set_title(sctx->s, p);
server_status_window(ictx->wp->window); server_status_window(ictx->wp->window);
} }
break; break;
@ -2158,7 +2164,7 @@ input_exit_osc(struct input_ctx *ictx)
break; break;
case 12: case 12:
if (utf8_isvalid(p) && *p != '?') /* ? is colour request */ if (utf8_isvalid(p) && *p != '?') /* ? is colour request */
screen_set_cursor_colour(ictx->ctx.s, p); screen_set_cursor_colour(sctx->s, p);
break; break;
case 52: case 52:
input_osc_52(ictx, p); input_osc_52(ictx, p);
@ -2168,7 +2174,7 @@ input_exit_osc(struct input_ctx *ictx)
break; break;
case 112: case 112:
if (*p == '\0') /* no arguments allowed */ if (*p == '\0') /* no arguments allowed */
screen_set_cursor_colour(ictx->ctx.s, ""); screen_set_cursor_colour(sctx->s, "");
break; break;
default: default:
log_debug("%s: unknown '%u'", __func__, option); log_debug("%s: unknown '%u'", __func__, option);
@ -2191,13 +2197,15 @@ input_enter_apc(struct input_ctx *ictx)
static void static void
input_exit_apc(struct input_ctx *ictx) input_exit_apc(struct input_ctx *ictx)
{ {
struct screen_write_ctx *sctx = &ictx->ctx;
if (ictx->flags & INPUT_DISCARD) if (ictx->flags & INPUT_DISCARD)
return; return;
log_debug("%s: \"%s\"", __func__, ictx->input_buf); log_debug("%s: \"%s\"", __func__, ictx->input_buf);
if (!utf8_isvalid(ictx->input_buf)) if (!utf8_isvalid(ictx->input_buf))
return; return;
screen_set_title(ictx->ctx.s, ictx->input_buf); screen_set_title(sctx->s, ictx->input_buf);
server_status_window(ictx->wp->window); server_status_window(ictx->wp->window);
} }
@ -2233,6 +2241,7 @@ input_exit_rename(struct input_ctx *ictx)
static int static int
input_top_bit_set(struct input_ctx *ictx) input_top_bit_set(struct input_ctx *ictx)
{ {
struct screen_write_ctx *sctx = &ictx->ctx;
struct utf8_data *ud = &ictx->utf8data; struct utf8_data *ud = &ictx->utf8data;
ictx->last = -1; ictx->last = -1;
@ -2259,7 +2268,7 @@ input_top_bit_set(struct input_ctx *ictx)
(int)ud->size, ud->data, ud->width); (int)ud->size, ud->data, ud->width);
utf8_copy(&ictx->cell.cell.data, ud); utf8_copy(&ictx->cell.cell.data, ud);
screen_write_collect_add(&ictx->ctx, &ictx->cell.cell); screen_write_collect_add(sctx, &ictx->cell.cell);
return (0); return (0);
} }
@ -2270,7 +2279,7 @@ input_osc_4(struct input_ctx *ictx, const char *p)
{ {
struct window_pane *wp = ictx->wp; struct window_pane *wp = ictx->wp;
char *copy, *s, *next = NULL; char *copy, *s, *next = NULL;
long idx; long idx;
u_int r, g, b; u_int r, g, b;
copy = s = xstrdup(p); copy = s = xstrdup(p);
@ -2410,7 +2419,7 @@ input_osc_104(struct input_ctx *ictx, const char *p)
{ {
struct window_pane *wp = ictx->wp; struct window_pane *wp = ictx->wp;
char *copy, *s; char *copy, *s;
long idx; long idx;
if (*p == '\0') { if (*p == '\0') {
window_pane_reset_palette(wp); window_pane_reset_palette(wp);

View File

@ -1034,20 +1034,20 @@ screen_write_clearstartofline(struct screen_write_ctx *ctx, u_int bg)
/* Move cursor to px,py. */ /* Move cursor to px,py. */
void void
screen_write_cursormove(struct screen_write_ctx *ctx, u_int px, u_int py) screen_write_cursormove(struct screen_write_ctx *ctx, int px, int py)
{ {
struct screen *s = ctx->s; struct screen *s = ctx->s;
if (s->mode & MODE_ORIGIN) { if (py != -1 && (s->mode & MODE_ORIGIN)) {
if (py > s->rlower - s->rupper) if ((u_int)py > s->rlower - s->rupper)
py = s->rlower; py = s->rlower;
else else
py += s->rupper; py += s->rupper;
} }
if (px > screen_size_x(s) - 1) if (px != -1 && (u_int)px > screen_size_x(s) - 1)
px = screen_size_x(s) - 1; px = screen_size_x(s) - 1;
if (py > screen_size_y(s) - 1) if (py != -1 && (u_int)py > screen_size_y(s) - 1)
py = screen_size_y(s) - 1; py = screen_size_y(s) - 1;
screen_write_set_cursor(ctx, px, py); screen_write_set_cursor(ctx, px, py);

2
tmux.h
View File

@ -2102,7 +2102,7 @@ void screen_write_deleteline(struct screen_write_ctx *, u_int, u_int);
void screen_write_clearline(struct screen_write_ctx *, u_int); void screen_write_clearline(struct screen_write_ctx *, u_int);
void screen_write_clearendofline(struct screen_write_ctx *, u_int); void screen_write_clearendofline(struct screen_write_ctx *, u_int);
void screen_write_clearstartofline(struct screen_write_ctx *, u_int); void screen_write_clearstartofline(struct screen_write_ctx *, u_int);
void screen_write_cursormove(struct screen_write_ctx *, u_int, u_int); void screen_write_cursormove(struct screen_write_ctx *, int, int);
void screen_write_reverseindex(struct screen_write_ctx *, u_int); void screen_write_reverseindex(struct screen_write_ctx *, u_int);
void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int); void screen_write_scrollregion(struct screen_write_ctx *, u_int, u_int);
void screen_write_linefeed(struct screen_write_ctx *, int, u_int); void screen_write_linefeed(struct screen_write_ctx *, int, u_int);