Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2020-04-16 16:01:35 +01:00
commit 5e38d26257
10 changed files with 87 additions and 23 deletions

View File

@ -2569,7 +2569,7 @@ format_defaults_client(struct format_tree *ft, struct client *c)
format_add(ft, "client_prefix", "%d", 1);
format_add(ft, "client_key_table", "%s", c->keytable->name);
if (tty->flags & TTY_UTF8)
if (tty_get_flags(tty) & TERM_UTF8)
format_add(ft, "client_utf8", "%d", 1);
else
format_add(ft, "client_utf8", "%d", 0);

View File

@ -435,6 +435,7 @@ screen_redraw_screen(struct client *c)
flags = screen_redraw_update(c, c->flags);
screen_redraw_set_context(c, &ctx);
tty_sync_start(&c->tty);
if (flags & (CLIENT_REDRAWWINDOW|CLIENT_REDRAWBORDERS)) {
if (ctx.pane_status != PANE_STATUS_OFF)
@ -448,7 +449,9 @@ screen_redraw_screen(struct client *c)
screen_redraw_draw_status(&ctx);
if (c->overlay_draw != NULL && (flags & CLIENT_REDRAWOVERLAY))
c->overlay_draw(c, &ctx);
tty_reset(&c->tty);
tty_sync_end(&c->tty);
}
/* Redraw a single pane. */
@ -461,9 +464,12 @@ screen_redraw_pane(struct client *c, struct window_pane *wp)
return;
screen_redraw_set_context(c, &ctx);
tty_sync_start(&c->tty);
screen_redraw_draw_pane(&ctx, wp);
tty_reset(&c->tty);
tty_sync_end(&c->tty);
}
/* Draw a border cell. */

View File

@ -100,7 +100,8 @@ void
screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp,
struct screen *s)
{
u_int y;
struct tty_ctx ttyctx;
u_int y;
memset(ctx, 0, sizeof *ctx);
@ -129,18 +130,26 @@ screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp,
screen_size_y(ctx->s));
}
}
screen_write_initctx(ctx, &ttyctx);
tty_write(tty_cmd_syncstart, &ttyctx);
}
/* Finish writing. */
void
screen_write_stop(struct screen_write_ctx *ctx)
{
struct tty_ctx ttyctx;
screen_write_collect_end(ctx);
screen_write_collect_flush(ctx, 0);
log_debug("%s: %u cells (%u written, %u skipped)", __func__,
ctx->cells, ctx->written, ctx->skipped);
screen_write_initctx(ctx, &ttyctx);
tty_write(tty_cmd_syncend, &ttyctx);
free(ctx->item);
free(ctx->list); /* flush will have emptied */
}

View File

