Add a context for cell/palette/hyperlinks when drawing to tty to avoid

passing so much in parameters.
This commit is contained in:
nicm
2026-06-09 21:22:22 +00:00
parent 34dd42dc7f
commit d533d7c97c
10 changed files with 125 additions and 125 deletions

View File

@@ -91,6 +91,7 @@ cmd_display_panes_draw_format(struct screen_redraw_ctx *ctx,
const char *format; const char *format;
char *expanded; char *expanded;
u_int i, px = ctx->ox + xoff; u_int i, px = ctx->ox + xoff;
struct tty_style_ctx style_ctx = { .defaults = gc };
format = options_get_string(s->options, "display-panes-format"); format = options_get_string(s->options, "display-panes-format");
expanded = format_single(NULL, format, c, s, s->curw, wp); expanded = format_single(NULL, format, c, s, s->curw, wp);
@@ -105,7 +106,7 @@ cmd_display_panes_draw_format(struct screen_redraw_ctx *ctx,
for (i = 0; i < r->used; i++) { for (i = 0; i < r->used; i++) {
ri = &r->ranges[i]; ri = &r->ranges[i];
tty_draw_line(tty, &screen, ri->px - px, 0, ri->nx, tty_draw_line(tty, &screen, ri->px - px, 0, ri->nx,
ri->px - ctx->ox, yoff, gc, NULL); ri->px - ctx->ox, yoff, &style_ctx);
} }
screen_free(&screen); screen_free(&screen);
} }
@@ -199,7 +200,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
llen = 0; llen = 0;
if (sx < len * 6 || sy < 5) { if (sx < len * 6 || sy < 5) {
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL); tty_attributes(tty, &fgc, NULL);
if (sx >= len + llen + 1) { if (sx >= len + llen + 1) {
len += llen + 1; len += llen + 1;
cx = xoff + px - len / 2; cx = xoff + px - len / 2;
@@ -220,7 +221,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
px -= len * 3; px -= len * 3;
py -= 2; py -= 2;
tty_attributes(tty, &bgc, &grid_default_cell, NULL, NULL); tty_attributes(tty, &bgc, NULL);
for (ptr = buf; *ptr != '\0'; ptr++) { for (ptr = buf; *ptr != '\0'; ptr++) {
if (*ptr < '0' || *ptr > '9') if (*ptr < '0' || *ptr > '9')
continue; continue;
@@ -242,7 +243,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
goto out; goto out;
cmd_display_panes_draw_format(ctx, wp, xoff, yoff, sx, &fgc); cmd_display_panes_draw_format(ctx, wp, xoff, yoff, sx, &fgc);
if (llen != 0) { if (llen != 0) {
tty_attributes(tty, &fgc, &grid_default_cell, NULL, NULL); tty_attributes(tty, &fgc, NULL);
cx = xoff + sx / 2 + len * 3 - llen - 1; cx = xoff + sx / 2 + len * 3 - llen - 1;
cy = yoff + py + 5; cy = yoff + py + 5;
cmd_display_panes_put(ctx, wp, cx, cy, lbuf, llen); cmd_display_panes_put(ctx, wp, cx, cy, lbuf, llen);

View File

@@ -50,8 +50,6 @@ cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
{ {
struct args *args = cmd_get_args(self); struct args *args = cmd_get_args(self);
struct cmd_find_state *target = cmdq_get_target(item); struct cmd_find_state *target = cmdq_get_target(item);
struct session *s = target->s;
struct winlink *wl = target->wl;
struct window_pane *wp = target->wp; struct window_pane *wp = target->wp;
const char *filter = args_get(args, 'f'); const char *filter = args_get(args, 'f');

6
menu.c
View File

@@ -281,10 +281,8 @@ menu_draw_cb(struct client *c, void *data,
&md->style_gc, &md->border_style_gc, &md->selected_style_gc); &md->style_gc, &md->border_style_gc, &md->selected_style_gc);
screen_write_stop(&ctx); screen_write_stop(&ctx);
for (i = 0; i < screen_size_y(&md->s); i++) { for (i = 0; i < screen_size_y(&md->s); i++)
tty_draw_line(tty, s, 0, i, menu->width + 4, px, py + i, tty_draw_line(tty, s, 0, i, menu->width + 4, px, py + i, NULL);
&grid_default_cell, NULL);
}
} }
void void

18
popup.c
View File

@@ -209,7 +209,8 @@ popup_init_ctx_cb(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx)
memcpy(&ttyctx->defaults, &pd->defaults, sizeof ttyctx->defaults); memcpy(&ttyctx->defaults, &pd->defaults, sizeof ttyctx->defaults);
ttyctx->flags &= ~TTY_CTX_WINDOW_BIGGER; ttyctx->flags &= ~TTY_CTX_WINDOW_BIGGER;
ttyctx->palette = &pd->palette; ttyctx->style_ctx.defaults = &ttyctx->defaults;
ttyctx->style_ctx.palette = &pd->palette;
ttyctx->redraw_cb = popup_redraw_cb; ttyctx->redraw_cb = popup_redraw_cb;
ttyctx->set_client_cb = popup_set_client_cb; ttyctx->set_client_cb = popup_set_client_cb;
ttyctx->arg = pd; ttyctx->arg = pd;
@@ -295,8 +296,8 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx)
struct screen s; struct screen s;
struct screen_write_ctx ctx; struct screen_write_ctx ctx;
u_int i, px = pd->px, py = pd->py; u_int i, px = pd->px, py = pd->py;
struct colour_palette *palette = &pd->palette;
struct grid_cell defaults; struct grid_cell defaults;
struct tty_style_ctx style_ctx;
popup_reapply_styles(pd); popup_reapply_styles(pd);
@@ -322,9 +323,12 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx)
memcpy(&defaults, &pd->defaults, sizeof defaults); memcpy(&defaults, &pd->defaults, sizeof defaults);
if (defaults.fg == 8) if (defaults.fg == 8)
defaults.fg = palette->fg; defaults.fg = pd->palette.fg;
if (defaults.bg == 8) if (defaults.bg == 8)
defaults.bg = palette->bg; defaults.bg = pd->palette.bg;
style_ctx.defaults = &defaults;
style_ctx.palette = &pd->palette;
style_ctx.hyperlinks = s.hyperlinks;
if (pd->md != NULL) { if (pd->md != NULL) {
c->overlay_check = menu_check_cb; c->overlay_check = menu_check_cb;
@@ -333,10 +337,8 @@ popup_draw_cb(struct client *c, void *data, struct screen_redraw_ctx *rctx)
c->overlay_check = NULL; c->overlay_check = NULL;
c->overlay_data = NULL; c->overlay_data = NULL;
} }
for (i = 0; i < pd->sy; i++) { for (i = 0; i < pd->sy; i++)
tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &defaults, tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &style_ctx);
palette);
}
screen_free(&s); screen_free(&s);
if (pd->md != NULL) { if (pd->md != NULL) {
c->overlay_check = NULL; c->overlay_check = NULL;

View File

@@ -725,8 +725,7 @@ screen_redraw_draw_pane_status(struct screen_redraw_ctx *ctx)
if (ri->nx == 0) if (ri->nx == 0)
continue; continue;
tty_draw_line(tty, s, l + (ri->px - x), 0, ri->nx, tty_draw_line(tty, s, l + (ri->px - x), 0, ri->nx,
ri->px, yoff - ctx->oy, ri->px, yoff - ctx->oy, NULL);
&grid_default_cell, NULL);
} }
} }
tty_cursor(tty, 0, 0); tty_cursor(tty, 0, 0);
@@ -1044,7 +1043,7 @@ screen_redraw_draw_borders_cell(struct screen_redraw_ctx *ctx, u_int i, u_int j)
screen_redraw_draw_border_arrows(ctx, i, j, cell_type, wp, active, &gc); screen_redraw_draw_border_arrows(ctx, i, j, cell_type, wp, active, &gc);
tty_cell(tty, &gc, &grid_default_cell, NULL, NULL); tty_cell(tty, &gc, NULL);
if (isolates) if (isolates)
tty_puts(tty, START_ISOLATE); tty_puts(tty, START_ISOLATE);
} }
@@ -1104,10 +1103,8 @@ screen_redraw_draw_status(struct screen_redraw_ctx *ctx)
y = 0; y = 0;
else else
y = c->tty.sy - ctx->statuslines; y = c->tty.sy - ctx->statuslines;
for (i = 0; i < ctx->statuslines; i++) { for (i = 0; i < ctx->statuslines; i++)
tty_draw_line(tty, s, 0, i, UINT_MAX, 0, y + i, tty_draw_line(tty, s, 0, i, UINT_MAX, 0, y + i, NULL);
&grid_default_cell, NULL);
}
} }
/* /*
@@ -1302,6 +1299,7 @@ screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp)
struct screen *s = wp->screen; struct screen *s = wp->screen;
struct colour_palette *palette = &wp->palette; struct colour_palette *palette = &wp->palette;
struct grid_cell defaults; struct grid_cell defaults;
struct tty_style_ctx style_ctx;
u_int j, k, woy, wx, wy, py, width; u_int j, k, woy, wx, wy, py, width;
struct visible_ranges *r; struct visible_ranges *r;
struct visible_range *ri; struct visible_range *ri;
@@ -1376,10 +1374,15 @@ screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp)
width = ctx->sx - wx; width = ctx->sx - wx;
} }
/* Set up the default style. */
tty_default_colours(&defaults, wp);
style_ctx.defaults = &defaults;
style_ctx.palette = palette;
style_ctx.hyperlinks = s->hyperlinks;
/* Get visible ranges of line before we draw it. */ /* Get visible ranges of line before we draw it. */
r = tty_check_overlay_range(tty, wx, wy, width); r = tty_check_overlay_range(tty, wx, wy, width);
r = screen_redraw_get_visible_ranges(wp, wx, wy, width, r); r = screen_redraw_get_visible_ranges(wp, wx, wy, width, r);
tty_default_colours(&defaults, wp);
for (k = 0; k < r->used; k++) { for (k = 0; k < r->used; k++) {
ri = &r->ranges[k]; ri = &r->ranges[k];
if (ri->nx == 0) if (ri->nx == 0)
@@ -1390,7 +1393,7 @@ screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp)
ri->px + (int)ctx->ox - wp->xoff, j, ri->nx, ri->px + (int)ctx->ox - wp->xoff, j, ri->nx,
ri->px, py, ri->nx); ri->px, py, ri->nx);
tty_draw_line(tty, s, ri->px + (int)ctx->ox - wp->xoff, tty_draw_line(tty, s, ri->px + (int)ctx->ox - wp->xoff,
j, ri->nx, ri->px, py, &defaults, palette); j, ri->nx, ri->px, py, &style_ctx);
} }
} }
} }
@@ -1563,16 +1566,14 @@ screen_redraw_draw_scrollbar(struct screen_redraw_ctx *ctx,
if ((sb_pos == PANE_SCROLLBARS_LEFT && if ((sb_pos == PANE_SCROLLBARS_LEFT &&
i >= sb_w && i < sb_w + sb_pad) || i >= sb_w && i < sb_w + sb_pad) ||
(sb_pos == PANE_SCROLLBARS_RIGHT && (sb_pos == PANE_SCROLLBARS_RIGHT &&
i < sb_pad)) { i < sb_pad))
tty_cell(tty, &grid_default_cell, tty_cell(tty, &grid_default_cell, NULL);
&grid_default_cell, NULL, NULL); else {
} else {
if (j >= slider_y && j < slider_y + slider_h) if (j >= slider_y && j < slider_y + slider_h)
gcp = &slgc; gcp = &slgc;
else else
gcp = &gc; gcp = &gc;
tty_cell(tty, gcp, &grid_default_cell, NULL, tty_cell(tty, gcp, NULL);
NULL);
} }
} }
} }

