2009-01-28 20:52:21 +01:00
|
|
|
/* $Id: screen-write.c,v 1.31 2009-01-28 19:52:21 nicm Exp $ */
|
2007-12-06 10:46:23 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
|
|
|
/* Initialise writing with a window. */
|
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_start(
|
|
|
|
struct screen_write_ctx *ctx, struct window_pane *wp, struct screen *s)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
ctx->s = s;
|
2009-01-12 00:31:46 +01:00
|
|
|
if (wp != NULL) {
|
|
|
|
ctx->write = tty_write_window;
|
|
|
|
ctx->data = wp;
|
|
|
|
if (ctx->s == NULL)
|
|
|
|
ctx->s = wp->screen;
|
2009-01-28 20:52:21 +01:00
|
|
|
tty_write_update_mode(ctx->data, ctx->s->mode & ~MODE_CURSOR);
|
2009-01-12 00:31:46 +01:00
|
|
|
} else {
|
|
|
|
ctx->write = NULL;
|
|
|
|
ctx->data = NULL;
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Finish writing. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2009-01-12 00:31:46 +01:00
|
|
|
screen_write_stop(unused struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Write character. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_putc(
|
|
|
|
struct screen_write_ctx *ctx, struct grid_cell *gc, u_char ch)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
gc->data = ch;
|
|
|
|
screen_write_cell(ctx, gc);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Write string. */
|
|
|
|
void printflike3
|
|
|
|
screen_write_puts(
|
|
|
|
struct screen_write_ctx *ctx, struct grid_cell *gc, const char *fmt, ...)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
va_list ap;
|
|
|
|
char *msg, *ptr;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
va_start(ap, fmt);
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
for (ptr = msg; *ptr != '\0'; ptr++)
|
|
|
|
screen_write_putc(ctx, gc, (u_char) *ptr);
|
|
|
|
|
|
|
|
xfree(msg);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Copy from another screen. */
|
2008-09-10 00:16:37 +02:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_copy(struct screen_write_ctx *ctx,
|
|
|
|
struct screen *src, u_int px, u_int py, u_int nx, u_int ny)
|
2008-09-10 00:16:37 +02:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid_data *gd = src->grid;
|
|
|
|
const struct grid_cell *gc;
|
|
|
|
u_int xx, yy, cx, cy;
|
|
|
|
|
|
|
|
cx = s->cx;
|
|
|
|
cy = s->cy;
|
|
|
|
for (yy = py; yy < py + ny; yy++) {
|
|
|
|
for (xx = px; xx < px + nx; xx++) {
|
|
|
|
if (xx >= gd->sx || yy >= gd->hsize + gd->sy)
|
|
|
|
gc = &grid_default_cell;
|
|
|
|
else
|
|
|
|
gc = grid_peek_cell(gd, xx, yy);
|
|
|
|
screen_write_cell(ctx, gc);
|
2008-09-10 00:16:37 +02:00
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
cy++;
|
|
|
|
screen_write_cursormove(ctx, cx, cy);
|
2008-09-10 00:16:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Cursor up by ny. */
|
|
|
|
void
|
|
|
|
screen_write_cursorup(struct screen_write_ctx *ctx, u_int ny)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ny > s->cy)
|
|
|
|
ny = s->cy;
|
|
|
|
if (ny == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
s->cy -= ny;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Cursor down by ny. */
|
|
|
|
void
|
|
|
|
screen_write_cursordown(struct screen_write_ctx *ctx, u_int ny)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ny > screen_size_y(s) - 1 - s->cy)
|
|
|
|
ny = screen_size_y(s) - 1 - s->cy;
|
|
|
|
if (ny == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
s->cy += ny;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Cursor right by nx. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursorright(struct screen_write_ctx *ctx, u_int nx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (nx > screen_size_x(s) - 1 - s->cx)
|
|
|
|
nx = screen_size_x(s) - 1 - s->cx;
|
|
|
|
if (nx == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
s->cx += nx;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Cursor left by nx. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cursorleft(struct screen_write_ctx *ctx, u_int nx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (nx > s->cx)
|
|
|
|
nx = s->cx;
|
|
|
|
if (nx == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
s->cx -= nx;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Insert nx characters. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-01-10 02:51:22 +01:00
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (nx > screen_size_x(s) - 1 - s->cx)
|
|
|
|
nx = screen_size_x(s) - 1 - s->cx;
|
|
|
|
if (nx == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
if (ctx->write != NULL)
|
2008-09-25 22:08:57 +02:00
|
|
|
ctx->write(ctx->data, TTY_INSERTCHARACTER, nx);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
|
|
|
if (s->cx <= screen_size_x(s) - 1)
|
|
|
|
grid_view_insert_cells(s->grid, s->cx, s->cy, nx);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Delete nx characters. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (nx > screen_size_x(s) - 1 - s->cx)
|
|
|
|
nx = screen_size_x(s) - 1 - s->cx;
|
|
|
|
if (nx == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_DELETECHARACTER, nx);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
|
|
|
if (s->cx <= screen_size_x(s) - 1)
|
|
|
|
grid_view_delete_cells(s->grid, s->cx, s->cy, nx);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Insert ny lines. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ny > screen_size_y(s) - 1 - s->cy)
|
|
|
|
ny = screen_size_y(s) - 1 - s->cy;
|
|
|
|
if (ny == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_INSERTLINE, ny);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
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->rupper, s->rlower, s->cy, ny);
|
2008-09-26 08:45:28 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Delete ny lines. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ny > screen_size_y(s) - 1 - s->cy)
|
|
|
|
ny = screen_size_y(s) - 1 - s->cy;
|
|
|
|
if (ny == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_DELETELINE, ny);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
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->rupper, s->rlower, s->cy, ny);
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Clear line at cursor. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearline(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
if (ctx->write != NULL)
|
2008-09-25 22:08:57 +02:00
|
|
|
ctx->write(ctx->data, TTY_CLEARLINE);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, screen_size_x(s), 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Clear to end of line from cursor. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearendofline(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-01-08 22:55:12 +01:00
|
|
|
u_int sx;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-08 22:55:12 +01:00
|
|
|
sx = screen_size_x(s);
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
if (ctx->write != NULL)
|
2008-09-25 22:08:57 +02:00
|
|
|
ctx->write(ctx->data, TTY_CLEARENDOFLINE);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
|
|
|
if (s->cx <= sx - 1)
|
|
|
|
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Clear to start of line from cursor. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearstartofline(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-01-08 22:55:12 +01:00
|
|
|
u_int sx;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-08 22:55:12 +01:00
|
|
|
sx = screen_size_x(s);
|
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_CLEARSTARTOFLINE);
|
|
|
|
|
2009-01-08 22:55:12 +01:00
|
|
|
if (s->cx > sx - 1)
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, sx, 1);
|
|
|
|
else
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Move cursor to px,py. */
|
|
|
|
void
|
|
|
|
screen_write_cursormove(struct screen_write_ctx *ctx, u_int px, u_int py)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (px > screen_size_x(s) - 1)
|
|
|
|
px = screen_size_x(s) - 1;
|
|
|
|
if (py > screen_size_y(s) - 1)
|
|
|
|
py = screen_size_y(s) - 1;
|
|
|
|
|
|
|
|
s->cx = px;
|
|
|
|
s->cy = py;
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Set cursor mode. */
|
|
|
|
void
|
|
|
|
screen_write_cursormode(struct screen_write_ctx *ctx, int state)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (state)
|
|
|
|
s->mode |= MODE_CURSOR;
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2008-09-25 22:08:57 +02:00
|
|
|
s->mode &= ~MODE_CURSOR;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Reverse index (up with scroll). */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_reverseindex(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_REVERSEINDEX);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (s->cy == s->rupper)
|
|
|
|
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower);
|
|
|
|
else if (s->cy > 0)
|
|
|
|
s->cy--;
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Set scroll region. */
|
|
|
|
void
|
|
|
|
screen_write_scrollregion(
|
|
|
|
struct screen_write_ctx *ctx, u_int rupper, u_int rlower)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (rupper > screen_size_y(s) - 1)
|
|
|
|
rupper = screen_size_y(s) - 1;
|
|
|
|
if (rlower > screen_size_y(s) - 1)
|
|
|
|
rlower = screen_size_y(s) - 1;
|
|
|
|
if (rupper > rlower)
|
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Cursor moves to top-left. */
|
|
|
|
s->cx = 0;
|
|
|
|
s->cy = rupper;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
s->rupper = rupper;
|
|
|
|
s->rlower = rlower;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Set insert mode. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_insertmode(struct screen_write_ctx *ctx, int state)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (state)
|
|
|
|
s->mode |= MODE_INSERT;
|
2007-12-06 10:46:23 +01:00
|
|
|
else
|
2008-09-25 22:08:57 +02:00
|
|
|
s->mode &= ~MODE_INSERT;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Set mouse mode. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_mousemode(struct screen_write_ctx *ctx, int state)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (state)
|
|
|
|
s->mode |= MODE_MOUSE;
|
|
|
|
else
|
|
|
|
s->mode &= ~MODE_MOUSE;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Line feed (down with scroll). */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_linefeed(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_LINEFEED);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (s->cy == s->rlower)
|
|
|
|
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower);
|
2009-01-18 22:21:53 +01:00
|
|
|
else if (s->cy < screen_size_y(s) - 1)
|
2008-09-25 22:08:57 +02:00
|
|
|
s->cy++;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Carriage return (cursor to start of line). */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_carriagereturn(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
s->cx = 0;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Set keypad cursor keys mode. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_kcursormode(struct screen_write_ctx *ctx, int state)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (state)
|
|
|
|
s->mode |= MODE_KCURSOR;
|
|
|
|
else
|
|
|
|
s->mode &= ~MODE_KCURSOR;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Set keypad number keys mode. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_kkeypadmode(struct screen_write_ctx *ctx, int state)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (state)
|
|
|
|
s->mode |= MODE_KKEYPAD;
|
|
|
|
else
|
2008-09-26 08:45:28 +02:00
|
|
|
s->mode &= ~MODE_KKEYPAD;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Clear to end of screen from cursor. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearendofscreen(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
u_int sx, sy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
sx = screen_size_x(s);
|
|
|
|
sy = screen_size_y(s);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_CLEARENDOFSCREEN);
|
|
|
|
|
2009-01-08 22:55:12 +01:00
|
|
|
if (s->cx <= sx - 1)
|
|
|
|
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
2008-09-25 22:08:57 +02:00
|
|
|
grid_view_clear(s->grid, 0, s->cy + 1, sx, sy - (s->cy + 1));
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Clear to start of screen. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearstartofscreen(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
2009-01-05 12:04:06 +01:00
|
|
|
u_int sx;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
sx = screen_size_x(s);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-12 00:31:46 +01:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_CLEARSTARTOFSCREEN);
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (s->cy > 0)
|
|
|
|
grid_view_clear(s->grid, 0, 0, sx, s->cy - 1);
|
2009-01-08 22:55:12 +01:00
|
|
|
if (s->cx > sx - 1)
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, sx, 1);
|
|
|
|
else
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, s->cx, 1);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Clear entire screen. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_clearscreen(struct screen_write_ctx *ctx)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ctx->write != NULL)
|
|
|
|
ctx->write(ctx->data, TTY_CLEARSCREEN);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
|
|
|
grid_view_clear(s->grid, 0, 0, screen_size_x(s), screen_size_y(s));
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Write cell data. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2008-09-25 22:08:57 +02:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid_data *gd = s->grid;
|
|
|
|
u_int width, xx;
|
|
|
|
const struct grid_cell *hc;
|
|
|
|
struct grid_cell *ic, tc;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-18 22:46:30 +01:00
|
|
|
/* Find character width. */
|
|
|
|
if (gc->flags & GRID_FLAG_UTF8)
|
|
|
|
width = utf8_width(gc->data);
|
|
|
|
else
|
|
|
|
width = 1;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-26 21:57:45 +01:00
|
|
|
/* Discard zero-width characters. */
|
|
|
|
if (width == 0)
|
|
|
|
return;
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* If the character is wider than the screen, don't print it. */
|
|
|
|
if (width > screen_size_x(s)) {
|
|
|
|
memcpy(&tc, gc, sizeof tc);
|
|
|
|
tc.data = '_';
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
width = 1;
|
|
|
|
gc = &tc;
|
|
|
|
}
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Check this will fit on the current line; scroll if not. */
|
2009-01-08 22:55:12 +01:00
|
|
|
if (s->cx > screen_size_x(s) - width) {
|
2008-09-25 22:08:57 +02:00
|
|
|
screen_write_carriagereturn(ctx);
|
|
|
|
screen_write_linefeed(ctx);
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Sanity checks. */
|
|
|
|
if (s->cx > screen_size_x(s) - 1 || s->cy > screen_size_y(s) - 1)
|
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/*
|
|
|
|
* UTF-8 wide characters are a bit of an annoyance. They take up more
|
|
|
|
* than one cell on the screen, so following cells must not be drawn by
|
|
|
|
* marking them as padding.
|
|
|
|
*
|
|
|
|
* So far, so good. The problem is, when overwriting a padding cell, or
|
|
|
|
* a UTF-8 character, it is necessary to also overwrite any other cells
|
|
|
|
* which covered by the same character.
|
|
|
|
*/
|
|
|
|
hc = grid_view_peek_cell(gd, s->cx, s->cy);
|
|
|
|
if (hc->flags & GRID_FLAG_PADDING) {
|
2008-09-26 08:45:28 +02:00
|
|
|
/*
|
2008-09-25 22:08:57 +02:00
|
|
|
* A padding cell, so clear any following and leading padding
|
|
|
|
* cells back to the character. Don't overwrite the current
|
|
|
|
* cell as that happens later anyway.
|
|
|
|
*/
|
2009-01-12 00:31:46 +01:00
|
|
|
xx = s->cx + 1;
|
|
|
|
while (--xx > 0) {
|
2008-09-25 22:08:57 +02:00
|
|
|
hc = grid_view_peek_cell(gd, xx, s->cy);
|
|
|
|
if (!(hc->flags & GRID_FLAG_PADDING))
|
|
|
|
break;
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Overwrite the character at the start of this padding. */
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Overwrite following padding cells. */
|
|
|
|
xx = s->cx;
|
|
|
|
while (++xx < screen_size_x(s)) {
|
|
|
|
hc = grid_view_peek_cell(gd, xx, s->cy);
|
|
|
|
if (!(hc->flags & GRID_FLAG_PADDING))
|
|
|
|
break;
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
|
|
|
}
|
2009-01-18 22:46:30 +01:00
|
|
|
} else if (hc->flags & GRID_FLAG_UTF8 && utf8_width(hc->data) > 1) {
|
2008-09-26 08:45:28 +02:00
|
|
|
/*
|
2008-09-25 22:08:57 +02:00
|
|
|
* An UTF-8 wide cell; overwrite following padding cells only.
|
|
|
|
*/
|
|
|
|
xx = s->cx;
|
|
|
|
while (++xx < screen_size_x(s)) {
|
|
|
|
hc = grid_view_peek_cell(gd, xx, s->cy);
|
|
|
|
if (!(hc->flags & GRID_FLAG_PADDING))
|
|
|
|
break;
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
|
|
|
}
|
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/*
|
|
|
|
* If the new character is UTF-8 wide, fill in padding cells. Have
|
|
|
|
* already ensured there is enough room.
|
|
|
|
*/
|
|
|
|
for (xx = s->cx + 1; xx < s->cx + width; xx++) {
|
|
|
|
ic = grid_view_get_cell(gd, xx, s->cy);
|
2009-01-17 19:47:37 +01:00
|
|
|
if (ic != NULL)
|
|
|
|
ic->flags |= GRID_FLAG_PADDING;
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Write the actual cell. */
|
|
|
|
grid_view_set_cell(gd, s->cx, s->cy, gc);
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ctx->write != NULL) {
|
2009-01-12 00:31:46 +01:00
|
|
|
if (screen_check_selection(s, s->cx, s->cy)) {
|
|
|
|
memcpy(&tc, &s->sel.cell, sizeof tc);
|
2008-12-08 17:19:51 +01:00
|
|
|
tc.data = gc->data;
|
2008-09-25 22:08:57 +02:00
|
|
|
ctx->write(ctx->data, TTY_CELL, &tc);
|
|
|
|
} else
|
|
|
|
ctx->write(ctx->data, TTY_CELL, gc);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
2009-01-12 00:31:46 +01:00
|
|
|
|
|
|
|
/* Move the cursor. */
|
|
|
|
s->cx += width;
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|