summaryrefslogtreecommitdiffstats
path: root/screen-write.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2009-07-22 20:53:38 +0000
committerNicholas Marriott <nicm@openbsd.org>2009-07-22 20:53:38 +0000
commitddad0be5f773978c09e7c86ad79596ce7af9ec71 (patch)
tree31ca49deb0c7507e96dd2cc470e8ebc12afaed87 /screen-write.c
parentbb4bab4c262f3b7b8bc2df8857b417a229c595e1 (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 'screen-write.c')
-rw-r--r--screen-write.c108
1 files changed, 67 insertions, 41 deletions
diff --git a/screen-write.c b/screen-write.c
index 2f41ae55..e2fbfbf4 100644
--- a/screen-write.c
+++ b/screen-write.c
@@ -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;