version 1.16, 2009/07/22 18:02:23 |
version 1.17, 2009/07/22 20:53:38 |
|
|
|
|
#include "tmux.h" |
#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 *); |
void screen_write_overwrite(struct screen_write_ctx *); |
|
|
/* Initialise writing with a window. */ |
/* Initialise writing with a window. */ |
|
|
} |
} |
} |
} |
|
|
/* Save cursor and region positions. */ |
/* Set up context for TTY command. */ |
void |
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; |
struct screen *s = ctx->s; |
|
|
s->old_cx = s->cx; |
ttyctx->wp = ctx->wp; |
s->old_cy = s->cy; |
|
|
|
s->old_rlower = s->rlower; |
ttyctx->ocx = s->cx; |
s->old_rupper = s->rupper; |
ttyctx->ocy = s->cy; |
|
|
|
ttyctx->orlower = s->rlower; |
|
ttyctx->orupper = s->rupper; |
} |
} |
|
|
/* Cursor up by ny. */ |
/* Cursor up by ny. */ |
|
|
screen_write_alignmenttest(struct screen_write_ctx *ctx) |
screen_write_alignmenttest(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
struct grid_cell gc; |
struct grid_cell gc; |
u_int xx, yy; |
u_int xx, yy; |
|
|
|
screen_write_initctx(ctx, &ttyctx); |
|
|
memcpy(&gc, &grid_default_cell, sizeof gc); |
memcpy(&gc, &grid_default_cell, sizeof gc); |
gc.data = 'E'; |
gc.data = 'E'; |
|
|
|
|
s->rupper = 0; |
s->rupper = 0; |
s->rlower = screen_size_y(s) - 1; |
s->rlower = screen_size_y(s) - 1; |
|
|
tty_write0(ctx->wp, tty_cmd_alignmenttest); |
tty_write(tty_cmd_alignmenttest, &ttyctx); |
} |
} |
|
|
/* Insert nx characters. */ |
/* Insert nx characters. */ |
|
|
screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx) |
screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
|
|
if (nx == 0) |
if (nx == 0) |
nx = 1; |
nx = 1; |
|
|
if (nx == 0) |
if (nx == 0) |
return; |
return; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
if (s->cx <= screen_size_x(s) - 1) |
if (s->cx <= screen_size_x(s) - 1) |
grid_view_insert_cells(s->grid, s->cx, s->cy, nx); |
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. */ |
/* Delete nx characters. */ |
|
|
screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx) |
screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
|
|
if (nx == 0) |
if (nx == 0) |
nx = 1; |
nx = 1; |
|
|
if (nx == 0) |
if (nx == 0) |
return; |
return; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
if (s->cx <= screen_size_x(s) - 1) |
if (s->cx <= screen_size_x(s) - 1) |
grid_view_delete_cells(s->grid, s->cx, s->cy, nx); |
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. */ |
/* Insert ny lines. */ |
|
|
screen_write_insertline(struct screen_write_ctx *ctx, u_int ny) |
screen_write_insertline(struct screen_write_ctx *ctx, u_int ny) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
|
|
if (ny == 0) |
if (ny == 0) |
ny = 1; |
ny = 1; |
|
|
if (ny == 0) |
if (ny == 0) |
return; |
return; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
grid_view_insert_lines(s->grid, s->cy, ny); |
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; |
return; |
} |
} |
|
|
|
|
if (ny == 0) |
if (ny == 0) |
return; |
return; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
if (s->cy < s->rupper || s->cy > s->rlower) |
if (s->cy < s->rupper || s->cy > s->rlower) |
grid_view_insert_lines(s->grid, s->cy, ny); |
grid_view_insert_lines(s->grid, s->cy, ny); |
else |
else |
grid_view_insert_lines_region(s->grid, s->rlower, s->cy, ny); |
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. */ |
/* Delete ny lines. */ |
|
|
screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny) |
screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
|
|
if (ny == 0) |
if (ny == 0) |
ny = 1; |
ny = 1; |
|
|
if (ny == 0) |
if (ny == 0) |
return; |
return; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
grid_view_delete_lines(s->grid, s->cy, ny); |
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; |
return; |
} |
} |
|
|
|
|
if (ny == 0) |
if (ny == 0) |
return; |
return; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
if (s->cy < s->rupper || s->cy > s->rlower) |
if (s->cy < s->rupper || s->cy > s->rlower) |
grid_view_delete_lines(s->grid, s->cy, ny); |
grid_view_delete_lines(s->grid, s->cy, ny); |
else |
else |
grid_view_delete_lines_region(s->grid, s->rlower, s->cy, ny); |
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. */ |
/* Clear line at cursor. */ |
|
|
screen_write_clearline(struct screen_write_ctx *ctx) |
screen_write_clearline(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
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); |
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. */ |
/* Clear to end of line from cursor. */ |
|
|
screen_write_clearendofline(struct screen_write_ctx *ctx) |
screen_write_clearendofline(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
u_int sx; |
u_int sx; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
sx = screen_size_x(s); |
sx = screen_size_x(s); |
|
|
if (s->cx <= sx - 1) |
if (s->cx <= sx - 1) |
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 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. */ |
/* Clear to start of line from cursor. */ |
|
|
screen_write_clearstartofline(struct screen_write_ctx *ctx) |
screen_write_clearstartofline(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
u_int sx; |
u_int sx; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
sx = screen_size_x(s); |
sx = screen_size_x(s); |
|
|
|
|
else |
else |
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1); |
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. */ |
/* Move cursor to px,py. */ |
|
|
screen_write_reverseindex(struct screen_write_ctx *ctx) |
screen_write_reverseindex(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
if (s->cy == s->rupper) |
if (s->cy == s->rupper) |
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower); |
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower); |
else if (s->cy > 0) |
else if (s->cy > 0) |
s->cy--; |
s->cy--; |
|
|
tty_write0(ctx->wp, tty_cmd_reverseindex); |
tty_write(tty_cmd_reverseindex, &ttyctx); |
} |
} |
|
|
/* Set scroll region. */ |
/* Set scroll region. */ |
|
|
screen_write_linefeed(struct screen_write_ctx *ctx) |
screen_write_linefeed(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
if (s->cy == s->rlower) |
if (s->cy == s->rlower) |
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower); |
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower); |
else if (s->cy < screen_size_y(s) - 1) |
else if (s->cy < screen_size_y(s) - 1) |
s->cy++; |
s->cy++; |
|
|
tty_write0(ctx->wp, tty_cmd_linefeed); |
tty_write(tty_cmd_linefeed, &ttyctx); |
} |
} |
|
|
/* Carriage return (cursor to start of line). */ |
/* Carriage return (cursor to start of line). */ |
|
|
screen_write_clearendofscreen(struct screen_write_ctx *ctx) |
screen_write_clearendofscreen(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
u_int sx, sy; |
u_int sx, sy; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
sx = screen_size_x(s); |
sx = screen_size_x(s); |
sy = screen_size_y(s); |
sy = screen_size_y(s); |
|
|
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1); |
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)); |
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. */ |
/* Clear to start of screen. */ |
|
|
screen_write_clearstartofscreen(struct screen_write_ctx *ctx) |
screen_write_clearstartofscreen(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
struct screen *s = ctx->s; |
|
struct tty_ctx ttyctx; |
u_int sx; |
u_int sx; |
|
|
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
|
|
sx = screen_size_x(s); |
sx = screen_size_x(s); |
|
|
|
|
else |
else |
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1); |
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. */ |
/* Clear entire screen. */ |
|
|
screen_write_clearscreen(struct screen_write_ctx *ctx) |
screen_write_clearscreen(struct screen_write_ctx *ctx) |
{ |
{ |
struct screen *s = ctx->s; |
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)); |
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. */ |
/* Write cell data. */ |
|
|
memcpy(tmp_gu->data + i, udata, UTF8_SIZE - i); |
memcpy(tmp_gu->data + i, udata, UTF8_SIZE - i); |
|
|
/* Assume the previous character has just been input. */ |
/* 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; |
return; |
} |
} |
|
|
|
|
grid_view_set_utf8(gd, s->cx, s->cy, &gu); |
grid_view_set_utf8(gd, s->cx, s->cy, &gu); |
|
|
/* Move the cursor. */ |
/* Move the cursor. */ |
screen_write_save(ctx); |
screen_write_initctx(ctx, &ttyctx); |
s->cx += width; |
s->cx += width; |
|
|
/* Draw to the screen if necessary. */ |
/* Draw to the screen if necessary. */ |
if (insert) |
if (insert) { |
tty_writenum(ctx->wp, tty_cmd_insertcharacter, width); |
ttyctx.num = width; |
ttyctx.wp = ctx->wp; |
tty_write(tty_cmd_insertcharacter, &ttyctx); |
|
} |
ttyctx.utf8 = &gu; |
ttyctx.utf8 = &gu; |
if (screen_check_selection(s, s->cx - width, s->cy)) { |
if (screen_check_selection(s, s->cx - width, s->cy)) { |
s->sel.cell.data = gc->data; |
s->sel.cell.data = gc->data; |