summaryrefslogtreecommitdiff
path: root/usr.bin/tmux/screen-write.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2009-07-22 20:53:39 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2009-07-22 20:53:39 +0000
commita863befefddbb0946b94179c2685e6e7479effdd (patch)
tree8bc2b74225e7cf046a69a5961ec7ae1e65e0e2a6 /usr.bin/tmux/screen-write.c
parenta0af3b9ce9dd36f4efe8b903dc7d7ccd25647a45 (diff)
More tty code tidying: move the saved cursor/region position (from before the
screen was updated) out of struct screen and into struct tty_ctx.
Diffstat (limited to 'usr.bin/tmux/screen-write.c')
-rw-r--r--usr.bin/tmux/screen-write.c110
1 files changed, 68 insertions, 42 deletions
diff --git a/usr.bin/tmux/screen-write.c b/usr.bin/tmux/screen-write.c
index 7582f707146..02a523d3d25 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.16 2009/07/22 18:02:23 nicm Exp $ */
+/* $OpenBSD: screen-write.c,v 1.17 2009/07/22 20:53:38 nicm Exp $ */
/*
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -22,7 +22,7 @@
#include "tmux.h"
-void screen_write_save(struct screen_write_ctx *);
+void screen_write_initctx(struct screen_write_ctx *, struct tty_ctx *);
void screen_write_overwrite(struct screen_write_ctx *);
/* Initialise writing with a window. */
@@ -210,17 +210,19 @@ screen_write_copy(struct screen_write_ctx *ctx,
}
}
-/* Save cursor and region positions. */
+/* Set up context for TTY command. */
void
-screen_write_save(struct screen_write_ctx *ctx)
+screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx)
{
struct screen *s = ctx->s;
- s->old_cx = s->cx;
- s->old_cy = s->cy;
+ ttyctx->wp = ctx->wp;
- s->old_rlower = s->rlower;
- s->old_rupper = s->rupper;
+ ttyctx->ocx = s->cx;
+ ttyctx->ocy = s->cy;
+
+ ttyctx->orlower = s->rlower;
+ ttyctx->orupper = s->rupper;
}
/* Cursor up by ny. */
@@ -310,9 +312,12 @@ void
screen_write_alignmenttest(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
struct grid_cell gc;
u_int xx, yy;
+ screen_write_initctx(ctx, &ttyctx);
+
memcpy(&gc, &grid_default_cell, sizeof gc);
gc.data = 'E';
@@ -327,7 +332,7 @@ screen_write_alignmenttest(struct screen_write_ctx *ctx)
s->rupper = 0;
s->rlower = screen_size_y(s) - 1;
- tty_write0(ctx->wp, tty_cmd_alignmenttest);
+ tty_write(tty_cmd_alignmenttest, &ttyctx);
}
/* Insert nx characters. */
@@ -335,6 +340,7 @@ void
screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
if (nx == 0)
nx = 1;
@@ -344,12 +350,13 @@ screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx)
if (nx == 0)
return;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
if (s->cx <= screen_size_x(s) - 1)
grid_view_insert_cells(s->grid, s->cx, s->cy, nx);
- tty_writenum(ctx->wp, tty_cmd_insertcharacter, nx);
+ ttyctx.num = nx;
+ tty_write(tty_cmd_insertcharacter, &ttyctx);
}
/* Delete nx characters. */
@@ -357,6 +364,7 @@ void
screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
if (nx == 0)
nx = 1;
@@ -366,12 +374,13 @@ screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx)
if (nx == 0)
return;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
if (s->cx <= screen_size_x(s) - 1)
grid_view_delete_cells(s->grid, s->cx, s->cy, nx);
- tty_writenum(ctx->wp, tty_cmd_deletecharacter, nx);
+ ttyctx.num = nx;
+ tty_write(tty_cmd_deletecharacter, &ttyctx);
}
/* Insert ny lines. */
@@ -379,6 +388,7 @@ void
screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
if (ny == 0)
ny = 1;
@@ -389,11 +399,12 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
if (ny == 0)
return;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
grid_view_insert_lines(s->grid, s->cy, ny);
- tty_writenum(ctx->wp, tty_cmd_insertline, ny);
+ ttyctx.num = ny;
+ tty_write(tty_cmd_insertline, &ttyctx);
return;
}
@@ -402,14 +413,15 @@ screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
if (ny == 0)
return;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
if (s->cy < s->rupper || s->cy > s->rlower)
grid_view_insert_lines(s->grid, s->cy, ny);
else
grid_view_insert_lines_region(s->grid, s->rlower, s->cy, ny);
- tty_writenum(ctx->wp, tty_cmd_insertline, ny);
+ ttyctx.num = ny;
+ tty_write(tty_cmd_insertline, &ttyctx);
}
/* Delete ny lines. */
@@ -417,6 +429,7 @@ void
screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
if (ny == 0)
ny = 1;
@@ -427,11 +440,12 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
if (ny == 0)
return;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
grid_view_delete_lines(s->grid, s->cy, ny);
- tty_writenum(ctx->wp, tty_cmd_deleteline, ny);
+ ttyctx.num = ny;
+ tty_write(tty_cmd_deleteline, &ttyctx);
return;
}
@@ -440,14 +454,15 @@ screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
if (ny == 0)
return;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
if (s->cy < s->rupper || s->cy > s->rlower)
grid_view_delete_lines(s->grid, s->cy, ny);
else
grid_view_delete_lines_region(s->grid, s->rlower, s->cy, ny);
- tty_writenum(ctx->wp, tty_cmd_deleteline, ny);
+ ttyctx.num = ny;
+ tty_write(tty_cmd_deleteline, &ttyctx);
}
/* Clear line at cursor. */
@@ -455,12 +470,13 @@ void
screen_write_clearline(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
grid_view_clear(s->grid, 0, s->cy, screen_size_x(s), 1);
- tty_write0(ctx->wp, tty_cmd_clearline);
+ tty_write(tty_cmd_clearline, &ttyctx);
}
/* Clear to end of line from cursor. */
@@ -468,16 +484,17 @@ void
screen_write_clearendofline(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
u_int sx;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
sx = screen_size_x(s);
if (s->cx <= sx - 1)
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
- tty_write0(ctx->wp, tty_cmd_clearendofline);
+ tty_write(tty_cmd_clearendofline, &ttyctx);
}
/* Clear to start of line from cursor. */
@@ -485,9 +502,10 @@ void
screen_write_clearstartofline(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
u_int sx;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
sx = screen_size_x(s);
@@ -496,7 +514,7 @@ screen_write_clearstartofline(struct screen_write_ctx *ctx)
else
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
- tty_write0(ctx->wp, tty_cmd_clearstartofline);
+ tty_write(tty_cmd_clearstartofline, &ttyctx);
}
/* Move cursor to px,py. */
@@ -531,15 +549,16 @@ void
screen_write_reverseindex(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
if (s->cy == s->rupper)
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower);
else if (s->cy > 0)
s->cy--;
- tty_write0(ctx->wp, tty_cmd_reverseindex);
+ tty_write(tty_cmd_reverseindex, &ttyctx);
}
/* Set scroll region. */
@@ -593,15 +612,16 @@ void
screen_write_linefeed(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
if (s->cy == s->rlower)
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower);
else if (s->cy < screen_size_y(s) - 1)
s->cy++;
- tty_write0(ctx->wp, tty_cmd_linefeed);
+ tty_write(tty_cmd_linefeed, &ttyctx);
}
/* Carriage return (cursor to start of line). */
@@ -642,9 +662,10 @@ void
screen_write_clearendofscreen(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
u_int sx, sy;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
sx = screen_size_x(s);
sy = screen_size_y(s);
@@ -653,7 +674,7 @@ screen_write_clearendofscreen(struct screen_write_ctx *ctx)
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
grid_view_clear(s->grid, 0, s->cy + 1, sx, sy - (s->cy + 1));
- tty_write0(ctx->wp, tty_cmd_clearendofscreen);
+ tty_write(tty_cmd_clearendofscreen, &ttyctx);
}
/* Clear to start of screen. */
@@ -661,9 +682,10 @@ void
screen_write_clearstartofscreen(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
u_int sx;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
sx = screen_size_x(s);
@@ -674,7 +696,7 @@ screen_write_clearstartofscreen(struct screen_write_ctx *ctx)
else
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
- tty_write0(ctx->wp, tty_cmd_clearstartofscreen);
+ tty_write(tty_cmd_clearstartofscreen, &ttyctx);
}
/* Clear entire screen. */
@@ -682,12 +704,13 @@ void
screen_write_clearscreen(struct screen_write_ctx *ctx)
{
struct screen *s = ctx->s;
+ struct tty_ctx ttyctx;
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
grid_view_clear(s->grid, 0, 0, screen_size_x(s), screen_size_y(s));
- tty_write0(ctx->wp, tty_cmd_clearscreen);
+ tty_write(tty_cmd_clearscreen, &ttyctx);
}
/* Write cell data. */
@@ -737,7 +760,9 @@ screen_write_cell(
memcpy(tmp_gu->data + i, udata, UTF8_SIZE - i);
/* Assume the previous character has just been input. */
- tty_writeptr(ctx->wp, tty_cmd_utf8character, udata);
+ screen_write_initctx(ctx, &ttyctx);
+ ttyctx.ptr = udata;
+ tty_write(tty_cmd_utf8character, &ttyctx);
return;
}
@@ -785,13 +810,14 @@ screen_write_cell(
grid_view_set_utf8(gd, s->cx, s->cy, &gu);
/* Move the cursor. */
- screen_write_save(ctx);
+ screen_write_initctx(ctx, &ttyctx);
s->cx += width;
/* Draw to the screen if necessary. */
- if (insert)
- tty_writenum(ctx->wp, tty_cmd_insertcharacter, width);
- ttyctx.wp = ctx->wp;
+ if (insert) {
+ ttyctx.num = width;
+ tty_write(tty_cmd_insertcharacter, &ttyctx);
+ }
ttyctx.utf8 = &gu;
if (screen_check_selection(s, s->cx - width, s->cy)) {
s->sel.cell.data = gc->data;