View File

@@ -219,7 +219,8 @@ static void
screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx, screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
int is_sync, int check_obscured) int is_sync, int check_obscured)
{ {
struct screen *s = ctx->s; struct screen *s = ctx->s;
struct colour_palette *palette = NULL;
memset(ttyctx, 0, sizeof *ttyctx); memset(ttyctx, 0, sizeof *ttyctx);
@@ -236,19 +237,23 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
ttyctx->flags |= TTY_CTX_PANE_OBSCURED; ttyctx->flags |= TTY_CTX_PANE_OBSCURED;
memcpy(&ttyctx->defaults, &grid_default_cell, sizeof ttyctx->defaults); memcpy(&ttyctx->defaults, &grid_default_cell, sizeof ttyctx->defaults);
ttyctx->style_ctx.defaults = &ttyctx->defaults;
ttyctx->style_ctx.hyperlinks = ctx->s->hyperlinks;
if (ctx->init_ctx_cb != NULL) { if (ctx->init_ctx_cb != NULL) {
ctx->init_ctx_cb(ctx, ttyctx); ctx->init_ctx_cb(ctx, ttyctx);
if (ttyctx->palette != NULL) { if (ttyctx->style_ctx.palette != NULL) {
palette = ttyctx->style_ctx.palette;
if (ttyctx->defaults.fg == 8) if (ttyctx->defaults.fg == 8)
ttyctx->defaults.fg = ttyctx->palette->fg; ttyctx->defaults.fg = palette->fg;
if (ttyctx->defaults.bg == 8) if (ttyctx->defaults.bg == 8)
ttyctx->defaults.bg = ttyctx->palette->bg; ttyctx->defaults.bg = palette->bg;
} }
} else { } else {
ttyctx->redraw_cb = screen_write_redraw_cb; ttyctx->redraw_cb = screen_write_redraw_cb;
if (ctx->wp != NULL) { if (ctx->wp != NULL) {
tty_default_colours(&ttyctx->defaults, ctx->wp); tty_default_colours(&ttyctx->defaults, ctx->wp);
ttyctx->palette = &ctx->wp->palette; ttyctx->style_ctx.palette = &ctx->wp->palette;
ttyctx->set_client_cb = screen_write_set_client_cb; ttyctx->set_client_cb = screen_write_set_client_cb;
ttyctx->arg = ctx->wp; ttyctx->arg = ctx->wp;
} }

27
tmux.h
View File

@@ -1610,6 +1610,13 @@ struct tty_term {
}; };
LIST_HEAD(tty_terms, tty_term); LIST_HEAD(tty_terms, tty_term);
/* Terminal style context. */
struct tty_style_ctx {
const struct grid_cell *defaults;
struct colour_palette *palette;
struct hyperlinks *hyperlinks;
};
/* Client terminal. */ /* Client terminal. */
struct tty { struct tty {
struct client *client; struct client *client;
@@ -1753,7 +1760,7 @@ struct tty_ctx {
/* The default colours and palette. */ /* The default colours and palette. */
struct grid_cell defaults; struct grid_cell defaults;
struct colour_palette *palette; struct tty_style_ctx style_ctx;
/* Containing region (usually window) offset and size. */ /* Containing region (usually window) offset and size. */
u_int wox; u_int wox;
@@ -2621,6 +2628,10 @@ void environ_push(struct environ *);
void printflike(2, 3) environ_log(struct environ *, const char *, ...); void printflike(2, 3) environ_log(struct environ *, const char *, ...);
struct environ *environ_for_session(struct session *, int); struct environ *environ_for_session(struct session *, int);
/* tty-draw.c */
void tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int,
u_int, u_int, const struct tty_style_ctx *);
/* tty.c */ /* tty.c */
void tty_create_log(void); void tty_create_log(void);
int tty_window_bigger(struct tty *); int tty_window_bigger(struct tty *);
@@ -2629,8 +2640,7 @@ void tty_update_window_offset(struct window *);
void tty_update_client_offset(struct client *); void tty_update_client_offset(struct client *);
void tty_raw(struct tty *, const char *); void tty_raw(struct tty *, const char *);
void tty_attributes(struct tty *, const struct grid_cell *, void tty_attributes(struct tty *, const struct grid_cell *,
const struct grid_cell *, struct colour_palette *, const struct tty_style_ctx *);
struct hyperlinks *);
void tty_reset(struct tty *); void tty_reset(struct tty *);
void tty_region_off(struct tty *); void tty_region_off(struct tty *);
void tty_margin_off(struct tty *); void tty_margin_off(struct tty *);
@@ -2649,8 +2659,7 @@ void tty_puts(struct tty *, const char *);
void tty_putc(struct tty *, u_char); void tty_putc(struct tty *, u_char);
void tty_putn(struct tty *, const void *, size_t, u_int); void tty_putn(struct tty *, const void *, size_t, u_int);
void tty_cell(struct tty *, const struct grid_cell *, void tty_cell(struct tty *, const struct grid_cell *,
const struct grid_cell *, struct colour_palette *, const struct tty_style_ctx *);
struct hyperlinks *);
int tty_init(struct tty *, struct client *); int tty_init(struct tty *, struct client *);
void tty_resize(struct tty *); void tty_resize(struct tty *);
void tty_set_size(struct tty *, u_int, u_int, u_int, u_int); void tty_set_size(struct tty *, u_int, u_int, u_int, u_int);
@@ -2662,17 +2671,13 @@ void tty_stop_tty(struct tty *);
void tty_set_title(struct tty *, const char *); void tty_set_title(struct tty *, const char *);
void tty_set_path(struct tty *, const char *); void tty_set_path(struct tty *, const char *);
void tty_set_progress_bar(struct tty *, struct progress_bar *); void tty_set_progress_bar(struct tty *, struct progress_bar *);
void tty_default_attributes(struct tty *, const struct grid_cell *, void tty_default_attributes(struct tty *, u_int,
struct colour_palette *, u_int, struct hyperlinks *); const struct tty_style_ctx *);
void tty_update_mode(struct tty *, int, struct screen *); void tty_update_mode(struct tty *, int, struct screen *);
const struct grid_cell *tty_check_codeset(struct tty *, const struct grid_cell *tty_check_codeset(struct tty *,
const struct grid_cell *); const struct grid_cell *);
struct visible_ranges *tty_check_overlay_range(struct tty *, u_int, u_int, struct visible_ranges *tty_check_overlay_range(struct tty *, u_int, u_int,
u_int); u_int);
/* tty-draw.c */
void tty_draw_line(struct tty *, struct screen *, u_int, u_int, u_int,
u_int, u_int, const struct grid_cell *, struct colour_palette *);
void tty_sync_start(struct tty *); void tty_sync_start(struct tty *);
void tty_sync_end(struct tty *); void tty_sync_end(struct tty *);
int tty_open(struct tty *, char **); int tty_open(struct tty *, char **);

View File

@@ -22,6 +22,7 @@
#include "tmux.h" #include "tmux.h"
/* Current state when drawing line. */
enum tty_draw_line_state { enum tty_draw_line_state {
TTY_DRAW_LINE_FIRST, TTY_DRAW_LINE_FIRST,
TTY_DRAW_LINE_FLUSH, TTY_DRAW_LINE_FLUSH,
@@ -91,8 +92,7 @@ tty_draw_line_clear(struct tty *tty, u_int px, u_int py, u_int nx,
/* Draw a line from screen to tty. */ /* Draw a line from screen to tty. */
void void
tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx, tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
u_int atx, u_int aty, const struct grid_cell *defaults, u_int atx, u_int aty, const struct tty_style_ctx *style_ctx)
struct colour_palette *palette)
{ {
struct grid *gd = s->grid; struct grid *gd = s->grid;
const struct grid_cell *gcp; const struct grid_cell *gcp;
@@ -104,6 +104,14 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
char buf[1000]; char buf[1000];
size_t len; size_t len;
enum tty_draw_line_state current_state, next_state; enum tty_draw_line_state current_state, next_state;
struct tty_style_ctx default_style_ctx = { 0 };
if (style_ctx == NULL) {
default_style_ctx.defaults = &grid_default_cell;
default_style_ctx.hyperlinks = s->hyperlinks;
style_ctx = &default_style_ctx;
}
/* /*
* py is the line in the screen to draw. px is the start x and nx is * py is the line in the screen to draw. px is the start x and nx is
@@ -130,8 +138,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
else else
ex = screen_size_x(s); ex = screen_size_x(s);
log_debug("%s: drawing %u-%u,%u (end %u) at %u,%u; defaults: fg=%d, " log_debug("%s: drawing %u-%u,%u (end %u) at %u,%u; defaults: fg=%d, "
"bg=%d", __func__, px, px + nx, py, ex, atx, aty, defaults->fg, "bg=%d", __func__, px, px + nx, py, ex, atx, aty,
defaults->bg); style_ctx->defaults->fg, style_ctx->defaults->bg);
/* Turn off cursor while redrawing and reset region and margins. */ /* Turn off cursor while redrawing and reset region and margins. */
flags = (tty->flags & TTY_NOCURSOR); flags = (tty->flags & TTY_NOCURSOR);
@@ -142,8 +150,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
/* Start with the default cell as the last cell. */ /* Start with the default cell as the last cell. */
memcpy(&last, &grid_default_cell, sizeof last); memcpy(&last, &grid_default_cell, sizeof last);
last.bg = defaults->bg; last.bg = style_ctx->defaults->bg;
tty_default_attributes(tty, defaults, palette, 8, s->hyperlinks); tty_default_attributes(tty, 8, style_ctx);
/* /*
* If there is padding at the start, we must have truncated a wide * If there is padding at the start, we must have truncated a wide
@@ -164,7 +172,7 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
break; break;
} }
if (i == 0) if (i == 0)
bg = defaults->bg; bg = style_ctx->defaults->bg;
else { else {
bg = gc.bg; bg = gc.bg;
if (gc.flags & GRID_FLAG_SELECTED) { if (gc.flags & GRID_FLAG_SELECTED) {
@@ -173,9 +181,9 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
bg = ngc.bg; bg = ngc.bg;
} }
} }
tty_attributes(tty, &last, defaults, palette, s->hyperlinks); tty_attributes(tty, &last, style_ctx);
log_debug("%s: clearing %u padding cells", __func__, cx); log_debug("%s: clearing %u padding cells", __func__, cx);
tty_draw_line_clear(tty, atx, aty, cx, defaults, bg, 0); tty_draw_line_clear(tty, atx, aty, cx, style_ctx->defaults, bg, 0);
if (cx == ex) if (cx == ex)
goto out; goto out;
atx += cx; atx += cx;
@@ -274,15 +282,14 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
/* If the state has changed, flush any collected data. */ /* If the state has changed, flush any collected data. */
if (next_state != current_state) { if (next_state != current_state) {
if (current_state == TTY_DRAW_LINE_EMPTY) { if (current_state == TTY_DRAW_LINE_EMPTY) {
tty_attributes(tty, &last, defaults, palette, tty_attributes(tty, &last, style_ctx);
s->hyperlinks);
tty_draw_line_clear(tty, atx + last_i, aty, tty_draw_line_clear(tty, atx + last_i, aty,
i - last_i, defaults, last.bg, wrapped); i - last_i, style_ctx->defaults, last.bg,
wrapped);
wrapped = 0; wrapped = 0;
} else if (next_state != TTY_DRAW_LINE_SAME && } else if (next_state != TTY_DRAW_LINE_SAME &&
len != 0) { len != 0) {
tty_attributes(tty, &last, defaults, palette, tty_attributes(tty, &last, style_ctx);
s->hyperlinks);
if (atx + i - width != 0 || !wrapped) if (atx + i - width != 0 || !wrapped)
tty_cursor(tty, atx + i - width, aty); tty_cursor(tty, atx + i - width, aty);
if (~last.attr & GRID_ATTR_CHARSET) if (~last.attr & GRID_ATTR_CHARSET)
@@ -322,4 +329,3 @@ out:
tty->flags = (tty->flags & ~TTY_NOCURSOR)|flags; tty->flags = (tty->flags & ~TTY_NOCURSOR)|flags;
tty_update_mode(tty, tty->mode, s); tty_update_mode(tty, tty->mode, s);
} }

99
tty.c
View File

@@ -79,6 +79,10 @@ static int tty_check_overlay(struct tty *, u_int, u_int);
#define TTY_QUERY_TIMEOUT 5 #define TTY_QUERY_TIMEOUT 5
#define TTY_REQUEST_LIMIT 30 #define TTY_REQUEST_LIMIT 30
static struct tty_style_ctx tty_default_style_ctx = {
&grid_default_cell, NULL, NULL
};
void void
tty_create_log(void) tty_create_log(void)
{ {
@@ -1410,7 +1414,7 @@ tty_draw_pane(struct tty *tty, const struct tty_ctx *ctx, u_int py)
if (rr->nx == 0) if (rr->nx == 0)
continue; continue;
tty_draw_line(tty, s, rr->px - ctx->xoff, py, rr->nx, tty_draw_line(tty, s, rr->px - ctx->xoff, py, rr->nx,
rr->px, ctx->yoff + py, &ctx->defaults, ctx->palette); rr->px, ctx->yoff + py, &ctx->style_ctx);
} }
return; return;
} }
@@ -1421,7 +1425,7 @@ tty_draw_pane(struct tty *tty, const struct tty_ctx *ctx, u_int py)
if (rr->nx == 0) if (rr->nx == 0)
continue; continue;
tty_draw_line(tty, s, i + rr->px - x, py, rr->nx, tty_draw_line(tty, s, i + rr->px - x, py, rr->nx,
rr->px, ry, &ctx->defaults, ctx->palette); rr->px, ry, &ctx->style_ctx);
} }
} }
} }
@@ -1578,8 +1582,7 @@ tty_cmd_insertcharacter(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@@ -1601,8 +1604,7 @@ tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy); tty_cursor_pane(tty, ctx, ctx->ocx, ctx->ocy);
@@ -1612,8 +1614,7 @@ tty_cmd_deletecharacter(struct tty *tty, const struct tty_ctx *ctx)
void void
tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx) tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx)
{ {
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, ctx->n, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, ctx->n, ctx->bg);
} }
@@ -1635,8 +1636,7 @@ tty_cmd_insertline(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_off(tty); tty_margin_off(tty);
@@ -1663,8 +1663,7 @@ tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_off(tty); tty_margin_off(tty);
@@ -1677,8 +1676,7 @@ tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx)
void void
tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx) tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx)
{ {
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->sx, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->sx, ctx->bg);
} }
@@ -1688,8 +1686,7 @@ tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx)
{ {
u_int nx = ctx->sx - ctx->ocx; u_int nx = ctx->sx - ctx->ocx;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, nx, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, ctx->ocx, nx, ctx->bg);
} }
@@ -1697,8 +1694,7 @@ tty_cmd_clearendofline(struct tty *tty, const struct tty_ctx *ctx)
void void
tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx) tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx)
{ {
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->ocx + 1, ctx->bg); tty_clear_pane_line(tty, ctx, ctx->ocy, 0, ctx->ocx + 1, ctx->bg);
} }
@@ -1724,8 +1720,7 @@ tty_cmd_reverseindex(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_pane(tty, ctx); tty_margin_pane(tty, ctx);
@@ -1756,8 +1751,7 @@ tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_pane(tty, ctx); tty_margin_pane(tty, ctx);
@@ -1797,8 +1791,7 @@ tty_cmd_scrollup(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_pane(tty, ctx); tty_margin_pane(tty, ctx);
@@ -1838,8 +1831,7 @@ tty_cmd_scrolldown(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower); tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_pane(tty, ctx); tty_margin_pane(tty, ctx);
@@ -1858,8 +1850,7 @@ tty_cmd_clearendofscreen(struct tty *tty, const struct tty_ctx *ctx)
{ {
u_int px, py, nx, ny; u_int px, py, nx, ny;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_region_pane(tty, ctx, 0, ctx->sy - 1);
tty_margin_off(tty); tty_margin_off(tty);
@@ -1883,8 +1874,7 @@ tty_cmd_clearstartofscreen(struct tty *tty, const struct tty_ctx *ctx)
{ {
u_int px, py, nx, ny; u_int px, py, nx, ny;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_region_pane(tty, ctx, 0, ctx->sy - 1);
tty_margin_off(tty); tty_margin_off(tty);
@@ -1908,8 +1898,7 @@ tty_cmd_clearscreen(struct tty *tty, const struct tty_ctx *ctx)
{ {
u_int px, py, nx, ny; u_int px, py, nx, ny;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg, tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_region_pane(tty, ctx, 0, ctx->sy - 1);
tty_margin_off(tty); tty_margin_off(tty);
@@ -1934,8 +1923,7 @@ tty_cmd_alignmenttest(struct tty *tty, const struct tty_ctx *ctx)
return; return;
} }
tty_attributes(tty, &grid_default_cell, &ctx->defaults, ctx->palette, tty_attributes(tty, &grid_default_cell, &ctx->style_ctx);
ctx->s->hyperlinks);
tty_region_pane(tty, ctx, 0, ctx->sy - 1); tty_region_pane(tty, ctx, 0, ctx->sy - 1);
tty_margin_off(tty); tty_margin_off(tty);
@@ -1968,7 +1956,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
vis += r->ranges[i].nx; vis += r->ranges[i].nx;
if (vis < gcp->data.width) { if (vis < gcp->data.width) {
tty_draw_line(tty, s, s->cx, s->cy, gcp->data.width, tty_draw_line(tty, s, s->cx, s->cy, gcp->data.width,
px, py, &ctx->defaults, ctx->palette); px, py, &ctx->style_ctx);
return; return;
} }
} }
@@ -1983,8 +1971,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
tty_invalidate(tty); tty_invalidate(tty);
tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy); tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
tty_cell(tty, ctx->cell, &ctx->defaults, ctx->palette, tty_cell(tty, ctx->cell, &ctx->style_ctx);
ctx->s->hyperlinks);
if (ctx->flags & TTY_CTX_CELL_INVALIDATE) if (ctx->flags & TTY_CTX_CELL_INVALIDATE)
tty_invalidate(tty); tty_invalidate(tty);
@@ -2020,8 +2007,7 @@ tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx)
tty_margin_off(tty); tty_margin_off(tty);
tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy); tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
tty_attributes(tty, ctx->cell, &ctx->defaults, ctx->palette, tty_attributes(tty, ctx->cell, &ctx->style_ctx);
ctx->s->hyperlinks);
/* Get tty position from pane position for overlay check. */ /* Get tty position from pane position for overlay check. */
px = ctx->xoff + ctx->ocx - ctx->wox; px = ctx->xoff + ctx->ocx - ctx->wox;
@@ -2098,8 +2084,7 @@ tty_cmd_syncstart(struct tty *tty, const struct tty_ctx *ctx)
void void
tty_cell(struct tty *tty, const struct grid_cell *gc, tty_cell(struct tty *tty, const struct grid_cell *gc,
const struct grid_cell *defaults, struct colour_palette *palette, const struct tty_style_ctx *style_ctx)
struct hyperlinks *hl)
{ {
const struct grid_cell *gcp; const struct grid_cell *gcp;
@@ -2119,7 +2104,7 @@ tty_cell(struct tty *tty, const struct grid_cell *gc,
/* Check the output codeset and apply attributes. */ /* Check the output codeset and apply attributes. */
gcp = tty_check_codeset(tty, gc); gcp = tty_check_codeset(tty, gc);
tty_attributes(tty, gcp, defaults, palette, hl); tty_attributes(tty, gcp, style_ctx);
/* If it is a single character, write with putc to handle ACS. */ /* If it is a single character, write with putc to handle ACS. */
if (gcp->data.size == 1) { if (gcp->data.size == 1) {
@@ -2464,19 +2449,22 @@ tty_hyperlink(struct tty *tty, const struct grid_cell *gc,
void void
tty_attributes(struct tty *tty, const struct grid_cell *gc, tty_attributes(struct tty *tty, const struct grid_cell *gc,
const struct grid_cell *defaults, struct colour_palette *palette, const struct tty_style_ctx *style_ctx)
struct hyperlinks *hl)
{ {
struct grid_cell *tc = &tty->cell, gc2; struct grid_cell *tc = &tty->cell, gc2;
int changed; int changed;
/* Use default style if not given. */
if (style_ctx == NULL)
style_ctx = &tty_default_style_ctx;
/* Copy cell and update default colours. */ /* Copy cell and update default colours. */
memcpy(&gc2, gc, sizeof gc2); memcpy(&gc2, gc, sizeof gc2);
if (~gc->flags & GRID_FLAG_NOPALETTE) { if (~gc->flags & GRID_FLAG_NOPALETTE) {
if (gc2.fg == 8) if (gc2.fg == 8)
gc2.fg = defaults->fg; gc2.fg = style_ctx->defaults->fg;
if (gc2.bg == 8) if (gc2.bg == 8)
gc2.bg = defaults->bg; gc2.bg = style_ctx->defaults->bg;
} }
/* Ignore cell if it is the same as the last one. */ /* Ignore cell if it is the same as the last one. */
@@ -2503,9 +2491,9 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc,
} }
/* Fix up the colours if necessary. */ /* Fix up the colours if necessary. */
tty_check_fg(tty, palette, &gc2); tty_check_fg(tty, style_ctx->palette, &gc2);
tty_check_bg(tty, palette, &gc2); tty_check_bg(tty, style_ctx->palette, &gc2);
tty_check_us(tty, palette, &gc2); tty_check_us(tty, style_ctx->palette, &gc2);
/* /*
* If any bits are being cleared or the underline colour is now default, * If any bits are being cleared or the underline colour is now default,
@@ -2561,7 +2549,7 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc,
tty_putcode(tty, TTYC_SMACS); tty_putcode(tty, TTYC_SMACS);
/* Set hyperlink if any. */ /* Set hyperlink if any. */
tty_hyperlink(tty, gc, hl); tty_hyperlink(tty, gc, style_ctx->hyperlinks);
memcpy(&tty->last_cell, &gc2, sizeof tty->last_cell); memcpy(&tty->last_cell, &gc2, sizeof tty->last_cell);
} }
@@ -2583,8 +2571,9 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
*/ */
if (COLOUR_DEFAULT(gc->fg) || COLOUR_DEFAULT(gc->bg)) { if (COLOUR_DEFAULT(gc->fg) || COLOUR_DEFAULT(gc->bg)) {
/* /*
* If don't have AX, send sgr0. This resets both colours to default. * If don't have AX, send sgr0. This resets both colours to
* Otherwise, try to set the default colour only as needed. * default. Otherwise, try to set the default colour only as
* needed.
*/ */
if (!tty_term_flag(tty->term, TTYC_AX)) if (!tty_term_flag(tty->term, TTYC_AX))
tty_reset(tty); tty_reset(tty);
@@ -2950,14 +2939,14 @@ tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
} }
void void
tty_default_attributes(struct tty *tty, const struct grid_cell *defaults, tty_default_attributes(struct tty *tty, u_int bg,
struct colour_palette *palette, u_int bg, struct hyperlinks *hl) const struct tty_style_ctx *style_ctx)
{ {
struct grid_cell gc; struct grid_cell gc;
memcpy(&gc, &grid_default_cell, sizeof gc); memcpy(&gc, &grid_default_cell, sizeof gc);
gc.bg = bg; gc.bg = bg;
tty_attributes(tty, &gc, defaults, palette, hl); tty_attributes(tty, &gc, style_ctx);
} }
static void static void

View File

@@ -567,13 +567,8 @@ window_copy_add(struct window_pane *wp, int parse, const char *fmt, ...)
static void static void
window_copy_init_ctx_cb(__unused struct screen_write_ctx *ctx, window_copy_init_ctx_cb(__unused struct screen_write_ctx *ctx,
struct tty_ctx *ttyctx) __unused struct tty_ctx *ttyctx)
{ {
memcpy(&ttyctx->defaults, &grid_default_cell, sizeof ttyctx->defaults);
ttyctx->palette = NULL;
ttyctx->redraw_cb = NULL;
ttyctx->set_client_cb = NULL;
ttyctx->arg = NULL;
} }
void void