2011-07-09 11:42:33 +02:00
|
|
|
/* $Id$ */
|
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>
|
|
|
|
|
2012-07-11 21:34:16 +02:00
|
|
|
#include <stdlib.h>
|
2007-12-06 10:46:23 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
void screen_write_initctx(struct screen_write_ctx *, struct tty_ctx *, int);
|
2010-06-16 20:09:23 +02:00
|
|
|
void screen_write_overwrite(struct screen_write_ctx *, u_int);
|
2009-10-23 19:16:25 +02:00
|
|
|
int screen_write_combine(
|
|
|
|
struct screen_write_ctx *, const struct utf8_data *);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2007-12-06 10:46:23 +01:00
|
|
|
/* 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
|
|
|
{
|
2009-02-11 07:31:09 +01:00
|
|
|
ctx->wp = wp;
|
2009-02-24 22:49:05 +01:00
|
|
|
if (wp != NULL && s == NULL)
|
2009-02-11 07:31:09 +01:00
|
|
|
ctx->s = wp->screen;
|
|
|
|
else
|
|
|
|
ctx->s = s;
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-01-21 20:31:59 +01:00
|
|
|
|
|
|
|
/* Reset screen state. */
|
|
|
|
void
|
|
|
|
screen_write_reset(struct screen_write_ctx *ctx)
|
|
|
|
{
|
2013-02-17 11:43:35 +01:00
|
|
|
struct screen *s = ctx->s;
|
2012-01-21 20:31:59 +01:00
|
|
|
|
2013-02-17 11:43:35 +01:00
|
|
|
screen_reset_tabs(s);
|
|
|
|
screen_write_scrollregion(ctx, 0, screen_size_y(s) - 1);
|
2013-02-18 15:52:27 +01:00
|
|
|
|
|
|
|
s->mode &= ~(MODE_INSERT|MODE_KCURSOR|MODE_KKEYPAD);
|
|
|
|
s->mode &= ~(ALL_MOUSE_MODES|MODE_MOUSE_UTF8|MODE_MOUSE_SGR);
|
2012-01-21 20:31:59 +01:00
|
|
|
|
|
|
|
screen_write_clearscreen(ctx);
|
|
|
|
screen_write_cursormove(ctx, 0, 0);
|
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Write character. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2013-01-18 03:16:21 +01:00
|
|
|
screen_write_putc(struct screen_write_ctx *ctx, struct grid_cell *gc, u_char ch)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_one(gc, ch);
|
|
|
|
screen_write_cell(ctx, gc);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2009-09-08 01:37:48 +02:00
|
|
|
/* Calculate string length, with embedded formatting. */
|
|
|
|
size_t printflike2
|
|
|
|
screen_write_cstrlen(int utf8flag, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
char *msg, *msg2, *ptr, *ptr2;
|
|
|
|
size_t size;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
msg2 = xmalloc(strlen(msg) + 1);
|
|
|
|
|
|
|
|
ptr = msg;
|
|
|
|
ptr2 = msg2;
|
|
|
|
while (*ptr != '\0') {
|
|
|
|
if (ptr[0] == '#' && ptr[1] == '[') {
|
|
|
|
while (*ptr != ']' && *ptr != '\0')
|
|
|
|
ptr++;
|
|
|
|
if (*ptr == ']')
|
|
|
|
ptr++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
*ptr2++ = *ptr++;
|
|
|
|
}
|
|
|
|
*ptr2 = '\0';
|
|
|
|
|
|
|
|
size = screen_write_strlen(utf8flag, "%s", msg2);
|
|
|
|
|
2012-07-11 21:34:16 +02:00
|
|
|
free(msg);
|
|
|
|
free(msg2);
|
2009-09-08 01:37:48 +02:00
|
|
|
|
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
|
2009-06-25 17:47:07 +02:00
|
|
|
/* Calculate string length. */
|
2009-06-25 17:48:25 +02:00
|
|
|
size_t printflike2
|
|
|
|
screen_write_strlen(int utf8flag, const char *fmt, ...)
|
2009-06-25 17:47:07 +02:00
|
|
|
{
|
2009-10-23 19:16:25 +02:00
|
|
|
va_list ap;
|
|
|
|
char *msg;
|
|
|
|
struct utf8_data utf8data;
|
|
|
|
u_char *ptr;
|
|
|
|
size_t left, size = 0;
|
2009-06-25 17:47:07 +02:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
ptr = msg;
|
|
|
|
while (*ptr != '\0') {
|
2009-10-23 19:16:25 +02:00
|
|
|
if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
|
|
|
|
ptr++;
|
2009-06-25 17:47:07 +02:00
|
|
|
|
|
|
|
left = strlen(ptr);
|
2009-10-23 19:16:25 +02:00
|
|
|
if (left < utf8data.size - 1)
|
|
|
|
break;
|
|
|
|
while (utf8_append(&utf8data, *ptr))
|
2009-06-25 17:47:07 +02:00
|
|
|
ptr++;
|
2009-10-23 19:16:25 +02:00
|
|
|
ptr++;
|
|
|
|
|
|
|
|
size += utf8data.width;
|
2009-06-25 17:47:07 +02:00
|
|
|
} else {
|
|
|
|
size++;
|
|
|
|
ptr++;
|
|
|
|
}
|
2009-06-25 18:34:50 +02:00
|
|
|
}
|
2009-06-25 17:47:07 +02:00
|
|
|
|
2012-07-11 21:34:16 +02:00
|
|
|
free(msg);
|
2009-06-25 17:47:07 +02:00
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
|
2009-06-25 17:48:25 +02:00
|
|
|
/* Write simple string (no UTF-8 or maximum length). */
|
2008-09-25 22:08:57 +02:00
|
|
|
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;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
va_start(ap, fmt);
|
2009-06-25 17:48:25 +02:00
|
|
|
screen_write_vnputs(ctx, -1, gc, 0, fmt, ap);
|
2008-09-25 22:08:57 +02:00
|
|
|
va_end(ap);
|
2009-06-25 17:47:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write string with length limit (-1 for unlimited). */
|
2009-06-25 17:48:25 +02:00
|
|
|
void printflike5
|
2009-06-25 17:47:07 +02:00
|
|
|
screen_write_nputs(struct screen_write_ctx *ctx,
|
2009-06-25 17:48:25 +02:00
|
|
|
ssize_t maxlen, struct grid_cell *gc, int utf8flag, const char *fmt, ...)
|
2009-06-25 17:47:07 +02:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2009-06-25 17:48:25 +02:00
|
|
|
screen_write_vnputs(ctx, maxlen, gc, utf8flag, fmt, ap);
|
2009-06-25 17:47:07 +02:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-06-25 17:48:25 +02:00
|
|
|
screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
|
|
|
struct grid_cell *gc, int utf8flag, const char *fmt, va_list ap)
|
2009-06-25 17:47:07 +02:00
|
|
|
{
|
2009-10-23 19:16:25 +02:00
|
|
|
char *msg;
|
|
|
|
struct utf8_data utf8data;
|
|
|
|
u_char *ptr;
|
|
|
|
size_t left, size = 0;
|
2009-06-25 17:47:07 +02:00
|
|
|
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
|
|
|
|
ptr = msg;
|
|
|
|
while (*ptr != '\0') {
|
2009-10-23 19:16:25 +02:00
|
|
|
if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
|
|
|
|
ptr++;
|
2009-06-25 17:47:07 +02:00
|
|
|
|
|
|
|
left = strlen(ptr);
|
2009-10-23 19:16:25 +02:00
|
|
|
if (left < utf8data.size - 1)
|
|
|
|
break;
|
|
|
|
while (utf8_append(&utf8data, *ptr))
|
2009-06-25 17:47:07 +02:00
|
|
|
ptr++;
|
2009-10-23 19:16:25 +02:00
|
|
|
ptr++;
|
2009-06-25 18:34:50 +02:00
|
|
|
|
2009-10-23 19:16:25 +02:00
|
|
|
if (maxlen > 0 &&
|
|
|
|
size + utf8data.width > (size_t) maxlen) {
|
2009-06-25 17:47:07 +02:00
|
|
|
while (size < (size_t) maxlen) {
|
|
|
|
screen_write_putc(ctx, gc, ' ');
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-10-23 19:16:25 +02:00
|
|
|
size += utf8data.width;
|
2009-12-04 23:14:47 +01:00
|
|
|
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_set(gc, &utf8data);
|
|
|
|
screen_write_cell(ctx, gc);
|
2009-06-25 17:47:07 +02:00
|
|
|
} else {
|
2009-06-26 17:34:12 +02:00
|
|
|
if (maxlen > 0 && size + 1 > (size_t) maxlen)
|
2009-06-25 17:47:07 +02:00
|
|
|
break;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2012-09-25 09:54:01 +02:00
|
|
|
if (*ptr == '\001')
|
|
|
|
gc->attr ^= GRID_ATTR_CHARSET;
|
|
|
|
else {
|
|
|
|
size++;
|
|
|
|
screen_write_putc(ctx, gc, *ptr);
|
|
|
|
}
|
2009-06-25 17:47:07 +02:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2012-07-11 21:34:16 +02:00
|
|
|
free(msg);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2009-09-08 01:37:48 +02:00
|
|
|
/* Write string, similar to nputs, but with embedded formatting (#[]). */
|
|
|
|
void printflike5
|
|
|
|
screen_write_cnputs(struct screen_write_ctx *ctx,
|
|
|
|
ssize_t maxlen, struct grid_cell *gc, int utf8flag, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
struct grid_cell lgc;
|
2009-10-23 19:16:25 +02:00
|
|
|
struct utf8_data utf8data;
|
2009-09-08 01:37:48 +02:00
|
|
|
va_list ap;
|
|
|
|
char *msg;
|
2009-10-23 19:16:25 +02:00
|
|
|
u_char *ptr, *last;
|
2009-09-08 01:37:48 +02:00
|
|
|
size_t left, size = 0;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
memcpy(&lgc, gc, sizeof lgc);
|
|
|
|
|
|
|
|
ptr = msg;
|
|
|
|
while (*ptr != '\0') {
|
|
|
|
if (ptr[0] == '#' && ptr[1] == '[') {
|
|
|
|
ptr += 2;
|
|
|
|
last = ptr + strcspn(ptr, "]");
|
|
|
|
if (*last == '\0') {
|
|
|
|
/* No ]. Not much point in doing anything. */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
*last = '\0';
|
|
|
|
|
|
|
|
screen_write_parsestyle(gc, &lgc, ptr);
|
|
|
|
ptr = last + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2009-10-23 19:16:25 +02:00
|
|
|
if (utf8flag && *ptr > 0x7f && utf8_open(&utf8data, *ptr)) {
|
|
|
|
ptr++;
|
2009-09-08 01:37:48 +02:00
|
|
|
|
|
|
|
left = strlen(ptr);
|
2009-10-23 19:16:25 +02:00
|
|
|
if (left < utf8data.size - 1)
|
|
|
|
break;
|
|
|
|
while (utf8_append(&utf8data, *ptr))
|
2009-09-08 01:37:48 +02:00
|
|
|
ptr++;
|
2009-10-23 19:16:25 +02:00
|
|
|
ptr++;
|
2009-09-08 01:37:48 +02:00
|
|
|
|
2009-10-23 19:16:25 +02:00
|
|
|
if (maxlen > 0 &&
|
|
|
|
size + utf8data.width > (size_t) maxlen) {
|
2009-09-08 01:37:48 +02:00
|
|
|
while (size < (size_t) maxlen) {
|
|
|
|
screen_write_putc(ctx, gc, ' ');
|
|
|
|
size++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-10-23 19:16:25 +02:00
|
|
|
size += utf8data.width;
|
2009-09-08 01:37:48 +02:00
|
|
|
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_set(&lgc, &utf8data);
|
|
|
|
screen_write_cell(ctx, &lgc);
|
2009-09-08 01:37:48 +02:00
|
|
|
} else {
|
|
|
|
if (maxlen > 0 && size + 1 > (size_t) maxlen)
|
|
|
|
break;
|
|
|
|
|
|
|
|
size++;
|
|
|
|
screen_write_putc(ctx, &lgc, *ptr);
|
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-11 21:34:16 +02:00
|
|
|
free(msg);
|
2009-09-08 01:37:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Parse an embedded style of the form "fg=colour,bg=colour,bright,...". */
|
|
|
|
void
|
|
|
|
screen_write_parsestyle(
|
|
|
|
struct grid_cell *defgc, struct grid_cell *gc, const char *in)
|
|
|
|
{
|
|
|
|
const char delimiters[] = " ,";
|
|
|
|
char tmp[32];
|
|
|
|
int val;
|
|
|
|
size_t end;
|
2009-09-11 16:13:52 +02:00
|
|
|
u_char fg, bg, attr, flags;
|
2009-09-08 01:37:48 +02:00
|
|
|
|
|
|
|
if (*in == '\0')
|
|
|
|
return;
|
|
|
|
if (strchr(delimiters, in[strlen(in) - 1]) != NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
fg = gc->fg;
|
|
|
|
bg = gc->bg;
|
2009-09-11 16:13:52 +02:00
|
|
|
attr = gc->attr;
|
|
|
|
flags = gc->flags;
|
2009-09-08 01:37:48 +02:00
|
|
|
do {
|
|
|
|
end = strcspn(in, delimiters);
|
|
|
|
if (end > (sizeof tmp) - 1)
|
|
|
|
return;
|
|
|
|
memcpy(tmp, in, end);
|
|
|
|
tmp[end] = '\0';
|
|
|
|
|
|
|
|
if (strcasecmp(tmp, "default") == 0) {
|
|
|
|
fg = defgc->fg;
|
|
|
|
bg = defgc->bg;
|
|
|
|
attr = defgc->attr;
|
2012-12-08 18:05:57 +01:00
|
|
|
flags &= ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
|
|
|
|
flags |=
|
|
|
|
defgc->flags & (GRID_FLAG_FG256|GRID_FLAG_BG256);
|
2009-09-08 01:37:48 +02:00
|
|
|
} else if (end > 3 && strncasecmp(tmp + 1, "g=", 2) == 0) {
|
|
|
|
if ((val = colour_fromstring(tmp + 3)) == -1)
|
|
|
|
return;
|
|
|
|
if (*in == 'f' || *in == 'F') {
|
2009-09-11 16:13:52 +02:00
|
|
|
if (val != 8) {
|
|
|
|
if (val & 0x100) {
|
|
|
|
flags |= GRID_FLAG_FG256;
|
|
|
|
val &= ~0x100;
|
|
|
|
} else
|
|
|
|
flags &= ~GRID_FLAG_FG256;
|
2009-09-08 01:37:48 +02:00
|
|
|
fg = val;
|
2012-12-08 18:05:57 +01:00
|
|
|
} else {
|
2009-09-08 01:37:48 +02:00
|
|
|
fg = defgc->fg;
|
2012-12-08 18:05:57 +01:00
|
|
|
flags &= ~GRID_FLAG_FG256;
|
|
|
|
flags |= defgc->flags & GRID_FLAG_FG256;
|
|
|
|
}
|
2009-09-08 01:37:48 +02:00
|
|
|
} else if (*in == 'b' || *in == 'B') {
|
2009-09-11 16:13:52 +02:00
|
|
|
if (val != 8) {
|
|
|
|
if (val & 0x100) {
|
|
|
|
flags |= GRID_FLAG_BG256;
|
|
|
|
val &= ~0x100;
|
|
|
|
} else
|
|
|
|
flags &= ~GRID_FLAG_BG256;
|
2009-09-08 01:37:48 +02:00
|
|
|
bg = val;
|
2012-12-08 18:05:57 +01:00
|
|
|
} else {
|
2009-09-08 01:37:48 +02:00
|
|
|
bg = defgc->bg;
|
2012-12-08 18:05:57 +01:00
|
|
|
flags &= ~GRID_FLAG_BG256;
|
|
|
|
flags |= defgc->flags & GRID_FLAG_BG256;
|
|
|
|
}
|
2009-09-08 01:37:48 +02:00
|
|
|
} else
|
|
|
|
return;
|
2009-10-15 03:31:38 +02:00
|
|
|
} else if (end > 2 && strncasecmp(tmp, "no", 2) == 0) {
|
|
|
|
if ((val = attributes_fromstring(tmp + 2)) == -1)
|
|
|
|
return;
|
|
|
|
attr &= ~val;
|
2009-09-08 01:37:48 +02:00
|
|
|
} else {
|
|
|
|
if ((val = attributes_fromstring(tmp)) == -1)
|
|
|
|
return;
|
|
|
|
attr |= val;
|
|
|
|
}
|
|
|
|
|
|
|
|
in += end + strspn(in + end, delimiters);
|
|
|
|
} while (*in != '\0');
|
|
|
|
gc->fg = fg;
|
|
|
|
gc->bg = bg;
|
|
|
|
gc->attr = attr;
|
2009-09-11 16:13:52 +02:00
|
|
|
gc->flags = flags;
|
2009-09-08 01:37:48 +02: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;
|
2009-03-28 16:43:41 +01:00
|
|
|
struct grid *gd = src->grid;
|
2009-08-14 23:32:38 +02:00
|
|
|
struct grid_line *gl;
|
2008-09-25 22:08:57 +02:00
|
|
|
const struct grid_cell *gc;
|
2013-01-18 03:16:21 +01:00
|
|
|
struct utf8_data ud;
|
2009-11-19 23:23:27 +01:00
|
|
|
u_int xx, yy, cx, cy, ax, bx;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
|
|
|
cx = s->cx;
|
|
|
|
cy = s->cy;
|
|
|
|
for (yy = py; yy < py + ny; yy++) {
|
2009-08-14 23:32:38 +02:00
|
|
|
gl = &gd->linedata[yy];
|
2009-09-16 01:54:57 +02:00
|
|
|
if (yy < gd->hsize + gd->sy) {
|
|
|
|
/*
|
|
|
|
* Find start and end position and copy between
|
|
|
|
* them. Limit to the real end of the line then use a
|
|
|
|
* clear EOL only if copying to the end, otherwise
|
|
|
|
* could overwrite whatever is there already.
|
|
|
|
*/
|
|
|
|
if (px > gl->cellsize)
|
|
|
|
ax = gl->cellsize;
|
|
|
|
else
|
|
|
|
ax = px;
|
|
|
|
if (px + nx == gd->sx && px + nx > gl->cellsize)
|
|
|
|
bx = gl->cellsize;
|
|
|
|
else
|
|
|
|
bx = px + nx;
|
2009-12-04 23:14:47 +01:00
|
|
|
|
2009-09-16 01:54:57 +02:00
|
|
|
for (xx = ax; xx < bx; xx++) {
|
|
|
|
if (xx >= gl->cellsize)
|
|
|
|
gc = &grid_default_cell;
|
2009-10-23 19:16:25 +02:00
|
|
|
else
|
2009-09-16 01:54:57 +02:00
|
|
|
gc = &gl->celldata[xx];
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
screen_write_cell(ctx, gc);
|
2009-03-28 17:30:05 +01:00
|
|
|
}
|
2009-09-16 01:54:57 +02:00
|
|
|
if (px + nx == gd->sx && px + nx > gl->cellsize)
|
|
|
|
screen_write_clearendofline(ctx);
|
|
|
|
} else
|
2009-10-23 19:16:25 +02:00
|
|
|
screen_write_clearline(ctx);
|
2008-09-25 22:08:57 +02:00
|
|
|
cy++;
|
|
|
|
screen_write_cursormove(ctx, cx, cy);
|
2008-09-10 00:16:37 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
/* Set up context for TTY command. */
|
2009-02-11 18:04:39 +01:00
|
|
|
void
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(
|
|
|
|
struct screen_write_ctx *ctx, struct tty_ctx *ttyctx, int save_last)
|
2009-02-11 18:04:39 +01:00
|
|
|
{
|
2009-10-23 19:06:23 +02:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
|
|
|
const struct grid_cell *gc;
|
|
|
|
u_int xx;
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx->wp = ctx->wp;
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx->ocx = s->cx;
|
|
|
|
ttyctx->ocy = s->cy;
|
|
|
|
|
|
|
|
ttyctx->orlower = s->rlower;
|
|
|
|
ttyctx->orupper = s->rupper;
|
2009-10-23 19:06:23 +02:00
|
|
|
|
|
|
|
if (!save_last)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Save the last cell on the screen. */
|
2009-11-18 02:25:35 +01:00
|
|
|
gc = &grid_default_cell;
|
|
|
|
for (xx = 1; xx <= screen_size_x(s); xx++) {
|
2009-10-23 19:06:23 +02:00
|
|
|
gc = grid_view_peek_cell(gd, screen_size_x(s) - xx, s->cy);
|
|
|
|
if (!(gc->flags & GRID_FLAG_PADDING))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ttyctx->last_width = xx;
|
|
|
|
memcpy(&ttyctx->last_cell, gc, sizeof ttyctx->last_cell);
|
2009-02-11 18:04:39 +01:00
|
|
|
}
|
|
|
|
|
2013-02-17 11:43:35 +01:00
|
|
|
/* Set a mode. */
|
|
|
|
void
|
|
|
|
screen_write_mode_set(struct screen_write_ctx *ctx, int mode)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
s->mode |= mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear a mode. */
|
|
|
|
void
|
|
|
|
screen_write_mode_clear(struct screen_write_ctx *ctx, int mode)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
s->mode &= ~mode;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
2009-07-09 20:08:13 +02:00
|
|
|
if (s->cy < s->rupper) {
|
|
|
|
/* Above region. */
|
|
|
|
if (ny > s->cy)
|
|
|
|
ny = s->cy;
|
|
|
|
} else {
|
|
|
|
/* Below region. */
|
|
|
|
if (ny > s->cy - s->rupper)
|
|
|
|
ny = s->cy - s->rupper;
|
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
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;
|
|
|
|
|
2009-07-09 20:08:13 +02:00
|
|
|
if (s->cy > s->rlower) {
|
|
|
|
/* Below region. */
|
|
|
|
if (ny > screen_size_y(s) - 1 - s->cy)
|
|
|
|
ny = screen_size_y(s) - 1 - s->cy;
|
|
|
|
} else {
|
|
|
|
/* Above region. */
|
|
|
|
if (ny > s->rlower - s->cy)
|
|
|
|
ny = s->rlower - s->cy;
|
|
|
|
}
|
2008-09-25 22:08:57 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2009-10-15 03:39:30 +02:00
|
|
|
/* Backspace; cursor left unless at start of wrapped line when can move up. */
|
|
|
|
void
|
|
|
|
screen_write_backspace(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid_line *gl;
|
|
|
|
|
|
|
|
if (s->cx == 0) {
|
|
|
|
if (s->cy == 0)
|
|
|
|
return;
|
|
|
|
gl = &s->grid->linedata[s->grid->hsize + s->cy - 1];
|
|
|
|
if (gl->flags & GRID_LINE_WRAPPED) {
|
|
|
|
s->cy--;
|
|
|
|
s->cx = screen_size_x(s) - 1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
s->cx--;
|
|
|
|
}
|
|
|
|
|
2009-06-25 17:51:54 +02:00
|
|
|
/* VT100 alignment test. */
|
|
|
|
void
|
|
|
|
screen_write_alignmenttest(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2009-06-25 17:51:54 +02:00
|
|
|
struct grid_cell gc;
|
|
|
|
u_int xx, yy;
|
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-07-23 14:48:18 +02:00
|
|
|
|
2009-06-25 17:51:54 +02:00
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_one(&gc, 'E');
|
2009-06-25 18:34:50 +02:00
|
|
|
|
2009-06-25 17:51:54 +02:00
|
|
|
for (yy = 0; yy < screen_size_y(s); yy++) {
|
|
|
|
for (xx = 0; xx < screen_size_x(s); xx++)
|
|
|
|
grid_view_set_cell(s->grid, xx, yy, &gc);
|
|
|
|
}
|
2009-06-25 18:34:50 +02:00
|
|
|
|
2009-06-25 17:51:54 +02:00
|
|
|
s->cx = 0;
|
|
|
|
s->cy = 0;
|
|
|
|
|
|
|
|
s->rupper = 0;
|
2009-10-15 03:39:30 +02:00
|
|
|
|
2009-06-25 17:51:54 +02:00
|
|
|
s->rlower = screen_size_y(s) - 1;
|
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
tty_write(tty_cmd_alignmenttest, &ttyctx);
|
2009-06-25 17:51:54 +02: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-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
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
|
|
|
|
2009-07-01 21:14:33 +02:00
|
|
|
if (nx > screen_size_x(s) - s->cx)
|
|
|
|
nx = screen_size_x(s) - s->cx;
|
2008-09-25 22:08:57 +02:00
|
|
|
if (nx == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
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);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx.num = nx;
|
|
|
|
tty_write(tty_cmd_insertcharacter, &ttyctx);
|
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;
|
2009-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
2009-07-01 21:14:33 +02:00
|
|
|
if (nx > screen_size_x(s) - s->cx)
|
|
|
|
nx = screen_size_x(s) - s->cx;
|
2008-09-25 22:08:57 +02:00
|
|
|
if (nx == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2008-09-25 22:08:57 +02:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
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);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx.num = nx;
|
|
|
|
tty_write(tty_cmd_deletecharacter, &ttyctx);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2013-01-16 00:18:55 +01:00
|
|
|
/* Clear nx characters. */
|
|
|
|
void
|
|
|
|
screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
|
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
|
|
|
if (nx > screen_size_x(s) - s->cx)
|
|
|
|
nx = screen_size_x(s) - s->cx;
|
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
|
|
|
|
|
|
|
if (s->cx <= screen_size_x(s) - 1)
|
|
|
|
grid_view_clear(s->grid, s->cx, s->cy, nx, 1);
|
|
|
|
|
|
|
|
ttyctx.num = nx;
|
|
|
|
tty_write(tty_cmd_clearcharacter, &ttyctx);
|
|
|
|
}
|
|
|
|
|
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-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2009-07-09 20:04:53 +02:00
|
|
|
if (s->cy < s->rupper || s->cy > s->rlower) {
|
|
|
|
if (ny > screen_size_y(s) - s->cy)
|
|
|
|
ny = screen_size_y(s) - s->cy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-07-09 20:04:53 +02:00
|
|
|
|
|
|
|
grid_view_insert_lines(s->grid, s->cy, ny);
|
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_insertline, &ttyctx);
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2009-07-09 20:04:53 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-07-09 20:04:53 +02:00
|
|
|
if (ny > s->rlower + 1 - s->cy)
|
|
|
|
ny = s->rlower + 1 - s->cy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
2009-12-04 23:14:47 +01:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
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);
|
2009-07-09 20:04:17 +02:00
|
|
|
else
|
|
|
|
grid_view_insert_lines_region(s->grid, s->rlower, s->cy, ny);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_insertline, &ttyctx);
|
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-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-01-06 19:07:57 +01:00
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2009-07-09 20:04:53 +02:00
|
|
|
if (s->cy < s->rupper || s->cy > s->rlower) {
|
|
|
|
if (ny > screen_size_y(s) - s->cy)
|
|
|
|
ny = screen_size_y(s) - s->cy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-07-09 20:04:53 +02:00
|
|
|
|
|
|
|
grid_view_delete_lines(s->grid, s->cy, ny);
|
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_deleteline, &ttyctx);
|
2009-07-09 20:04:53 +02:00
|
|
|
return;
|
|
|
|
}
|
2009-12-04 23:14:47 +01:00
|
|
|
|
2009-07-09 20:04:53 +02:00
|
|
|
if (ny > s->rlower + 1 - s->cy)
|
|
|
|
ny = s->rlower + 1 - s->cy;
|
2008-09-25 22:08:57 +02:00
|
|
|
if (ny == 0)
|
2009-01-06 19:07:57 +01:00
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
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);
|
2009-07-09 20:04:17 +02:00
|
|
|
else
|
|
|
|
grid_view_delete_lines_region(s->grid, s->rlower, s->cy, ny);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_deleteline, &ttyctx);
|
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;
|
2009-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, screen_size_x(s), 1);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
tty_write(tty_cmd_clearline, &ttyctx);
|
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-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2009-01-08 22:55:12 +01:00
|
|
|
u_int sx;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-02-11 18:04:39 +01:00
|
|
|
sx = screen_size_x(s);
|
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);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-12-04 23:14:47 +01:00
|
|
|
tty_write(tty_cmd_clearendofline, &ttyctx);
|
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-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2009-01-08 22:55:12 +01:00
|
|
|
u_int sx;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-01-08 22:55:12 +01:00
|
|
|
|
2009-02-11 18:04:39 +01:00
|
|
|
sx = screen_size_x(s);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
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);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
tty_write(tty_cmd_clearstartofline, &ttyctx);
|
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
|
|
|
/* 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;
|
2009-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2008-09-26 08:45:28 +02:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
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--;
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
tty_write(tty_cmd_reverseindex, &ttyctx);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
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;
|
2009-07-15 19:43:02 +02:00
|
|
|
if (rupper >= rlower) /* cannot be one line */
|
2008-09-25 22:08:57 +02:00
|
|
|
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;
|
2009-03-05 21:27:51 +01:00
|
|
|
s->cy = 0;
|
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
|
|
|
}
|
|
|
|
|
2009-10-23 19:11:26 +02:00
|
|
|
/* Line feed. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2009-10-23 19:11:26 +02:00
|
|
|
screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped)
|
2007-12-06 10:46:23 +01:00
|
|
|
{
|
2009-08-09 19:32:06 +02:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid_line *gl;
|
2009-10-23 19:11:26 +02:00
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
|
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
2009-08-09 19:32:06 +02:00
|
|
|
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
|
|
|
if (wrapped)
|
|
|
|
gl->flags |= GRID_LINE_WRAPPED;
|
|
|
|
else
|
|
|
|
gl->flags &= ~GRID_LINE_WRAPPED;
|
|
|
|
|
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++;
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-10-23 19:11:26 +02:00
|
|
|
ttyctx.num = wrapped;
|
2009-12-04 23:14:47 +01:00
|
|
|
tty_write(tty_cmd_linefeed, &ttyctx);
|
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
|
|
|
/* 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;
|
2009-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2008-09-25 22:08:57 +02:00
|
|
|
u_int sx, sy;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-02-11 18:04:39 +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
|
|
|
|
2011-02-15 16:10:47 +01:00
|
|
|
/* Scroll into history if it is enabled and clearing entire screen. */
|
|
|
|
if (s->cy == 0 && s->grid->flags & GRID_HISTORY)
|
|
|
|
grid_view_clear_history(s->grid);
|
|
|
|
else {
|
|
|
|
if (s->cx <= sx - 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));
|
|
|
|
}
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
tty_write(tty_cmd_clearendofscreen, &ttyctx);
|
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-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2009-01-05 12:04:06 +01:00
|
|
|
u_int sx;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-02-11 18:04:39 +01:00
|
|
|
sx = screen_size_x(s);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
if (s->cy > 0)
|
2009-06-25 17:50:48 +02:00
|
|
|
grid_view_clear(s->grid, 0, 0, sx, s->cy);
|
2009-01-08 22:55:12 +01:00
|
|
|
if (s->cx > sx - 1)
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, sx, 1);
|
|
|
|
else
|
2009-06-25 17:50:48 +02:00
|
|
|
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
tty_write(tty_cmd_clearstartofscreen, &ttyctx);
|
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;
|
2009-07-23 14:48:18 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-10-23 19:06:23 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
2009-01-12 00:31:46 +01:00
|
|
|
|
2011-02-15 16:10:47 +01:00
|
|
|
/* Scroll into history if it is enabled. */
|
|
|
|
if (s->grid->flags & GRID_HISTORY)
|
|
|
|
grid_view_clear_history(s->grid);
|
|
|
|
else {
|
|
|
|
grid_view_clear(
|
|
|
|
s->grid, 0, 0, screen_size_x(s), screen_size_y(s));
|
|
|
|
}
|
2009-02-11 18:04:39 +01:00
|
|
|
|
2009-07-23 14:48:18 +02:00
|
|
|
tty_write(tty_cmd_clearscreen, &ttyctx);
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
|
|
|
|
2011-10-23 17:10:22 +02:00
|
|
|
/* Clear entire history. */
|
|
|
|
void
|
|
|
|
screen_write_clearhistory(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
|
|
|
|
|
|
|
grid_move_lines(gd, 0, gd->hsize, gd->sy);
|
|
|
|
gd->hsize = 0;
|
|
|
|
}
|
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Write cell data. */
|
2007-12-06 10:46:23 +01:00
|
|
|
void
|
2013-01-18 03:16:21 +01: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;
|
2009-03-28 16:43:41 +01:00
|
|
|
struct grid *gd = s->grid;
|
2009-07-22 20:08:56 +02:00
|
|
|
struct tty_ctx ttyctx;
|
2009-10-23 19:13:10 +02:00
|
|
|
u_int width, xx;
|
2009-10-23 19:08:30 +02:00
|
|
|
struct grid_cell tmp_gc, *tmp_gcp;
|
2013-01-18 03:16:21 +01:00
|
|
|
struct utf8_data ud;
|
2009-06-25 17:52:12 +02:00
|
|
|
int insert = 0;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-03-29 13:06:22 +02:00
|
|
|
/* Ignore padding. */
|
|
|
|
if (gc->flags & GRID_FLAG_PADDING)
|
|
|
|
return;
|
2013-01-18 03:16:21 +01:00
|
|
|
width = grid_cell_width(gc);
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-10-23 19:07:18 +02:00
|
|
|
/*
|
|
|
|
* If this is a wide character and there is no room on the screen, for
|
|
|
|
* the entire character, don't print it.
|
|
|
|
*/
|
2011-03-24 18:03:29 +01:00
|
|
|
if (!(s->mode & MODE_WRAP)
|
|
|
|
&& (width > 1 && (width > screen_size_x(s) ||
|
|
|
|
(s->cx != screen_size_x(s)
|
|
|
|
&& s->cx > screen_size_x(s) - width))))
|
2009-10-23 19:07:18 +02:00
|
|
|
return;
|
|
|
|
|
2009-10-23 19:13:10 +02:00
|
|
|
/*
|
|
|
|
* If the width is zero, combine onto the previous character, if
|
2009-12-04 23:14:47 +01:00
|
|
|
* there is space.
|
2009-10-23 19:13:10 +02:00
|
|
|
*/
|
2009-03-28 21:17:29 +01:00
|
|
|
if (width == 0) {
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
if (screen_write_combine(ctx, &ud) == 0) {
|
2009-10-23 19:13:10 +02:00
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
|
|
|
tty_write(tty_cmd_utf8character, &ttyctx);
|
2009-03-29 13:06:22 +02:00
|
|
|
}
|
2009-01-26 21:57:45 +01:00
|
|
|
return;
|
2009-03-28 21:17:29 +01:00
|
|
|
}
|
2009-01-26 21:57:45 +01:00
|
|
|
|
2012-03-18 02:57:01 +01:00
|
|
|
/* Initialise the redraw context, saving the last cell. */
|
|
|
|
screen_write_initctx(ctx, &ttyctx, 1);
|
|
|
|
|
2009-06-25 17:52:12 +02:00
|
|
|
/* If in insert mode, make space for the cells. */
|
2012-03-18 02:57:01 +01:00
|
|
|
if ((s->mode & MODE_INSERT) && s->cx <= screen_size_x(s) - width) {
|
2009-06-25 17:52:12 +02:00
|
|
|
xx = screen_size_x(s) - s->cx - width;
|
|
|
|
grid_move_cells(s->grid, s->cx + width, s->cx, s->cy, xx);
|
|
|
|
insert = 1;
|
|
|
|
}
|
|
|
|
|
2009-08-09 19:32:06 +02:00
|
|
|
/* Check this will fit on the current line and wrap if not. */
|
2010-04-05 07:11:44 +02:00
|
|
|
if ((s->mode & MODE_WRAP) && s->cx > screen_size_x(s) - width) {
|
2009-10-23 19:11:26 +02:00
|
|
|
screen_write_linefeed(ctx, 1);
|
2009-10-15 03:41:14 +02:00
|
|
|
s->cx = 0; /* carriage return */
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/* Sanity checks. */
|
2011-03-24 18:03:29 +01:00
|
|
|
if (((s->mode & MODE_WRAP) && s->cx > screen_size_x(s) - width)
|
2011-04-18 23:06:49 +02:00
|
|
|
|| s->cy > screen_size_y(s) - 1)
|
2008-09-25 22:08:57 +02:00
|
|
|
return;
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2009-03-28 21:17:29 +01:00
|
|
|
/* Handle overwriting of UTF-8 characters. */
|
2010-06-16 20:09:23 +02:00
|
|
|
screen_write_overwrite(ctx, width);
|
2009-03-28 21:17:29 +01:00
|
|
|
|
2008-09-25 22:08:57 +02:00
|
|
|
/*
|
2009-03-28 21:17:29 +01:00
|
|
|
* If the new character is UTF-8 wide, fill in padding cells. Have
|
|
|
|
* already ensured there is enough room.
|
2008-09-25 22:08:57 +02:00
|
|
|
*/
|
2009-03-28 21:17:29 +01:00
|
|
|
for (xx = s->cx + 1; xx < s->cx + width; xx++) {
|
2009-07-29 00:41:38 +02:00
|
|
|
tmp_gcp = grid_view_get_cell(gd, xx, s->cy);
|
|
|
|
if (tmp_gcp != NULL)
|
|
|
|
tmp_gcp->flags |= GRID_FLAG_PADDING;
|
2009-03-28 21:17:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the cell. */
|
|
|
|
grid_view_set_cell(gd, s->cx, s->cy, gc);
|
2009-05-04 19:58:27 +02:00
|
|
|
|
2009-03-28 21:17:29 +01:00
|
|
|
/* Move the cursor. */
|
|
|
|
s->cx += width;
|
|
|
|
|
|
|
|
/* Draw to the screen if necessary. */
|
2009-07-23 14:48:18 +02:00
|
|
|
if (insert) {
|
|
|
|
ttyctx.num = width;
|
|
|
|
tty_write(tty_cmd_insertcharacter, &ttyctx);
|
|
|
|
}
|
2009-03-30 22:14:50 +02:00
|
|
|
if (screen_check_selection(s, s->cx - width, s->cy)) {
|
2009-10-23 19:08:30 +02:00
|
|
|
memcpy(&tmp_gc, &s->sel.cell, sizeof tmp_gc);
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_get(gc, &ud);
|
|
|
|
grid_cell_set(&tmp_gc, &ud);
|
|
|
|
tmp_gc.flags = gc->flags & ~(GRID_FLAG_FG256|GRID_FLAG_BG256);
|
2009-10-23 19:08:30 +02:00
|
|
|
tmp_gc.flags |= s->sel.cell.flags &
|
2009-10-15 03:35:35 +02:00
|
|
|
(GRID_FLAG_FG256|GRID_FLAG_BG256);
|
2009-10-23 19:08:30 +02:00
|
|
|
ttyctx.cell = &tmp_gc;
|
2009-07-23 14:38:01 +02:00
|
|
|
tty_write(tty_cmd_cell, &ttyctx);
|
2009-07-22 20:08:56 +02:00
|
|
|
} else {
|
|
|
|
ttyctx.cell = gc;
|
2009-07-23 14:38:01 +02:00
|
|
|
tty_write(tty_cmd_cell, &ttyctx);
|
2009-07-22 20:08:56 +02:00
|
|
|
}
|
2009-03-28 21:17:29 +01:00
|
|
|
}
|
|
|
|
|
2009-10-23 19:13:10 +02:00
|
|
|
/* Combine a UTF-8 zero-width character onto the previous. */
|
|
|
|
int
|
2013-01-18 03:16:21 +01:00
|
|
|
screen_write_combine(struct screen_write_ctx *ctx, const struct utf8_data *ud)
|
2009-10-23 19:13:10 +02:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
|
|
|
struct grid_cell *gc;
|
2013-01-18 03:16:21 +01:00
|
|
|
struct utf8_data ud1;
|
2009-10-23 19:13:10 +02:00
|
|
|
|
|
|
|
/* Can't combine if at 0. */
|
|
|
|
if (s->cx == 0)
|
|
|
|
return (-1);
|
|
|
|
|
2013-01-18 03:16:21 +01:00
|
|
|
/* Empty data is out. */
|
|
|
|
if (ud->size == 0)
|
2009-11-13 17:54:04 +01:00
|
|
|
fatalx("UTF-8 data empty");
|
|
|
|
|
2013-01-18 03:16:21 +01:00
|
|
|
/* Retrieve the previous cell. */
|
2009-10-23 19:13:10 +02:00
|
|
|
gc = grid_view_get_cell(gd, s->cx - 1, s->cy);
|
2013-01-18 03:16:21 +01:00
|
|
|
grid_cell_get(gc, &ud1);
|
2009-10-23 19:13:10 +02:00
|
|
|
|
2013-01-18 03:16:21 +01:00
|
|
|
/* Check there is enough space. */
|
|
|
|
if (ud1.size + ud->size > sizeof ud1.data)
|
|
|
|
return (-1);
|
2009-10-23 19:13:10 +02:00
|
|
|
|
2013-01-18 03:16:21 +01:00
|
|
|
/* Append the data and set the cell. */
|
|
|
|
memcpy(ud1.data + ud1.size, ud->data, ud->size);
|
|
|
|
ud1.size += ud->size;
|
|
|
|
grid_cell_set(gc, &ud1);
|
2009-10-23 19:13:10 +02:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-03-28 21:17:29 +01: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.
|
|
|
|
*/
|
|
|
|
void
|
2010-06-16 20:09:23 +02:00
|
|
|
screen_write_overwrite(struct screen_write_ctx *ctx, u_int width)
|
2009-03-28 21:17:29 +01:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
|
|
|
const struct grid_cell *gc;
|
|
|
|
u_int xx;
|
|
|
|
|
|
|
|
gc = grid_view_peek_cell(gd, s->cx, s->cy);
|
|
|
|
if (gc->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) {
|
2009-03-28 21:17:29 +01:00
|
|
|
gc = grid_view_peek_cell(gd, xx, s->cy);
|
|
|
|
if (!(gc->flags & GRID_FLAG_PADDING))
|
2008-09-25 22:08:57 +02:00
|
|
|
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);
|
2010-06-16 20:09:23 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
|
2010-06-16 20:09:23 +02:00
|
|
|
/*
|
|
|
|
* Overwrite any padding cells that belong to a UTF-8 character
|
|
|
|
* we'll be overwriting with the current character.
|
|
|
|
*/
|
|
|
|
xx = s->cx + width - 1;
|
|
|
|
while (++xx < screen_size_x(s)) {
|
|
|
|
gc = grid_view_peek_cell(gd, xx, s->cy);
|
|
|
|
if (!(gc->flags & GRID_FLAG_PADDING))
|
|
|
|
break;
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
2008-09-25 22:08:57 +02:00
|
|
|
}
|
2007-12-06 10:46:23 +01:00
|
|
|
}
|
2011-03-20 00:30:37 +01:00
|
|
|
|
2011-05-22 18:23:07 +02:00
|
|
|
void
|
|
|
|
screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len)
|
|
|
|
{
|
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
|
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
|
|
|
ttyctx.ptr = str;
|
|
|
|
ttyctx.num = len;
|
|
|
|
|
|
|
|
tty_write(tty_cmd_setselection, &ttyctx);
|
|
|
|
}
|
|
|
|
|
2011-03-20 00:30:37 +01:00
|
|
|
void
|
|
|
|
screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len)
|
|
|
|
{
|
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
|
|
|
|
screen_write_initctx(ctx, &ttyctx, 0);
|
|
|
|
ttyctx.ptr = str;
|
|
|
|
ttyctx.num = len;
|
|
|
|
|
|
|
|
tty_write(tty_cmd_rawstring, &ttyctx);
|
|
|
|
}
|