@ -2058,7 +2058,7 @@ server_client_dispatch_identify(struct client *c, struct imsg *imsg)
c->fd = -1;
} else {
if (c->flags & CLIENT_UTF8)
c->tty.flags |= TTY_UTF8;
c->tty.term_flags |= TERM_UTF8;
if (c->flags & CLIENT_256COLOURS)
c->tty.term_flags |= TERM_256COLOURS;
tty_resize(&c->tty);

2
tmux.1
View File

@ -5511,6 +5511,8 @@ $ printf '\e033[4 q'
If
.Em Se
is not set, \&Ss with argument 0 will be used to reset the cursor style instead.
.It Em \&Sync
Show that the terminal supports synchronized updates.
.It Em \&Tc
Indicate that the terminal supports the
.Ql direct colour

10
tmux.h
View File

@ -454,6 +454,7 @@ enum tty_code_code {
TTYC_SMUL,
TTYC_SMXX,
TTYC_SS,
TTYC_SYNC,
TTYC_TC,
TTYC_TSL,
TTYC_U8,
@ -1183,6 +1184,8 @@ struct tty_term {
#define TERM_DECSLRM 0x4
#define TERM_DECFRA 0x8
#define TERM_RGBCOLOURS 0x10
#define TERM_SYNC 0x20
#define TERM_UTF8 0x40
int flags;
LIST_ENTRY(tty_term) entry;
@ -1235,7 +1238,7 @@ struct tty {
#define TTY_NOCURSOR 0x1
#define TTY_FREEZE 0x2
#define TTY_TIMER 0x4
#define TTY_UTF8 0x8
/* 0x8 unused */
#define TTY_STARTED 0x10
#define TTY_OPENED 0x20
#define TTY_FOCUS 0x40
@ -1951,10 +1954,13 @@ void tty_set_title(struct tty *, const char *);
void tty_update_mode(struct tty *, int, struct screen *);
void tty_draw_line(struct tty *, struct window_pane *, struct screen *,
u_int, u_int, u_int, u_int, u_int);
void tty_sync_start(struct tty *);
void tty_sync_end(struct tty *);
int tty_open(struct tty *, char **);
void tty_close(struct tty *);
void tty_free(struct tty *);
void tty_set_flags(struct tty *, int);
int tty_get_flags(struct tty *);
void tty_write(void (*)(struct tty *, const struct tty_ctx *),
struct tty_ctx *);
void tty_cmd_alignmenttest(struct tty *, const struct tty_ctx *);
@ -1978,6 +1984,8 @@ void tty_cmd_scrolldown(struct tty *, const struct tty_ctx *);
void tty_cmd_reverseindex(struct tty *, const struct tty_ctx *);
void tty_cmd_setselection(struct tty *, const struct tty_ctx *);
void tty_cmd_rawstring(struct tty *, const struct tty_ctx *);
void tty_cmd_syncstart(struct tty *, const struct tty_ctx *);
void tty_cmd_syncend(struct tty *, const struct tty_ctx *);
/* tty-term.c */
extern struct tty_terms tty_terms;

View File

@ -99,7 +99,7 @@ tty_acs_needed(struct tty *tty)
tty_term_number(tty->term, TTYC_U8) == 0)
return (1);
if (tty->flags & TTY_UTF8)
if (tty_get_flags(tty) & TERM_UTF8)
return (0);
return (1);
}

View File

@ -1117,7 +1117,7 @@ tty_keys_device_status_report(struct tty *tty, const char *buf, size_t len,
/* Set terminal flags. */
if (strncmp(tmp, "ITERM2 ", 7) == 0)
flags |= (TERM_DECSLRM|TERM_256COLOURS|TERM_RGBCOLOURS);
flags |= (TERM_DECSLRM|TERM_256COLOURS|TERM_RGBCOLOURS|TERM_SYNC);
if (strncmp(tmp, "TMUX ", 5) == 0)
flags |= (TERM_256COLOURS|TERM_RGBCOLOURS);
log_debug("%s: received DSR %.*s", c->name, (int)*size, buf);

View File

@ -263,6 +263,7 @@ static const struct tty_term_code_entry tty_term_codes[] = {
[TTYC_SMUL] = { TTYCODE_STRING, "smul" },
[TTYC_SMXX] = { TTYCODE_STRING, "smxx" },
[TTYC_SS] = { TTYCODE_STRING, "Ss" },
[TTYC_SYNC] = { TTYCODE_FLAG, "Sync" },
[TTYC_TC] = { TTYCODE_FLAG, "Tc" },
[TTYC_TSL] = { TTYCODE_STRING, "tsl" },
[TTYC_U8] = { TTYCODE_NUMBER, "U8" },
@ -538,6 +539,10 @@ tty_term_find(char *name, int fd, char **cause)
tty_term_has(term, TTYC_SETRGBB)))
term->flags |= TERM_RGBCOLOURS;
/* Set flag if terminal has synchronized updates. */
if (tty_term_flag(term, TTYC_SYNC))
term->flags |= TERM_SYNC;
/*
* Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1
* rather than $COLUMNS (the cursor can never be beyond $COLUMNS - 1).

68
tty.c
View File

@ -74,7 +74,7 @@ static void tty_default_attributes(struct tty *, struct window_pane *,
u_int);
#define tty_use_margin(tty) \
((tty->term->flags|tty->term_flags) & TERM_DECSLRM)
(tty_get_flags(tty) & TERM_DECSLRM)
#define tty_pane_full_width(tty, ctx) \
((ctx)->xoff == 0 && screen_size_x((ctx)->wp->screen) >= (tty)->sx)
@ -478,6 +478,14 @@ tty_set_flags(struct tty *tty, int flags)
tty_puts(tty, "\033[?69h"); /* DECLRMM */
}
int
tty_get_flags(struct tty *tty)
{
if (tty->term != NULL)
return (tty->term->flags|tty->term_flags);
return (tty->term_flags);
}
void
tty_raw(struct tty *tty, const char *s)
{
@ -575,7 +583,7 @@ tty_putc(struct tty *tty, u_char ch)
{
const char *acs;
if ((tty->term->flags & TERM_NOXENL) &&
if ((tty_get_flags(tty) & TERM_NOXENL) &&
ch >= 0x20 && ch != 0x7f &&
tty->cy == tty->sy - 1 &&
tty->cx + 1 >= tty->sx)
@ -601,7 +609,7 @@ tty_putc(struct tty *tty, u_char ch)
* where we think it should be after a line wrap - this
* means it works on sensible terminals as well.
*/
if (tty->term->flags & TERM_NOXENL)
if (tty_get_flags(tty) & TERM_NOXENL)
tty_putcode2(tty, TTYC_CUP, tty->cy, tty->cx);
} else
tty->cx++;
@ -611,7 +619,7 @@ tty_putc(struct tty *tty, u_char ch)
void
tty_putn(struct tty *tty, const void *buf, size_t len, u_int width)
{
if ((tty->term->flags & TERM_NOXENL) &&
if ((tty_get_flags(tty) & TERM_NOXENL) &&
tty->cy == tty->sy - 1 &&
tty->cx + len >= tty->sx)
len = tty->sx - tty->cx - 1;
@ -1167,7 +1175,7 @@ tty_clear_area(struct tty *tty, struct window_pane *wp, u_int py, u_int ny,
* background colour isn't default (because it doesn't work
* after SGR 0).
*/
if (((tty->term->flags|tty->term_flags) & TERM_DECFRA) &&
if ((tty_get_flags(tty) & TERM_DECFRA) &&
!COLOUR_DEFAULT(bg)) {
xsnprintf(tmp, sizeof tmp, "\033[32;%u;%u;%u;%u$x",
py + 1, px + 1, py + ny, px + nx);
@ -1247,7 +1255,7 @@ tty_check_codeset(struct tty *tty, const struct grid_cell *gc)
return (gc);
/* UTF-8 terminal and a UTF-8 character - fine. */
if (tty->flags & TTY_UTF8)
if (tty_get_flags(tty) & TERM_UTF8)
return (gc);
/* Replace by the right number of underscores. */
@ -1426,6 +1434,20 @@ tty_draw_line(struct tty *tty, struct window_pane *wp, struct screen *s,
tty_update_mode(tty, tty->mode, s);
}
void
tty_sync_start(struct tty *tty)
{
if (tty_get_flags(tty) & TERM_SYNC)
tty_puts(tty, "\033P=1s\033\\");
}
void
tty_sync_end(struct tty *tty)
{
if (tty_get_flags(tty) & TERM_SYNC)
tty_puts(tty, "\033P=2s\033\\");
}
static int
tty_client_ready(struct client *c, struct window_pane *wp)
{
@ -1876,7 +1898,7 @@ tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx)
ctx->xoff + ctx->ocx + ctx->num > ctx->ox + ctx->sx)) {
if (!ctx->wrapped ||
!tty_pane_full_width(tty, ctx) ||
(tty->term->flags & TERM_NOXENL) ||
(tty_get_flags(tty) & TERM_NOXENL) ||
ctx->xoff + ctx->ocx != 0 ||
ctx->yoff + ctx->ocy != tty->cy + 1 ||
tty->cx < tty->sx ||
@ -1919,13 +1941,25 @@ tty_cmd_rawstring(struct tty *tty, const struct tty_ctx *ctx)
tty_invalidate(tty);
}
void
tty_cmd_syncstart(struct tty *tty, __unused const struct tty_ctx *ctx)
{
tty_sync_start(tty);
}
void
tty_cmd_syncend(struct tty *tty, __unused const struct tty_ctx *ctx)
{
tty_sync_end(tty);
}
static void
tty_cell(struct tty *tty, const struct grid_cell *gc, struct window_pane *wp)
{
const struct grid_cell *gcp;
/* Skip last character if terminal is stupid. */
if ((tty->term->flags & TERM_NOXENL) &&
if ((tty_get_flags(tty) & TERM_NOXENL) &&
tty->cy == tty->sy - 1 &&
tty->cx == tty->sx - 1)
return;
@ -2084,7 +2118,7 @@ tty_cursor_pane_unless_wrap(struct tty *tty, const struct tty_ctx *ctx,
{
if (!ctx->wrapped ||
!tty_pane_full_width(tty, ctx) ||
(tty->term->flags & TERM_NOXENL) ||
(tty_get_flags(tty) & TERM_NOXENL) ||
ctx->xoff + cx != 0 ||
ctx->yoff + cy != tty->cy + 1 ||
tty->cx < tty->sx ||
@ -2421,14 +2455,14 @@ tty_check_fg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
/* Is this a 24-bit colour? */
if (gc->fg & COLOUR_FLAG_RGB) {
/* Not a 24-bit terminal? Translate to 256-colour palette. */
if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
if (tty_get_flags(tty) & TERM_RGBCOLOURS)
return;
colour_split_rgb(gc->fg, &r, &g, &b);
gc->fg = colour_find_rgb(r, g, b);
}
/* How many colours does this terminal have? */
if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS)
if (tty_get_flags(tty) & TERM_256COLOURS)
colours = 256;
else
colours = tty_term_number(tty->term, TTYC_COLORS);
@ -2470,14 +2504,14 @@ tty_check_bg(struct tty *tty, struct window_pane *wp, struct grid_cell *gc)
/* Is this a 24-bit colour? */
if (gc->bg & COLOUR_FLAG_RGB) {
/* Not a 24-bit terminal? Translate to 256-colour palette. */
if ((tty->term->flags|tty->term_flags) & TERM_RGBCOLOURS)
if (tty_get_flags(tty) & TERM_RGBCOLOURS)
return;
colour_split_rgb(gc->bg, &r, &g, &b);
gc->bg = colour_find_rgb(r, g, b);
}
/* How many colours does this terminal have? */
if ((tty->term->flags|tty->term_flags) & TERM_256COLOURS)
if (tty_get_flags(tty) & TERM_256COLOURS)
colours = 256;
else
colours = tty_term_number(tty->term, TTYC_COLORS);
@ -2538,7 +2572,7 @@ tty_colours_fg(struct tty *tty, const struct grid_cell *gc)
/* Is this an aixterm bright colour? */
if (gc->fg >= 90 && gc->fg <= 97) {
if (tty->term_flags & TERM_256COLOURS) {
if (tty_get_flags(tty) & TERM_256COLOURS) {
xsnprintf(s, sizeof s, "\033[%dm", gc->fg);
tty_puts(tty, s);
} else
@ -2570,7 +2604,7 @@ tty_colours_bg(struct tty *tty, const struct grid_cell *gc)
/* Is this an aixterm bright colour? */
if (gc->bg >= 90 && gc->bg <= 97) {
if (tty->term_flags & TERM_256COLOURS) {
if (tty_get_flags(tty) & TERM_256COLOURS) {
xsnprintf(s, sizeof s, "\033[%dm", gc->bg + 10);
tty_puts(tty, s);
} else
@ -2626,7 +2660,7 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
* Also if RGB is set, setaf and setab do not support the 256
* colour palette so use the sequences directly there too.
*/
if ((tty->term_flags & TERM_256COLOURS) ||
if ((tty_get_flags(tty) & TERM_256COLOURS) ||
tty_term_has(tty->term, TTYC_RGB))
goto fallback_256;
@ -2634,7 +2668,7 @@ tty_try_colour(struct tty *tty, int colour, const char *type)
* If the terminfo entry has 256 colours and setaf and setab
* exist, assume that they work correctly.
*/
if (tty->term->flags & TERM_256COLOURS) {
if (tty_get_flags(tty) & TERM_256COLOURS) {
if (*type == '3') {
if (!tty_term_has(tty->term, TTYC_SETAF))
goto fallback_256;