diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-02-08 15:41:42 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2017-02-08 15:41:42 +0000 |
commit | 73398c7a75663b62be63630bcdc112ff563ca29b (patch) | |
tree | 0258671812fa1d451be696fafda20bd16fec4eb6 /usr.bin | |
parent | 0cb4121c9ba9d94a6bb34df14f6805fa6f948936 (diff) |
Add a helper to store a cell, and some tidying.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/grid.c | 40 | ||||
-rw-r--r-- | usr.bin/tmux/screen-redraw.c | 5 | ||||
-rw-r--r-- | usr.bin/tmux/screen-write.c | 71 |
3 files changed, 65 insertions, 51 deletions
diff --git a/usr.bin/tmux/grid.c b/usr.bin/tmux/grid.c index ff1ac8dba93..829205e44ad 100644 --- a/usr.bin/tmux/grid.c +++ b/usr.bin/tmux/grid.c @@ -1,4 +1,4 @@ -/* $OpenBSD: grid.c,v 1.62 2017/02/08 08:26:35 nicm Exp $ */ +/* $OpenBSD: grid.c,v 1.63 2017/02/08 15:41:41 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -59,6 +59,25 @@ static size_t grid_string_cells_bg(const struct grid_cell *, int *); static void grid_string_cells_code(const struct grid_cell *, const struct grid_cell *, char *, size_t, int); +/* Store cell in entry. */ +static void +grid_store_cell(struct grid_cell_entry *gce, const struct grid_cell *gc, + u_char c) +{ + gce->flags = gc->flags; + + gce->data.fg = gc->fg & 0xff; + if (gc->fg & COLOUR_FLAG_256) + gce->flags |= GRID_FLAG_FG256; + + gce->data.bg = gc->bg & 0xff; + if (gc->bg & COLOUR_FLAG_256) + gce->flags |= GRID_FLAG_BG256; + + gce->data.attr = gc->attr; + gce->data.data = c; +} + /* Set cell as extended. */ static struct grid_cell * grid_extended_cell(struct grid_line *gl, struct grid_cell_entry *gce, @@ -371,11 +390,10 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc) grid_expand_line(gd, py, px + 1, 8); gl = &gd->linedata[py]; - gce = &gl->celldata[px]; - if (px + 1 > gl->cellused) gl->cellused = px + 1; + gce = &gl->celldata[px]; extended = (gce->flags & GRID_FLAG_EXTENDED); if (!extended && (gc->data.size != 1 || gc->data.width != 1)) extended = 1; @@ -383,20 +401,10 @@ grid_set_cell(struct grid *gd, u_int px, u_int py, const struct grid_cell *gc) extended = 1; if (!extended && (gc->bg & COLOUR_FLAG_RGB)) extended = 1; - if (extended) { + if (extended) grid_extended_cell(gl, gce, gc); - return; - } - - gce->flags = gc->flags; - gce->data.attr = gc->attr; - gce->data.fg = gc->fg & 0xff; - if (gc->fg & COLOUR_FLAG_256) - gce->flags |= GRID_FLAG_FG256; - gce->data.bg = gc->bg & 0xff; - if (gc->bg & COLOUR_FLAG_256) - gce->flags |= GRID_FLAG_BG256; - gce->data.data = gc->data.data[0]; + else + grid_store_cell(gce, gc, gc->data.data[0]); } /* Clear area. */ diff --git a/usr.bin/tmux/screen-redraw.c b/usr.bin/tmux/screen-redraw.c index 1eec2029205..e7fd2f078c6 100644 --- a/usr.bin/tmux/screen-redraw.c +++ b/usr.bin/tmux/screen-redraw.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-redraw.c,v 1.43 2017/02/03 11:57:27 nicm Exp $ */ +/* $OpenBSD: screen-redraw.c,v 1.44 2017/02/08 15:41:41 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -423,6 +423,9 @@ screen_redraw_pane(struct client *c, struct window_pane *wp) if (status_at_line(c) == 0) yoff++; + log_debug("%s: redraw pane %%%u (at %u,%u)", c->tty.path, wp->id, + wp->xoff, yoff); + for (i = 0; i < wp->sy; i++) tty_draw_pane(&c->tty, wp, i, wp->xoff, yoff); tty_reset(&c->tty); diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c index 8d11b52416b..733d8a3c989 100644 --- a/usr.bin/tmux/screen-write.c +++ b/usr.bin/tmux/screen-write.c @@ -1,4 +1,4 @@ -/* $OpenBSD: screen-write.c,v 1.106 2017/02/08 08:50:10 nicm Exp $ */ +/* $OpenBSD: screen-write.c,v 1.107 2017/02/08 15:41:41 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -604,14 +604,16 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg) if (nx == 0) return; + if (s->cx > screen_size_x(s) - 1) + return; + screen_write_flush(ctx); screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; - if (s->cx <= screen_size_x(s) - 1) - grid_view_insert_cells(s->grid, s->cx, s->cy, nx, bg); + grid_view_insert_cells(s->grid, s->cx, s->cy, nx, bg); ttyctx.num = nx; - ttyctx.bg = bg; tty_write(tty_cmd_insertcharacter, &ttyctx); } @@ -630,14 +632,16 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg) if (nx == 0) return; + if (s->cx > screen_size_x(s) - 1) + return; + screen_write_flush(ctx); screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; - if (s->cx <= screen_size_x(s) - 1) - grid_view_delete_cells(s->grid, s->cx, s->cy, nx, bg); + grid_view_delete_cells(s->grid, s->cx, s->cy, nx, bg); ttyctx.num = nx; - ttyctx.bg = bg; tty_write(tty_cmd_deletecharacter, &ttyctx); } @@ -656,13 +660,13 @@ screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx) if (nx == 0) return; + if (s->cx > screen_size_x(s) - 1) + return; + screen_write_initctx(ctx, &ttyctx); - if (s->cx <= screen_size_x(s) - 1) { - screen_dirty_clear(s, s->cx, s->cy, s->cx + nx - 1, s->cy); - grid_view_clear(s->grid, s->cx, s->cy, nx, 1, 8); - } else - return; + screen_dirty_clear(s, s->cx, s->cy, s->cx + nx - 1, s->cy); + grid_view_clear(s->grid, s->cx, s->cy, nx, 1, 8); ttyctx.num = nx; tty_write(tty_cmd_clearcharacter, &ttyctx); @@ -673,6 +677,7 @@ void screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg) { struct screen *s = ctx->s; + struct grid *gd = s->grid; struct tty_ctx ttyctx; if (ny == 0) @@ -686,11 +691,11 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg) screen_write_flush(ctx); screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; - grid_view_insert_lines(s->grid, s->cy, ny, bg); + grid_view_insert_lines(gd, s->cy, ny, bg); ttyctx.num = ny; - ttyctx.bg = bg; tty_write(tty_cmd_insertline, &ttyctx); return; } @@ -702,16 +707,14 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg) screen_write_flush(ctx); screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; if (s->cy < s->rupper || s->cy > s->rlower) - grid_view_insert_lines(s->grid, s->cy, ny, bg); - else { - grid_view_insert_lines_region(s->grid, s->rlower, s->cy, ny, - bg); - } + grid_view_insert_lines(gd, s->cy, ny, bg); + else + grid_view_insert_lines_region(gd, s->rlower, s->cy, ny, bg); ttyctx.num = ny; - ttyctx.bg = bg; tty_write(tty_cmd_insertline, &ttyctx); } @@ -720,6 +723,7 @@ void screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg) { struct screen *s = ctx->s; + struct grid *gd = s->grid; struct tty_ctx ttyctx; if (ny == 0) @@ -733,11 +737,11 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg) screen_write_flush(ctx); screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; - grid_view_delete_lines(s->grid, s->cy, ny, bg); + grid_view_delete_lines(gd, s->cy, ny, bg); ttyctx.num = ny; - ttyctx.bg = bg; tty_write(tty_cmd_deleteline, &ttyctx); return; } @@ -749,16 +753,14 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg) screen_write_flush(ctx); screen_write_initctx(ctx, &ttyctx); + ttyctx.bg = bg; if (s->cy < s->rupper || s->cy > s->rlower) - grid_view_delete_lines(s->grid, s->cy, ny, bg); - else { - grid_view_delete_lines_region(s->grid, s->rlower, s->cy, ny, - bg); - } + grid_view_delete_lines(gd, s->cy, ny, bg); + else + grid_view_delete_lines_region(gd, s->rlower, s->cy, ny, bg); ttyctx.num = ny; - ttyctx.bg = bg; tty_write(tty_cmd_deleteline, &ttyctx); } @@ -925,6 +927,7 @@ void screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg) { struct screen *s = ctx->s; + struct grid *gd = s->grid; struct tty_ctx ttyctx; u_int sx = screen_size_x(s), sy = screen_size_y(s); @@ -932,18 +935,16 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg) ttyctx.bg = bg; /* Scroll into history if it is enabled and clearing entire screen. */ - if (s->cx == 0 && s->cy == 0 && s->grid->flags & GRID_HISTORY) { + if (s->cx == 0 && s->cy == 0 && gd->flags & GRID_HISTORY) { screen_dirty_clear(s, 0, 0, sx - 1, sy - 1); - grid_view_clear_history(s->grid, bg); + grid_view_clear_history(gd, bg); } else { if (s->cx <= sx - 1) { screen_dirty_clear(s, s->cx, s->cy, sx - 1, s->cy); - grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1, - bg); + grid_view_clear(gd, s->cx, s->cy, sx - s->cx, 1, bg); } screen_dirty_clear(s, 0, s->cy + 1, sx - 1, sy - 1); - grid_view_clear(s->grid, 0, s->cy + 1, sx, sy - (s->cy + 1), - bg); + grid_view_clear(gd, 0, s->cy + 1, sx, sy - (s->cy + 1), bg); } tty_write(tty_cmd_clearendofscreen, &ttyctx); @@ -1277,6 +1278,7 @@ screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc, return (done); } +/* Set external clipboard. */ void screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len) { @@ -1289,6 +1291,7 @@ screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len) tty_write(tty_cmd_setselection, &ttyctx); } +/* Write unmodified string. */ void screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len) { |