1
0
mirror of https://github.com/openbsd/src.git synced 2026-06-18 15:23:33 +02:00

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 22130f212a
commit a6cfdb8300
10 changed files with 135 additions and 135 deletions
+6 -5
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: cmd-display-panes.c,v 1.49 2026/06/08 20:42:39 nicm Exp $ */
/* $OpenBSD: cmd-display-panes.c,v 1.50 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -91,6 +91,7 @@ cmd_display_panes_draw_format(struct screen_redraw_ctx *ctx,
const char *format;
char *expanded;
u_int i, px = ctx->ox + xoff;
struct tty_style_ctx style_ctx = { .defaults = gc };
format = options_get_string(s->options, "display-panes-format");
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++) {
ri = &r->ranges[i];
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);
}
@@ -199,7 +200,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
llen = 0;
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) {
len += llen + 1;
cx = xoff + px - len / 2;
@@ -220,7 +221,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
px -= len * 3;
py -= 2;
tty_attributes(tty, &bgc, &grid_default_cell, NULL, NULL);
tty_attributes(tty, &bgc, NULL);
for (ptr = buf; *ptr != '\0'; ptr++) {
if (*ptr < '0' || *ptr > '9')
continue;
@@ -242,7 +243,7 @@ cmd_display_panes_draw_pane(struct screen_redraw_ctx *ctx,
goto out;
cmd_display_panes_draw_format(ctx, wp, xoff, yoff, sx, &fgc);
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;
cy = yoff + py + 5;
cmd_display_panes_put(ctx, wp, cx, cy, lbuf, llen);
+1 -3
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: cmd-kill-pane.c,v 1.33 2026/06/09 12:24:59 nicm Exp $ */
/* $OpenBSD: cmd-kill-pane.c,v 1.34 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -50,8 +50,6 @@ cmd_kill_pane_exec(struct cmd *self, struct cmdq_item *item)
{
struct args *args = cmd_get_args(self);
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;
const char *filter = args_get(args, 'f');
+3 -5
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: menu.c,v 1.63 2026/04/28 10:01:07 nicm Exp $ */
/* $OpenBSD: menu.c,v 1.64 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -281,10 +281,8 @@ menu_draw_cb(struct client *c, void *data,
&md->style_gc, &md->border_style_gc, &md->selected_style_gc);
screen_write_stop(&ctx);
for (i = 0; i < screen_size_y(&md->s); i++) {
tty_draw_line(tty, s, 0, i, menu->width + 4, px, py + i,
&grid_default_cell, NULL);
}
for (i = 0; i < screen_size_y(&md->s); i++)
tty_draw_line(tty, s, 0, i, menu->width + 4, px, py + i, NULL);
}
void
+11 -9
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: popup.c,v 1.68 2026/05/22 09:05:16 nicm Exp $ */
/* $OpenBSD: popup.c,v 1.69 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2020 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -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);
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->set_client_cb = popup_set_client_cb;
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_write_ctx ctx;
u_int i, px = pd->px, py = pd->py;
struct colour_palette *palette = &pd->palette;
struct grid_cell defaults;
struct tty_style_ctx style_ctx;
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);
if (defaults.fg == 8)
defaults.fg = palette->fg;
defaults.fg = pd->palette.fg;
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) {
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_data = NULL;
}
for (i = 0; i < pd->sy; i++) {
tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &defaults,
palette);
}
for (i = 0; i < pd->sy; i++)
tty_draw_line(tty, &s, 0, i, pd->sx, px, py + i, &style_ctx);
screen_free(&s);
if (pd->md != NULL) {
c->overlay_check = NULL;
+17 -16
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: screen-redraw.c,v 1.131 2026/06/02 08:13:50 nicm Exp $ */
/* $OpenBSD: screen-redraw.c,v 1.132 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -725,8 +725,7 @@ screen_redraw_draw_pane_status(struct screen_redraw_ctx *ctx)
if (ri->nx == 0)
continue;
tty_draw_line(tty, s, l + (ri->px - x), 0, ri->nx,
ri->px, yoff - ctx->oy,
&grid_default_cell, NULL);
ri->px, yoff - ctx->oy, NULL);
}
}
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);
tty_cell(tty, &gc, &grid_default_cell, NULL, NULL);
tty_cell(tty, &gc, NULL);
if (isolates)
tty_puts(tty, START_ISOLATE);
}
@@ -1104,10 +1103,8 @@ screen_redraw_draw_status(struct screen_redraw_ctx *ctx)
y = 0;
else
y = c->tty.sy - ctx->statuslines;
for (i = 0; i < ctx->statuslines; i++) {
tty_draw_line(tty, s, 0, i, UINT_MAX, 0, y + i,
&grid_default_cell, NULL);
}
for (i = 0; i < ctx->statuslines; i++)
tty_draw_line(tty, s, 0, i, UINT_MAX, 0, y + i, NULL);
}
/*
@@ -1302,6 +1299,7 @@ screen_redraw_draw_pane(struct screen_redraw_ctx *ctx, struct window_pane *wp)
struct screen *s = wp->screen;
struct colour_palette *palette = &wp->palette;
struct grid_cell defaults;
struct tty_style_ctx style_ctx;
u_int j, k, woy, wx, wy, py, width;
struct visible_ranges *r;
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;
}
/* 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. */
r = tty_check_overlay_range(tty, wx, wy, width);
r = screen_redraw_get_visible_ranges(wp, wx, wy, width, r);
tty_default_colours(&defaults, wp);
for (k = 0; k < r->used; k++) {
ri = &r->ranges[k];
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, py, ri->nx);
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 &&
i >= sb_w && i < sb_w + sb_pad) ||
(sb_pos == PANE_SCROLLBARS_RIGHT &&
i < sb_pad)) {
tty_cell(tty, &grid_default_cell,
&grid_default_cell, NULL, NULL);
} else {
i < sb_pad))
tty_cell(tty, &grid_default_cell, NULL);
else {
if (j >= slider_y && j < slider_y + slider_h)
gcp = &slgc;
else
gcp = &gc;
tty_cell(tty, gcp, &grid_default_cell, NULL,
NULL);
tty_cell(tty, gcp, NULL);
}
}
}
+11 -6
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: screen-write.c,v 1.265 2026/06/08 20:41:21 nicm Exp $ */
/* $OpenBSD: screen-write.c,v 1.266 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -219,7 +219,8 @@ static void
screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
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);
@@ -236,19 +237,23 @@ screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx,
ttyctx->flags |= TTY_CTX_PANE_OBSCURED;
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) {
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)
ttyctx->defaults.fg = ttyctx->palette->fg;
ttyctx->defaults.fg = palette->fg;
if (ttyctx->defaults.bg == 8)
ttyctx->defaults.bg = ttyctx->palette->bg;
ttyctx->defaults.bg = palette->bg;
}
} else {
ttyctx->redraw_cb = screen_write_redraw_cb;
if (ctx->wp != NULL) {
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->arg = ctx->wp;
}
+17 -12
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: tmux.h,v 1.1340 2026/06/09 09:11:05 nicm Exp $ */
/* $OpenBSD: tmux.h,v 1.1341 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -1610,6 +1610,13 @@ struct 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. */
struct tty {
struct client *client;
@@ -1753,7 +1760,7 @@ struct tty_ctx {
/* The default colours and palette. */
struct grid_cell defaults;
struct colour_palette *palette;
struct tty_style_ctx style_ctx;
/* Containing region (usually window) offset and size. */
u_int wox;
@@ -2621,6 +2628,10 @@ void environ_push(struct environ *);
void printflike(2, 3) environ_log(struct environ *, const char *, ...);
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 */
void tty_create_log(void);
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_raw(struct tty *, const char *);
void tty_attributes(struct tty *, const struct grid_cell *,
const struct grid_cell *, struct colour_palette *,
struct hyperlinks *);
const struct tty_style_ctx *);
void tty_reset(struct tty *);
void tty_region_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_putn(struct tty *, const void *, size_t, u_int);
void tty_cell(struct tty *, const struct grid_cell *,
const struct grid_cell *, struct colour_palette *,
struct hyperlinks *);
const struct tty_style_ctx *);
int tty_init(struct tty *, struct client *);
void tty_resize(struct tty *);
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_path(struct tty *, const char *);
void tty_set_progress_bar(struct tty *, struct progress_bar *);
void tty_default_attributes(struct tty *, const struct grid_cell *,
struct colour_palette *, u_int, struct hyperlinks *);
void tty_default_attributes(struct tty *, u_int,
const struct tty_style_ctx *);
void tty_update_mode(struct tty *, int, struct screen *);
const struct grid_cell *tty_check_codeset(struct tty *,
const struct grid_cell *);
struct visible_ranges *tty_check_overlay_range(struct tty *, 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_end(struct tty *);
int tty_open(struct tty *, char **);
+22 -16
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: tty-draw.c,v 1.10 2026/05/27 20:47:23 nicm Exp $ */
/* $OpenBSD: tty-draw.c,v 1.11 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2026 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -22,6 +22,7 @@
#include "tmux.h"
/* Current state when drawing line. */
enum tty_draw_line_state {
TTY_DRAW_LINE_FIRST,
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. */
void
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,
struct colour_palette *palette)
u_int atx, u_int aty, const struct tty_style_ctx *style_ctx)
{
struct grid *gd = s->grid;
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];
size_t len;
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
@@ -130,8 +138,8 @@ tty_draw_line(struct tty *tty, struct screen *s, u_int px, u_int py, u_int nx,
else
ex = screen_size_x(s);
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,
defaults->bg);
"bg=%d", __func__, px, px + nx, py, ex, atx, aty,
style_ctx->defaults->fg, style_ctx->defaults->bg);
/* Turn off cursor while redrawing and reset region and margins. */
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. */
memcpy(&last, &grid_default_cell, sizeof last);
last.bg = defaults->bg;
tty_default_attributes(tty, defaults, palette, 8, s->hyperlinks);
last.bg = style_ctx->defaults->bg;
tty_default_attributes(tty, 8, style_ctx);
/*
* 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;
}
if (i == 0)
bg = defaults->bg;
bg = style_ctx->defaults->bg;
else {
bg = gc.bg;
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;
}
}
tty_attributes(tty, &last, defaults, palette, s->hyperlinks);
tty_attributes(tty, &last, style_ctx);
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)
goto out;
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 (next_state != current_state) {
if (current_state == TTY_DRAW_LINE_EMPTY) {
tty_attributes(tty, &last, defaults, palette,
s->hyperlinks);
tty_attributes(tty, &last, style_ctx);
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;
} else if (next_state != TTY_DRAW_LINE_SAME &&
len != 0) {
tty_attributes(tty, &last, defaults, palette,
s->hyperlinks);
tty_attributes(tty, &last, style_ctx);
if (atx + i - width != 0 || !wrapped)
tty_cursor(tty, atx + i - width, aty);
if (~last.attr & GRID_ATTR_CHARSET)
@@ -322,4 +329,3 @@ out:
tty->flags = (tty->flags & ~TTY_NOCURSOR)|flags;
tty_update_mode(tty, tty->mode, s);
}
+45 -56
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: tty.c,v 1.470 2026/06/09 11:49:36 nicm Exp $ */
/* $OpenBSD: tty.c,v 1.471 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -79,6 +79,10 @@ static int tty_check_overlay(struct tty *, u_int, u_int);
#define TTY_QUERY_TIMEOUT 5
#define TTY_REQUEST_LIMIT 30
static struct tty_style_ctx tty_default_style_ctx = {
&grid_default_cell, NULL, NULL
};
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)
continue;
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;
}
@@ -1421,7 +1425,7 @@ tty_draw_pane(struct tty *tty, const struct tty_ctx *ctx, u_int py)
if (rr->nx == 0)
continue;
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;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
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;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
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
tty_cmd_clearcharacter(struct tty *tty, const struct tty_ctx *ctx)
{
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
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;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_off(tty);
@@ -1663,8 +1663,7 @@ tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx)
return;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_off(tty);
@@ -1677,8 +1676,7 @@ tty_cmd_deleteline(struct tty *tty, const struct tty_ctx *ctx)
void
tty_cmd_clearline(struct tty *tty, const struct tty_ctx *ctx)
{
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
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;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
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
tty_cmd_clearstartofline(struct tty *tty, const struct tty_ctx *ctx)
{
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
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;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_pane(tty, ctx);
@@ -1756,8 +1751,7 @@ tty_cmd_linefeed(struct tty *tty, const struct tty_ctx *ctx)
return;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_pane(tty, ctx);
@@ -1797,8 +1791,7 @@ tty_cmd_scrollup(struct tty *tty, const struct tty_ctx *ctx)
return;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
tty_margin_pane(tty, ctx);
@@ -1838,8 +1831,7 @@ tty_cmd_scrolldown(struct tty *tty, const struct tty_ctx *ctx)
return;
}
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, ctx->orupper, ctx->orlower);
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;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, 0, ctx->sy - 1);
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;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, 0, ctx->sy - 1);
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;
tty_default_attributes(tty, &ctx->defaults, ctx->palette, ctx->bg,
ctx->s->hyperlinks);
tty_default_attributes(tty, ctx->bg, &ctx->style_ctx);
tty_region_pane(tty, ctx, 0, ctx->sy - 1);
tty_margin_off(tty);
@@ -1934,8 +1923,7 @@ tty_cmd_alignmenttest(struct tty *tty, const struct tty_ctx *ctx)
return;
}
tty_attributes(tty, &grid_default_cell, &ctx->defaults, ctx->palette,
ctx->s->hyperlinks);
tty_attributes(tty, &grid_default_cell, &ctx->style_ctx);
tty_region_pane(tty, ctx, 0, ctx->sy - 1);
tty_margin_off(tty);
@@ -1968,7 +1956,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
vis += r->ranges[i].nx;
if (vis < 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;
}
}
@@ -1983,8 +1971,7 @@ tty_cmd_cell(struct tty *tty, const struct tty_ctx *ctx)
tty_invalidate(tty);
tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
tty_cell(tty, ctx->cell, &ctx->defaults, ctx->palette,
ctx->s->hyperlinks);
tty_cell(tty, ctx->cell, &ctx->style_ctx);
if (ctx->flags & TTY_CTX_CELL_INVALIDATE)
tty_invalidate(tty);
@@ -2020,8 +2007,7 @@ tty_cmd_cells(struct tty *tty, const struct tty_ctx *ctx)
tty_margin_off(tty);
tty_cursor_pane_unless_wrap(tty, ctx, ctx->ocx, ctx->ocy);
tty_attributes(tty, ctx->cell, &ctx->defaults, ctx->palette,
ctx->s->hyperlinks);
tty_attributes(tty, ctx->cell, &ctx->style_ctx);
/* Get tty position from pane position for overlay check. */
px = ctx->xoff + ctx->ocx - ctx->wox;
@@ -2098,8 +2084,7 @@ tty_cmd_syncstart(struct tty *tty, const struct tty_ctx *ctx)
void
tty_cell(struct tty *tty, const struct grid_cell *gc,
const struct grid_cell *defaults, struct colour_palette *palette,
struct hyperlinks *hl)
const struct tty_style_ctx *style_ctx)
{
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. */
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 (gcp->data.size == 1) {
@@ -2464,19 +2449,22 @@ tty_hyperlink(struct tty *tty, const struct grid_cell *gc,
void
tty_attributes(struct tty *tty, const struct grid_cell *gc,
const struct grid_cell *defaults, struct colour_palette *palette,
struct hyperlinks *hl)
const struct tty_style_ctx *style_ctx)
{
struct grid_cell *tc = &tty->cell, gc2;
int changed;
/* Use default style if not given. */
if (style_ctx == NULL)
style_ctx = &tty_default_style_ctx;
/* Copy cell and update default colours. */
memcpy(&gc2, gc, sizeof gc2);
if (~gc->flags & GRID_FLAG_NOPALETTE) {
if (gc2.fg == 8)
gc2.fg = defaults->fg;
gc2.fg = style_ctx->defaults->fg;
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. */
@@ -2503,9 +2491,9 @@ tty_attributes(struct tty *tty, const struct grid_cell *gc,
}
/* Fix up the colours if necessary. */
tty_check_fg(tty, palette, &gc2);
tty_check_bg(tty, palette, &gc2);
tty_check_us(tty, palette, &gc2);
tty_check_fg(tty, style_ctx->palette, &gc2);
tty_check_bg(tty, style_ctx->palette, &gc2);
tty_check_us(tty, style_ctx->palette, &gc2);
/*
* 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);
/* 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);
}
@@ -2583,8 +2571,9 @@ tty_colours(struct tty *tty, const struct grid_cell *gc)
*/
if (COLOUR_DEFAULT(gc->fg) || COLOUR_DEFAULT(gc->bg)) {
/*
* If don't have AX, send sgr0. This resets both colours to default.
* Otherwise, try to set the default colour only as needed.
* If don't have AX, send sgr0. This resets both colours to
* default. Otherwise, try to set the default colour only as
* needed.
*/
if (!tty_term_flag(tty->term, TTYC_AX))
tty_reset(tty);
@@ -2950,14 +2939,14 @@ tty_default_colours(struct grid_cell *gc, struct window_pane *wp)
}
void
tty_default_attributes(struct tty *tty, const struct grid_cell *defaults,
struct colour_palette *palette, u_int bg, struct hyperlinks *hl)
tty_default_attributes(struct tty *tty, u_int bg,
const struct tty_style_ctx *style_ctx)
{
struct grid_cell gc;
memcpy(&gc, &grid_default_cell, sizeof gc);
gc.bg = bg;
tty_attributes(tty, &gc, defaults, palette, hl);
tty_attributes(tty, &gc, style_ctx);
}
static void
+2 -7
View File
@@ -1,4 +1,4 @@
/* $OpenBSD: window-copy.c,v 1.402 2026/06/04 09:24:03 nicm Exp $ */
/* $OpenBSD: window-copy.c,v 1.403 2026/06/09 21:22:22 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -567,13 +567,8 @@ window_copy_add(struct window_pane *wp, int parse, const char *fmt, ...)
static void
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