2009-06-01 22:58:49 +00:00
|
|
|
/* $OpenBSD$ */
|
|
|
|
|
|
|
|
/*
|
2016-01-19 15:59:12 +00:00
|
|
|
* Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
|
2009-06-01 22:58:49 +00:00
|
|
|
*
|
|
|
|
* 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-10 11:53:01 +00:00
|
|
|
#include <stdlib.h>
|
2009-06-01 22:58:49 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "tmux.h"
|
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
static void screen_write_initctx(struct screen_write_ctx *,
|
|
|
|
struct tty_ctx *);
|
|
|
|
static void screen_write_save_last(struct screen_write_ctx *,
|
|
|
|
struct tty_ctx *);
|
2016-07-15 00:49:08 +00:00
|
|
|
static void screen_write_flush(struct screen_write_ctx *);
|
2016-05-27 23:02:17 +00:00
|
|
|
|
2016-05-30 09:32:24 +00:00
|
|
|
static int screen_write_overwrite(struct screen_write_ctx *,
|
|
|
|
struct grid_cell *, u_int);
|
2016-05-27 23:02:17 +00:00
|
|
|
static int screen_write_combine(struct screen_write_ctx *,
|
|
|
|
const struct utf8_data *);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:06:12 +00:00
|
|
|
static const struct grid_cell screen_write_pad_cell = {
|
2016-07-15 00:49:08 +00:00
|
|
|
GRID_FLAG_PADDING, 0, 8, 8, { { 0 }, 0, 0, 0 }
|
2016-05-27 23:06:12 +00:00
|
|
|
};
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
#define screen_dirty_bit(s, x, y) (((y) * screen_size_x(s)) + (x))
|
|
|
|
#define screen_dirty_clear(s, sx, sy, ex, ey) \
|
|
|
|
do { \
|
|
|
|
if (s->dirty != NULL) { \
|
|
|
|
bit_nclear(s->dirty, \
|
|
|
|
screen_dirty_bit(s, sx, sy), \
|
|
|
|
screen_dirty_bit(s, ex, ey)); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/* Initialize writing with a window. */
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2014-10-20 23:57:13 +00:00
|
|
|
screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp,
|
|
|
|
struct screen *s)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int size;
|
|
|
|
char tmp[16];
|
|
|
|
const char *cp = tmp;
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
ctx->wp = wp;
|
|
|
|
if (wp != NULL && s == NULL)
|
|
|
|
ctx->s = wp->screen;
|
|
|
|
else
|
|
|
|
ctx->s = s;
|
2016-07-15 00:49:08 +00:00
|
|
|
|
|
|
|
size = screen_size_x(ctx->s) * screen_size_y(ctx->s);
|
|
|
|
if (ctx->s->dirtysize != size) {
|
|
|
|
free(ctx->s->dirty);
|
|
|
|
ctx->s->dirty = NULL;
|
|
|
|
ctx->s->dirtysize = size;
|
|
|
|
}
|
|
|
|
ctx->dirty = 0;
|
|
|
|
|
|
|
|
ctx->cells = ctx->written = ctx->skipped = 0;
|
|
|
|
|
|
|
|
if (wp == NULL)
|
|
|
|
cp = "no pane";
|
|
|
|
else
|
|
|
|
snprintf(tmp, sizeof tmp, "pane %%%u", wp->id);
|
|
|
|
log_debug("%s: size %ux%u, %s", __func__, screen_size_x(ctx->s),
|
|
|
|
screen_size_y(ctx->s), cp);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Finish writing. */
|
|
|
|
void
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_stop(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
screen_write_flush(ctx);
|
|
|
|
|
|
|
|
log_debug("%s: %u of %u written (dirty %u, skipped %u)", __func__,
|
|
|
|
ctx->written, ctx->cells, ctx->cells - ctx->written, ctx->skipped);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Flush outstanding cell writes. */
|
|
|
|
static void
|
|
|
|
screen_write_flush(struct screen_write_ctx *ctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-07-15 00:49:08 +00:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
u_int x, y, offset, cx, cy, dirty;
|
|
|
|
struct grid_cell gc;
|
|
|
|
|
|
|
|
if (ctx->dirty == 0)
|
|
|
|
return;
|
|
|
|
dirty = 0;
|
|
|
|
|
|
|
|
cx = s->cx;
|
|
|
|
cy = s->cy;
|
|
|
|
|
|
|
|
offset = 0;
|
|
|
|
for (y = 0; y < screen_size_y(s); y++) {
|
|
|
|
for (x = 0; x < screen_size_x(s); x++) {
|
|
|
|
offset++;
|
|
|
|
if (!bit_test(s->dirty, offset - 1))
|
|
|
|
continue;
|
|
|
|
bit_clear(s->dirty, offset - 1);
|
|
|
|
|
|
|
|
screen_write_cursormove(ctx, x, y);
|
|
|
|
grid_view_get_cell(s->grid, x, y, &gc);
|
|
|
|
|
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
|
|
|
ttyctx.cell = &gc;
|
|
|
|
tty_write(tty_cmd_cell, &ttyctx);
|
|
|
|
ctx->written++;
|
|
|
|
|
|
|
|
if (++dirty == ctx->dirty)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (dirty == ctx->dirty)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->cx = cx;
|
|
|
|
s->cy = cy;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2012-01-21 08:10:21 +00:00
|
|
|
/* Reset screen state. */
|
|
|
|
void
|
|
|
|
screen_write_reset(struct screen_write_ctx *ctx)
|
|
|
|
{
|
2013-03-21 18:47:56 +00:00
|
|
|
struct screen *s = ctx->s;
|
2012-01-21 08:10:21 +00:00
|
|
|
|
2013-03-21 18:47:56 +00:00
|
|
|
screen_reset_tabs(s);
|
|
|
|
screen_write_scrollregion(ctx, 0, screen_size_y(s) - 1);
|
2013-03-22 10:33:50 +00:00
|
|
|
|
2013-05-15 15:32:14 +00:00
|
|
|
s->mode &= ~(MODE_INSERT|MODE_KCURSOR|MODE_KKEYPAD|MODE_FOCUSON);
|
2015-11-23 23:47:57 +00:00
|
|
|
s->mode &= ~(ALL_MOUSE_MODES|MODE_MOUSE_UTF8|MODE_MOUSE_SGR);
|
2012-01-21 08:10:21 +00:00
|
|
|
|
|
|
|
screen_write_clearscreen(ctx);
|
|
|
|
screen_write_cursormove(ctx, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Write character. */
|
|
|
|
void
|
2016-04-29 13:21:33 +00:00
|
|
|
screen_write_putc(struct screen_write_ctx *ctx, const struct grid_cell *gcp,
|
2014-04-17 14:45:49 +00:00
|
|
|
u_char ch)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-04-29 13:21:33 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
|
|
|
|
memcpy(&gc, gcp, sizeof gc);
|
|
|
|
|
|
|
|
utf8_set(&gc.data, ch);
|
|
|
|
screen_write_cell(ctx, &gc);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 10:49:32 +00:00
|
|
|
/* Calculate string length, with embedded formatting. */
|
2014-10-20 23:57:13 +00:00
|
|
|
size_t
|
2015-11-12 11:09:11 +00:00
|
|
|
screen_write_cstrlen(const char *fmt, ...)
|
2009-09-07 10:49:32 +00:00
|
|
|
{
|
|
|
|
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';
|
|
|
|
|
2015-11-12 11:09:11 +00:00
|
|
|
size = screen_write_strlen("%s", msg2);
|
2009-09-07 10:49:32 +00:00
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(msg);
|
|
|
|
free(msg2);
|
2009-09-07 10:49:32 +00:00
|
|
|
|
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
|
2009-06-03 16:05:46 +00:00
|
|
|
/* Calculate string length. */
|
2014-10-20 23:57:13 +00:00
|
|
|
size_t
|
2015-11-12 11:09:11 +00:00
|
|
|
screen_write_strlen(const char *fmt, ...)
|
2009-06-03 16:05:46 +00:00
|
|
|
{
|
2009-10-20 19:18:28 +00:00
|
|
|
va_list ap;
|
|
|
|
char *msg;
|
2015-11-12 22:04:37 +00:00
|
|
|
struct utf8_data ud;
|
2009-10-20 19:18:28 +00:00
|
|
|
u_char *ptr;
|
|
|
|
size_t left, size = 0;
|
2015-11-14 11:45:43 +00:00
|
|
|
enum utf8_state more;
|
2009-06-03 16:05:46 +00:00
|
|
|
|
|
|
|
va_start(ap, fmt);
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
ptr = msg;
|
|
|
|
while (*ptr != '\0') {
|
2015-11-14 11:45:43 +00:00
|
|
|
if (*ptr > 0x7f && utf8_open(&ud, *ptr) == UTF8_MORE) {
|
2009-10-20 19:18:28 +00:00
|
|
|
ptr++;
|
2009-06-03 16:05:46 +00:00
|
|
|
|
|
|
|
left = strlen(ptr);
|
2015-11-13 08:09:28 +00:00
|
|
|
if (left < (size_t)ud.size - 1)
|
2009-10-20 19:18:28 +00:00
|
|
|
break;
|
2015-11-14 11:45:43 +00:00
|
|
|
while ((more = utf8_append(&ud, *ptr)) == UTF8_MORE)
|
2009-06-03 16:05:46 +00:00
|
|
|
ptr++;
|
2009-10-20 19:18:28 +00:00
|
|
|
ptr++;
|
|
|
|
|
2015-11-14 11:45:43 +00:00
|
|
|
if (more == UTF8_DONE)
|
2015-11-14 10:56:31 +00:00
|
|
|
size += ud.width;
|
2009-06-03 16:05:46 +00:00
|
|
|
} else {
|
2015-11-12 11:09:11 +00:00
|
|
|
if (*ptr > 0x1f && *ptr < 0x7f)
|
|
|
|
size++;
|
2009-06-03 16:05:46 +00:00
|
|
|
ptr++;
|
|
|
|
}
|
2009-06-05 03:13:16 +00:00
|
|
|
}
|
2009-06-03 16:05:46 +00:00
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(msg);
|
2009-06-03 16:05:46 +00:00
|
|
|
return (size);
|
|
|
|
}
|
|
|
|
|
2009-06-03 16:54:26 +00:00
|
|
|
/* Write simple string (no UTF-8 or maximum length). */
|
2014-10-20 23:57:13 +00:00
|
|
|
void
|
2016-04-29 13:21:33 +00:00
|
|
|
screen_write_puts(struct screen_write_ctx *ctx, const struct grid_cell *gcp,
|
2014-10-20 23:57:13 +00:00
|
|
|
const char *fmt, ...)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2016-04-29 13:21:33 +00:00
|
|
|
screen_write_vnputs(ctx, -1, gcp, fmt, ap);
|
2009-06-01 22:58:49 +00:00
|
|
|
va_end(ap);
|
2009-06-03 16:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write string with length limit (-1 for unlimited). */
|
2014-10-20 23:57:13 +00:00
|
|
|
void
|
|
|
|
screen_write_nputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
2016-04-29 13:21:33 +00:00
|
|
|
const struct grid_cell *gcp, const char *fmt, ...)
|
2009-06-03 16:05:46 +00:00
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
va_start(ap, fmt);
|
2016-04-29 13:21:33 +00:00
|
|
|
screen_write_vnputs(ctx, maxlen, gcp, fmt, ap);
|
2009-06-03 16:05:46 +00:00
|
|
|
va_end(ap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2009-06-03 16:54:26 +00:00
|
|
|
screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
2016-04-29 13:21:33 +00:00
|
|
|
const struct grid_cell *gcp, const char *fmt, va_list ap)
|
2009-06-03 16:05:46 +00:00
|
|
|
{
|
2016-04-29 13:21:33 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
struct utf8_data *ud = &gc.data;
|
2009-10-20 19:18:28 +00:00
|
|
|
char *msg;
|
|
|
|
u_char *ptr;
|
|
|
|
size_t left, size = 0;
|
2015-11-14 11:45:43 +00:00
|
|
|
enum utf8_state more;
|
2009-06-03 16:05:46 +00:00
|
|
|
|
2016-04-29 13:21:33 +00:00
|
|
|
memcpy(&gc, gcp, sizeof gc);
|
2009-06-03 16:05:46 +00:00
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
|
|
|
|
ptr = msg;
|
|
|
|
while (*ptr != '\0') {
|
2016-04-29 13:21:33 +00:00
|
|
|
if (*ptr > 0x7f && utf8_open(ud, *ptr) == UTF8_MORE) {
|
2009-10-20 19:18:28 +00:00
|
|
|
ptr++;
|
2009-06-03 16:05:46 +00:00
|
|
|
|
|
|
|
left = strlen(ptr);
|
2016-04-29 13:21:33 +00:00
|
|
|
if (left < (size_t)ud->size - 1)
|
2009-10-20 19:18:28 +00:00
|
|
|
break;
|
2016-04-29 13:21:33 +00:00
|
|
|
while ((more = utf8_append(ud, *ptr)) == UTF8_MORE)
|
2009-06-03 16:05:46 +00:00
|
|
|
ptr++;
|
2009-10-20 19:18:28 +00:00
|
|
|
ptr++;
|
2009-06-05 03:13:16 +00:00
|
|
|
|
2016-04-29 13:21:33 +00:00
|
|
|
if (more != UTF8_DONE)
|
|
|
|
continue;
|
|
|
|
if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
|
|
|
|
while (size < (size_t)maxlen) {
|
|
|
|
screen_write_putc(ctx, &gc, ' ');
|
|
|
|
size++;
|
2009-06-03 16:05:46 +00:00
|
|
|
}
|
2016-04-29 13:21:33 +00:00
|
|
|
break;
|
2015-11-14 10:56:31 +00:00
|
|
|
}
|
2016-04-29 13:21:33 +00:00
|
|
|
size += ud->width;
|
|
|
|
screen_write_cell(ctx, &gc);
|
2009-06-03 16:05:46 +00:00
|
|
|
} else {
|
2016-04-29 13:21:33 +00:00
|
|
|
if (maxlen > 0 && size + 1 > (size_t)maxlen)
|
2009-06-03 16:05:46 +00:00
|
|
|
break;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2012-09-24 12:53:55 +00:00
|
|
|
if (*ptr == '\001')
|
2016-04-29 13:21:33 +00:00
|
|
|
gc.attr ^= GRID_ATTR_CHARSET;
|
2015-11-12 11:09:11 +00:00
|
|
|
else if (*ptr > 0x1f && *ptr < 0x7f) {
|
2012-09-24 12:53:55 +00:00
|
|
|
size++;
|
2016-04-29 13:21:33 +00:00
|
|
|
screen_write_putc(ctx, &gc, *ptr);
|
2012-09-24 12:53:55 +00:00
|
|
|
}
|
2009-06-03 16:05:46 +00:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(msg);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-09-07 10:49:32 +00:00
|
|
|
/* Write string, similar to nputs, but with embedded formatting (#[]). */
|
2014-10-20 23:57:13 +00:00
|
|
|
void
|
2015-11-12 11:09:11 +00:00
|
|
|
screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
|
2016-04-29 13:21:33 +00:00
|
|
|
const struct grid_cell *gcp, const char *fmt, ...)
|
2009-09-07 10:49:32 +00:00
|
|
|
{
|
2016-04-29 13:21:33 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
struct utf8_data *ud = &gc.data;
|
2009-09-07 10:49:32 +00:00
|
|
|
va_list ap;
|
|
|
|
char *msg;
|
2009-10-20 19:18:28 +00:00
|
|
|
u_char *ptr, *last;
|
2009-09-07 10:49:32 +00:00
|
|
|
size_t left, size = 0;
|
2015-11-14 11:45:43 +00:00
|
|
|
enum utf8_state more;
|
2009-09-07 10:49:32 +00:00
|
|
|
|
2016-04-29 13:21:33 +00:00
|
|
|
memcpy(&gc, gcp, sizeof gc);
|
|
|
|
|
2009-09-07 10:49:32 +00:00
|
|
|
va_start(ap, fmt);
|
|
|
|
xvasprintf(&msg, fmt, ap);
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
2016-04-29 13:21:33 +00:00
|
|
|
style_parse(gcp, &gc, ptr);
|
2009-09-07 10:49:32 +00:00
|
|
|
ptr = last + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-29 13:21:33 +00:00
|
|
|
if (*ptr > 0x7f && utf8_open(ud, *ptr) == UTF8_MORE) {
|
2009-10-20 19:18:28 +00:00
|
|
|
ptr++;
|
2009-09-07 10:49:32 +00:00
|
|
|
|
|
|
|
left = strlen(ptr);
|
2016-04-29 13:21:33 +00:00
|
|
|
if (left < (size_t)ud->size - 1)
|
2009-10-20 19:18:28 +00:00
|
|
|
break;
|
2016-04-29 13:21:33 +00:00
|
|
|
while ((more = utf8_append(ud, *ptr)) == UTF8_MORE)
|
2009-09-07 10:49:32 +00:00
|
|
|
ptr++;
|
2009-10-20 19:18:28 +00:00
|
|
|
ptr++;
|
2009-09-07 10:49:32 +00:00
|
|
|
|
2016-04-29 13:21:33 +00:00
|
|
|
if (more != UTF8_DONE)
|
|
|
|
continue;
|
|
|
|
if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
|
|
|
|
while (size < (size_t)maxlen) {
|
|
|
|
screen_write_putc(ctx, &gc, ' ');
|
|
|
|
size++;
|
2009-09-07 10:49:32 +00:00
|
|
|
}
|
2016-04-29 13:21:33 +00:00
|
|
|
break;
|
2015-11-14 10:56:31 +00:00
|
|
|
}
|
2016-04-29 13:21:33 +00:00
|
|
|
size += ud->width;
|
|
|
|
screen_write_cell(ctx, &gc);
|
2009-09-07 10:49:32 +00:00
|
|
|
} else {
|
2016-04-29 13:21:33 +00:00
|
|
|
if (maxlen > 0 && size + 1 > (size_t)maxlen)
|
2009-09-07 10:49:32 +00:00
|
|
|
break;
|
|
|
|
|
2015-11-12 11:09:11 +00:00
|
|
|
if (*ptr > 0x1f && *ptr < 0x7f) {
|
|
|
|
size++;
|
2016-04-29 13:21:33 +00:00
|
|
|
screen_write_putc(ctx, &gc, *ptr);
|
2015-11-12 11:09:11 +00:00
|
|
|
}
|
2009-09-07 10:49:32 +00:00
|
|
|
ptr++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-10 11:53:01 +00:00
|
|
|
free(msg);
|
2009-09-07 10:49:32 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Copy from another screen. */
|
|
|
|
void
|
2016-10-05 12:36:36 +00:00
|
|
|
screen_write_copy(struct screen_write_ctx *ctx, struct screen *src, u_int px,
|
|
|
|
u_int py, u_int nx, u_int ny)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = src->grid;
|
2009-08-13 16:24:33 +00:00
|
|
|
struct grid_line *gl;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2009-11-18 17:02:17 +00:00
|
|
|
u_int xx, yy, cx, cy, ax, bx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
cx = s->cx;
|
|
|
|
cy = s->cy;
|
|
|
|
for (yy = py; yy < py + ny; yy++) {
|
2009-08-13 16:24:33 +00:00
|
|
|
gl = &gd->linedata[yy];
|
2009-09-15 15:14:09 +00: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-03 22:50:09 +00:00
|
|
|
|
2009-09-15 15:14:09 +00:00
|
|
|
for (xx = ax; xx < bx; xx++) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_get_cell(gd, xx, yy, &gc);
|
|
|
|
screen_write_cell(ctx, &gc);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2009-09-15 15:14:09 +00:00
|
|
|
if (px + nx == gd->sx && px + nx > gl->cellsize)
|
|
|
|
screen_write_clearendofline(ctx);
|
|
|
|
} else
|
2009-10-20 19:18:28 +00:00
|
|
|
screen_write_clearline(ctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
cy++;
|
|
|
|
screen_write_cursormove(ctx, cx, cy);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
/* Set up context for TTY command. */
|
2016-05-27 23:02:17 +00:00
|
|
|
static void
|
|
|
|
screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2016-05-27 23:02:17 +00:00
|
|
|
struct screen *s = ctx->s;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx->wp = ctx->wp;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx->ocx = s->cx;
|
|
|
|
ttyctx->ocy = s->cy;
|
|
|
|
|
|
|
|
ttyctx->orlower = s->rlower;
|
|
|
|
ttyctx->orupper = s->rupper;
|
2016-05-27 23:02:17 +00:00
|
|
|
}
|
2009-10-17 08:24:46 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
/* Save last cell on screen. */
|
|
|
|
static void
|
|
|
|
screen_write_save_last(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
|
|
|
struct grid_cell gc;
|
|
|
|
u_int xx;
|
2009-10-17 08:24:46 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
2009-11-16 13:40:45 +00:00
|
|
|
for (xx = 1; xx <= screen_size_x(s); xx++) {
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_view_get_cell(gd, screen_size_x(s) - xx, s->cy, &gc);
|
|
|
|
if (~gc.flags & GRID_FLAG_PADDING)
|
2009-10-17 08:24:46 +00:00
|
|
|
break;
|
|
|
|
}
|
2015-11-13 08:09:28 +00:00
|
|
|
memcpy(&ttyctx->last_cell, &gc, sizeof ttyctx->last_cell);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-21 18:47:56 +00: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;
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Cursor up by ny. */
|
|
|
|
void
|
|
|
|
screen_write_cursorup(struct screen_write_ctx *ctx, u_int ny)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2009-07-09 17:57:11 +00: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;
|
|
|
|
}
|
2013-03-27 11:19:19 +00:00
|
|
|
if (s->cx == screen_size_x(s))
|
|
|
|
s->cx--;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s->cy -= ny;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cursor down by ny. */
|
|
|
|
void
|
|
|
|
screen_write_cursordown(struct screen_write_ctx *ctx, u_int ny)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2009-07-09 17:57:11 +00: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;
|
|
|
|
}
|
2013-03-27 11:19:19 +00:00
|
|
|
if (s->cx == screen_size_x(s))
|
|
|
|
s->cx--;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s->cy += ny;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cursor right by nx. */
|
|
|
|
void
|
|
|
|
screen_write_cursorright(struct screen_write_ctx *ctx, u_int nx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
|
|
|
if (nx > screen_size_x(s) - 1 - s->cx)
|
|
|
|
nx = screen_size_x(s) - 1 - s->cx;
|
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s->cx += nx;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Cursor left by nx. */
|
|
|
|
void
|
|
|
|
screen_write_cursorleft(struct screen_write_ctx *ctx, u_int nx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
|
|
|
if (nx > s->cx)
|
|
|
|
nx = s->cx;
|
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
s->cx -= nx;
|
|
|
|
}
|
|
|
|
|
2009-10-12 16:59:55 +00: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-03 23:30:40 +00:00
|
|
|
/* VT100 alignment test. */
|
|
|
|
void
|
|
|
|
screen_write_alignmenttest(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2009-06-03 23:30:40 +00:00
|
|
|
struct grid_cell gc;
|
|
|
|
u_int xx, yy;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
2009-06-03 23:30:40 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-07-22 20:53:38 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_dirty_clear(s, 0, 0, sx - 1, sy - 1);
|
|
|
|
|
2009-06-03 23:30:40 +00:00
|
|
|
memcpy(&gc, &grid_default_cell, sizeof gc);
|
2015-11-13 08:09:28 +00:00
|
|
|
utf8_set(&gc.data, 'E');
|
2009-06-05 03:13:16 +00:00
|
|
|
|
2009-06-03 23:30:40 +00: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-05 03:13:16 +00:00
|
|
|
|
2009-06-03 23:30:40 +00:00
|
|
|
s->cx = 0;
|
|
|
|
s->cy = 0;
|
|
|
|
|
|
|
|
s->rupper = 0;
|
|
|
|
s->rlower = screen_size_y(s) - 1;
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_write(tty_cmd_alignmenttest, &ttyctx);
|
2009-06-03 23:30:40 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Insert nx characters. */
|
|
|
|
void
|
|
|
|
screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
2009-06-29 21:30:50 +00:00
|
|
|
if (nx > screen_size_x(s) - s->cx)
|
|
|
|
nx = screen_size_x(s) - s->cx;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_flush(ctx);
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (s->cx <= screen_size_x(s) - 1)
|
|
|
|
grid_view_insert_cells(s->grid, s->cx, s->cy, nx);
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx.num = nx;
|
|
|
|
tty_write(tty_cmd_insertcharacter, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete nx characters. */
|
|
|
|
void
|
|
|
|
screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (nx == 0)
|
|
|
|
nx = 1;
|
|
|
|
|
2009-06-29 21:30:50 +00:00
|
|
|
if (nx > screen_size_x(s) - s->cx)
|
|
|
|
nx = screen_size_x(s) - s->cx;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (nx == 0)
|
|
|
|
return;
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_flush(ctx);
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (s->cx <= screen_size_x(s) - 1)
|
|
|
|
grid_view_delete_cells(s->grid, s->cx, s->cy, nx);
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx.num = nx;
|
|
|
|
tty_write(tty_cmd_deletecharacter, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-01-15 23:18:55 +00: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;
|
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2013-01-15 23:18:55 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cx <= screen_size_x(s) - 1) {
|
|
|
|
screen_dirty_clear(s, s->cx, s->cy, s->cx + nx - 1, s->cy);
|
2013-01-15 23:18:55 +00:00
|
|
|
grid_view_clear(s->grid, s->cx, s->cy, nx, 1);
|
2016-07-15 00:49:08 +00:00
|
|
|
} else
|
|
|
|
return;
|
2013-01-15 23:18:55 +00:00
|
|
|
|
|
|
|
ttyctx.num = nx;
|
|
|
|
tty_write(tty_cmd_clearcharacter, &ttyctx);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Insert ny lines. */
|
|
|
|
void
|
|
|
|
screen_write_insertline(struct screen_write_ctx *ctx, u_int ny)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2009-07-09 07:58:14 +00: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;
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_flush(ctx);
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-07-09 07:58:14 +00:00
|
|
|
|
|
|
|
grid_view_insert_lines(s->grid, s->cy, ny);
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_insertline, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
2009-07-09 07:58:14 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-09 07:58:14 +00:00
|
|
|
if (ny > s->rlower + 1 - s->cy)
|
|
|
|
ny = s->rlower + 1 - s->cy;
|
|
|
|
if (ny == 0)
|
|
|
|
return;
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_flush(ctx);
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (s->cy < s->rupper || s->cy > s->rlower)
|
|
|
|
grid_view_insert_lines(s->grid, s->cy, ny);
|
2009-07-09 00:29:32 +00:00
|
|
|
else
|
|
|
|
grid_view_insert_lines_region(s->grid, s->rlower, s->cy, ny);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_insertline, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete ny lines. */
|
|
|
|
void
|
|
|
|
screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (ny == 0)
|
|
|
|
ny = 1;
|
|
|
|
|
2009-07-09 07:58:14 +00: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;
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_flush(ctx);
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-07-09 07:58:14 +00:00
|
|
|
|
|
|
|
grid_view_delete_lines(s->grid, s->cy, ny);
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_deleteline, &ttyctx);
|
2009-07-09 07:58:14 +00:00
|
|
|
return;
|
|
|
|
}
|
2009-12-03 22:50:09 +00:00
|
|
|
|
2009-07-09 07:58:14 +00:00
|
|
|
if (ny > s->rlower + 1 - s->cy)
|
|
|
|
ny = s->rlower + 1 - s->cy;
|
2009-06-01 22:58:49 +00:00
|
|
|
if (ny == 0)
|
|
|
|
return;
|
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_flush(ctx);
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
if (s->cy < s->rupper || s->cy > s->rlower)
|
|
|
|
grid_view_delete_lines(s->grid, s->cy, ny);
|
2009-07-09 00:29:32 +00:00
|
|
|
else
|
|
|
|
grid_view_delete_lines_region(s->grid, s->rlower, s->cy, ny);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx.num = ny;
|
|
|
|
tty_write(tty_cmd_deleteline, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear line at cursor. */
|
|
|
|
void
|
|
|
|
screen_write_clearline(struct screen_write_ctx *ctx)
|
|
|
|
{
|
2016-07-15 00:49:08 +00:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid_line *gl;
|
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
u_int sx = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
|
|
|
if (gl->cellsize != 0) {
|
|
|
|
screen_dirty_clear(s, 0, s->cy, sx - 1, s->cy);
|
|
|
|
grid_view_clear(s->grid, 0, s->cy, sx, 1);
|
|
|
|
} else
|
|
|
|
return;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_write(tty_cmd_clearline, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear to end of line from cursor. */
|
|
|
|
void
|
|
|
|
screen_write_clearendofline(struct screen_write_ctx *ctx)
|
|
|
|
{
|
2016-07-15 00:49:08 +00:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid_line *gl;
|
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
u_int sx = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
|
|
|
if (s->cx <= sx - 1 && s->cx < gl->cellsize) {
|
|
|
|
screen_dirty_clear(s, s->cx, s->cy, sx - 1, s->cy);
|
2009-06-01 22:58:49 +00:00
|
|
|
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
2016-07-15 00:49:08 +00:00
|
|
|
} else
|
|
|
|
return;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_write(tty_cmd_clearendofline, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear to start of line from cursor. */
|
|
|
|
void
|
|
|
|
screen_write_clearstartofline(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int sx = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cx > sx - 1) {
|
|
|
|
screen_dirty_clear(s, 0, s->cy, sx - 1, s->cy);
|
2009-06-01 22:58:49 +00:00
|
|
|
grid_view_clear(s->grid, 0, s->cy, sx, 1);
|
2016-07-15 00:49:08 +00:00
|
|
|
} else {
|
|
|
|
screen_dirty_clear(s, 0, s->cy, s->cx, s->cy);
|
2009-06-01 22:58:49 +00:00
|
|
|
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
|
2016-07-15 00:49:08 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_write(tty_cmd_clearstartofline, &ttyctx);
|
2009-06-01 22:58:49 +00: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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reverse index (up with scroll). */
|
|
|
|
void
|
|
|
|
screen_write_reverseindex(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cy == s->rupper) {
|
|
|
|
screen_write_flush(ctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
grid_view_scroll_region_down(s->grid, s->rupper, s->rlower);
|
2016-07-15 00:49:08 +00:00
|
|
|
} else if (s->cy > 0)
|
2009-06-01 22:58:49 +00:00
|
|
|
s->cy--;
|
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_write(tty_cmd_reverseindex, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set scroll region. */
|
|
|
|
void
|
2015-12-11 16:37:21 +00:00
|
|
|
screen_write_scrollregion(struct screen_write_ctx *ctx, u_int rupper,
|
|
|
|
u_int rlower)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
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-14 14:47:32 +00:00
|
|
|
if (rupper >= rlower) /* cannot be one line */
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Cursor moves to top-left. */
|
|
|
|
s->cx = 0;
|
|
|
|
s->cy = 0;
|
|
|
|
|
|
|
|
s->rupper = rupper;
|
|
|
|
s->rlower = rlower;
|
|
|
|
}
|
|
|
|
|
2009-10-20 16:32:23 +00:00
|
|
|
/* Line feed. */
|
2009-06-01 22:58:49 +00:00
|
|
|
void
|
2009-10-20 16:32:23 +00:00
|
|
|
screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
2009-08-08 15:57:49 +00:00
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid_line *gl;
|
2009-10-20 16:32:23 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
2009-10-20 16:32:23 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-08-08 15:57:49 +00:00
|
|
|
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
|
|
|
if (wrapped)
|
|
|
|
gl->flags |= GRID_LINE_WRAPPED;
|
2015-07-13 13:28:50 +00:00
|
|
|
else
|
|
|
|
gl->flags &= ~GRID_LINE_WRAPPED;
|
2009-08-08 15:57:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cy == s->rlower) {
|
|
|
|
screen_dirty_clear(s, 0, s->rupper, sx - 1, s->rupper);
|
|
|
|
screen_write_flush(ctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
grid_view_scroll_region_up(s->grid, s->rupper, s->rlower);
|
2016-07-15 00:49:08 +00:00
|
|
|
} else if (s->cy < sy - 1)
|
2009-06-01 22:58:49 +00:00
|
|
|
s->cy++;
|
|
|
|
|
2009-10-20 16:32:23 +00:00
|
|
|
ttyctx.num = wrapped;
|
2009-12-03 22:50:09 +00:00
|
|
|
tty_write(tty_cmd_linefeed, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Carriage return (cursor to start of line). */
|
|
|
|
void
|
|
|
|
screen_write_carriagereturn(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
|
|
|
|
s->cx = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear to end of screen from cursor. */
|
|
|
|
void
|
|
|
|
screen_write_clearendofscreen(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2011-01-25 23:40:26 +00:00
|
|
|
/* Scroll into history if it is enabled and clearing entire screen. */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cy == 0 && s->grid->flags & GRID_HISTORY) {
|
|
|
|
screen_dirty_clear(s, 0, 0, sx - 1, sy - 1);
|
2011-01-25 23:40:26 +00:00
|
|
|
grid_view_clear_history(s->grid);
|
2016-07-15 00:49:08 +00:00
|
|
|
} else {
|
|
|
|
if (s->cx <= sx - 1) {
|
|
|
|
screen_dirty_clear(s, s->cx, s->cy, sx - 1, s->cy);
|
2011-01-25 23:40:26 +00:00
|
|
|
grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1);
|
2016-07-15 00:49:08 +00:00
|
|
|
}
|
|
|
|
screen_dirty_clear(s, 0, s->cy + 1, sx - 1, sy - 1);
|
2011-01-25 23:40:26 +00:00
|
|
|
grid_view_clear(s->grid, 0, s->cy + 1, sx, sy - (s->cy + 1));
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_write(tty_cmd_clearendofscreen, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear to start of screen. */
|
|
|
|
void
|
|
|
|
screen_write_clearstartofscreen(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int sx = screen_size_x(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cy > 0) {
|
|
|
|
screen_dirty_clear(s, 0, 0, sx - 1, s->cy);
|
2009-06-03 23:26:56 +00:00
|
|
|
grid_view_clear(s->grid, 0, 0, sx, s->cy);
|
2016-07-15 00:49:08 +00:00
|
|
|
}
|
|
|
|
if (s->cx > sx - 1) {
|
|
|
|
screen_dirty_clear(s, 0, s->cy, sx - 1, s->cy);
|
2009-06-01 22:58:49 +00:00
|
|
|
grid_view_clear(s->grid, 0, s->cy, sx, 1);
|
2016-07-15 00:49:08 +00:00
|
|
|
} else {
|
|
|
|
screen_dirty_clear(s, 0, s->cy, s->cx, s->cy);
|
2009-06-03 23:26:56 +00:00
|
|
|
grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1);
|
2016-07-15 00:49:08 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_write(tty_cmd_clearstartofscreen, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Clear entire screen. */
|
|
|
|
void
|
|
|
|
screen_write_clearscreen(struct screen_write_ctx *ctx)
|
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
2009-07-22 20:53:38 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_dirty_clear(s, 0, 0, sx - 1, sy - 1);
|
|
|
|
|
2011-01-25 23:40:26 +00:00
|
|
|
/* Scroll into history if it is enabled. */
|
|
|
|
if (s->grid->flags & GRID_HISTORY)
|
|
|
|
grid_view_clear_history(s->grid);
|
2015-12-11 16:37:21 +00:00
|
|
|
else
|
|
|
|
grid_view_clear(s->grid, 0, 0, sx, sy);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-07-22 20:53:38 +00:00
|
|
|
tty_write(tty_cmd_clearscreen, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2011-10-23 10:16:14 +00: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);
|
2016-09-02 20:57:20 +00:00
|
|
|
gd->hscrolled = gd->hsize = 0;
|
2011-10-23 10:16:14 +00:00
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00:00
|
|
|
/* Write cell data. */
|
|
|
|
void
|
2013-01-18 02:16:21 +00:00
|
|
|
screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
2009-07-22 16:45:31 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2013-03-22 10:36:53 +00:00
|
|
|
u_int width, xx, last;
|
2016-07-15 00:49:08 +00:00
|
|
|
u_int sx = screen_size_x(s), sy = screen_size_y(s);
|
|
|
|
struct grid_line *gl;
|
2016-05-30 09:32:24 +00:00
|
|
|
struct grid_cell tmp_gc, now_gc;
|
2016-07-15 00:49:08 +00:00
|
|
|
struct grid_cell_entry *gce;
|
|
|
|
int insert, skip, selected, wrapped = 0;
|
|
|
|
|
|
|
|
ctx->cells++;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/* Ignore padding. */
|
|
|
|
if (gc->flags & GRID_FLAG_PADDING)
|
|
|
|
return;
|
2015-11-13 08:09:28 +00:00
|
|
|
width = gc->data.width;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2009-10-17 08:32:18 +00:00
|
|
|
/*
|
|
|
|
* If this is a wide character and there is no room on the screen, for
|
|
|
|
* the entire character, don't print it.
|
|
|
|
*/
|
2016-07-15 00:49:08 +00:00
|
|
|
if (!(s->mode & MODE_WRAP) && (width > 1 &&
|
|
|
|
(width > sx || (s->cx != sx && s->cx > sx - width))))
|
2009-10-17 08:32:18 +00:00
|
|
|
return;
|
|
|
|
|
2009-10-20 17:33:33 +00:00
|
|
|
/*
|
|
|
|
* If the width is zero, combine onto the previous character, if
|
2009-12-03 22:50:09 +00:00
|
|
|
* there is space.
|
2009-10-20 17:33:33 +00:00
|
|
|
*/
|
2009-06-01 22:58:49 +00:00
|
|
|
if (width == 0) {
|
2015-11-13 08:09:28 +00:00
|
|
|
if (screen_write_combine(ctx, &gc->data) == 0) {
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2009-10-20 17:33:33 +00:00
|
|
|
tty_write(tty_cmd_utf8character, &ttyctx);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-30 09:32:24 +00:00
|
|
|
/* Initialise the redraw context. */
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2012-03-17 17:36:03 +00:00
|
|
|
|
2009-06-03 23:37:30 +00:00
|
|
|
/* If in insert mode, make space for the cells. */
|
2016-07-15 00:49:08 +00:00
|
|
|
if ((s->mode & MODE_INSERT) && s->cx <= sx - width) {
|
|
|
|
xx = sx - s->cx - width;
|
2009-06-03 23:37:30 +00:00
|
|
|
grid_move_cells(s->grid, s->cx + width, s->cx, s->cy, xx);
|
|
|
|
insert = 1;
|
2013-03-22 10:36:53 +00:00
|
|
|
} else
|
|
|
|
insert = 0;
|
2016-05-30 09:32:24 +00:00
|
|
|
skip = !insert;
|
2009-06-03 23:37:30 +00:00
|
|
|
|
2009-08-08 15:57:49 +00:00
|
|
|
/* Check this will fit on the current line and wrap if not. */
|
2016-07-15 00:49:08 +00:00
|
|
|
if ((s->mode & MODE_WRAP) && s->cx > sx - width) {
|
|
|
|
screen_write_flush(ctx);
|
|
|
|
screen_write_save_last(ctx, &ttyctx);
|
2009-10-20 16:32:23 +00:00
|
|
|
screen_write_linefeed(ctx, 1);
|
2009-10-12 17:19:47 +00:00
|
|
|
s->cx = 0; /* carriage return */
|
2016-05-30 09:32:24 +00:00
|
|
|
skip = 0;
|
2016-07-15 00:49:08 +00:00
|
|
|
wrapped = 1;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 10:36:53 +00:00
|
|
|
/* Sanity check cursor position. */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cx > sx - width || s->cy > sy - 1)
|
2009-06-01 22:58:49 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
/* Handle overwriting of UTF-8 characters. */
|
2016-07-15 00:49:08 +00:00
|
|
|
gl = &s->grid->linedata[s->grid->hsize + s->cy];
|
|
|
|
if (gl->flags & GRID_LINE_EXTENDED) {
|
|
|
|
grid_view_get_cell(gd, s->cx, s->cy, &now_gc);
|
|
|
|
if (screen_write_overwrite(ctx, &now_gc, width))
|
|
|
|
skip = 0;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the new character is UTF-8 wide, fill in padding cells. Have
|
|
|
|
* already ensured there is enough room.
|
|
|
|
*/
|
2016-05-30 09:32:24 +00:00
|
|
|
for (xx = s->cx + 1; xx < s->cx + width; xx++) {
|
2016-05-27 23:06:12 +00:00
|
|
|
grid_view_set_cell(gd, xx, s->cy, &screen_write_pad_cell);
|
2016-05-30 09:32:24 +00:00
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no change, do not draw. */
|
2016-07-15 00:49:08 +00:00
|
|
|
if (skip) {
|
|
|
|
if (s->cx >= gl->cellsize)
|
|
|
|
skip = grid_cells_equal(gc, &grid_default_cell);
|
|
|
|
else {
|
|
|
|
gce = &gl->celldata[s->cx];
|
|
|
|
if (gce->flags & GRID_FLAG_EXTENDED)
|
|
|
|
skip = 0;
|
2016-10-05 12:36:36 +00:00
|
|
|
else if (gc->flags != gce->flags)
|
2016-07-15 00:49:08 +00:00
|
|
|
skip = 0;
|
|
|
|
else if (gc->attr != gce->data.attr)
|
|
|
|
skip = 0;
|
|
|
|
else if (gc->fg != gce->data.fg)
|
|
|
|
skip = 0;
|
|
|
|
else if (gc->bg != gce->data.bg)
|
|
|
|
skip = 0;
|
2016-10-05 12:36:36 +00:00
|
|
|
else if (gc->data.width != 1)
|
|
|
|
skip = 0;
|
|
|
|
else if (gce->data.data != gc->data.data[0])
|
2016-07-15 00:49:08 +00:00
|
|
|
skip = 0;
|
|
|
|
}
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-06-06 07:28:52 +00:00
|
|
|
/* Update the selection the flag and set the cell. */
|
|
|
|
selected = screen_check_selection(s, s->cx, s->cy);
|
|
|
|
if (selected && ~gc->flags & GRID_FLAG_SELECTED) {
|
|
|
|
skip = 0;
|
|
|
|
memcpy(&tmp_gc, gc, sizeof tmp_gc);
|
|
|
|
tmp_gc.flags |= GRID_FLAG_SELECTED;
|
|
|
|
grid_view_set_cell(gd, s->cx, s->cy, &tmp_gc);
|
|
|
|
} else if (!selected && gc->flags & GRID_FLAG_SELECTED) {
|
|
|
|
skip = 0;
|
|
|
|
memcpy(&tmp_gc, gc, sizeof tmp_gc);
|
|
|
|
tmp_gc.flags &= ~GRID_FLAG_SELECTED;
|
|
|
|
grid_view_set_cell(gd, s->cx, s->cy, &tmp_gc);
|
|
|
|
} else if (!skip)
|
2016-05-30 09:32:24 +00:00
|
|
|
grid_view_set_cell(gd, s->cx, s->cy, gc);
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2013-03-22 10:36:53 +00:00
|
|
|
/*
|
|
|
|
* Move the cursor. If not wrapping, stick at the last character and
|
|
|
|
* replace it.
|
|
|
|
*/
|
2013-03-22 10:41:01 +00:00
|
|
|
last = !(s->mode & MODE_WRAP);
|
2016-07-15 00:49:08 +00:00
|
|
|
if (s->cx <= sx - last - width)
|
2013-03-22 10:36:53 +00:00
|
|
|
s->cx += width;
|
|
|
|
else
|
2016-07-15 00:49:08 +00:00
|
|
|
s->cx = sx - last;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-30 09:32:24 +00:00
|
|
|
/* Create space for character in insert mode. */
|
2009-07-22 20:53:38 +00:00
|
|
|
if (insert) {
|
2016-07-15 00:49:08 +00:00
|
|
|
if (!wrapped)
|
|
|
|
screen_write_flush(ctx);
|
2009-07-22 20:53:38 +00:00
|
|
|
ttyctx.num = width;
|
|
|
|
tty_write(tty_cmd_insertcharacter, &ttyctx);
|
|
|
|
}
|
2016-05-30 09:32:24 +00:00
|
|
|
|
|
|
|
/* Write to the screen. */
|
|
|
|
if (selected) {
|
2009-10-17 08:35:38 +00:00
|
|
|
memcpy(&tmp_gc, &s->sel.cell, sizeof tmp_gc);
|
2015-11-13 08:09:28 +00:00
|
|
|
utf8_copy(&tmp_gc.data, &gc->data);
|
2014-10-02 08:36:26 +00:00
|
|
|
tmp_gc.attr = tmp_gc.attr & ~GRID_ATTR_CHARSET;
|
|
|
|
tmp_gc.attr |= gc->attr & GRID_ATTR_CHARSET;
|
2016-01-31 14:11:49 +00:00
|
|
|
tmp_gc.flags = gc->flags;
|
2016-07-15 00:49:08 +00:00
|
|
|
screen_write_flush(ctx);
|
2009-10-17 08:35:38 +00:00
|
|
|
ttyctx.cell = &tmp_gc;
|
2009-07-22 18:02:23 +00:00
|
|
|
tty_write(tty_cmd_cell, &ttyctx);
|
2016-07-15 00:49:08 +00:00
|
|
|
ctx->written++;
|
2016-05-30 09:32:24 +00:00
|
|
|
} else if (!skip) {
|
2016-07-15 00:49:08 +00:00
|
|
|
if (wrapped) {
|
|
|
|
ttyctx.cell = gc;
|
|
|
|
tty_write(tty_cmd_cell, &ttyctx);
|
|
|
|
ctx->written++;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If wp is NULL, we are not updating the terminal and
|
|
|
|
* don't care about actually writing the cells
|
|
|
|
* (tty_write will just return). So don't even bother
|
|
|
|
* allocating the dirty array.
|
|
|
|
*/
|
|
|
|
if (ctx->wp != NULL && s->dirty == NULL) {
|
|
|
|
log_debug("%s: allocating %u bits", __func__,
|
|
|
|
s->dirtysize);
|
|
|
|
s->dirty = bit_alloc(s->dirtysize);
|
|
|
|
}
|
|
|
|
if (s->dirty != NULL) {
|
|
|
|
bit_set(s->dirty, screen_dirty_bit(s,
|
|
|
|
ttyctx.ocx, ttyctx.ocy));
|
|
|
|
ctx->dirty++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
ctx->skipped++;
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
|
|
|
|
2009-10-20 17:33:33 +00:00
|
|
|
/* Combine a UTF-8 zero-width character onto the previous. */
|
2016-05-27 23:02:17 +00:00
|
|
|
static int
|
2013-01-18 02:16:21 +00:00
|
|
|
screen_write_combine(struct screen_write_ctx *ctx, const struct utf8_data *ud)
|
2009-10-20 17:33:33 +00:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
2015-11-13 08:09:28 +00:00
|
|
|
struct grid_cell gc;
|
2009-10-20 17:33:33 +00:00
|
|
|
|
|
|
|
/* Can't combine if at 0. */
|
|
|
|
if (s->cx == 0)
|
|
|
|
return (-1);
|
|
|
|
|
2013-01-18 02:16:21 +00:00
|
|
|
/* Empty data is out. */
|
|
|
|
if (ud->size == 0)
|
2009-11-11 18:53:21 +00:00
|
|
|
fatalx("UTF-8 data empty");
|
|
|
|
|
2013-01-18 02:16:21 +00:00
|
|
|
/* Retrieve the previous cell. */
|
2015-11-13 08:09:28 +00:00
|
|
|
grid_view_get_cell(gd, s->cx - 1, s->cy, &gc);
|
2009-10-20 17:33:33 +00:00
|
|
|
|
2013-01-18 02:16:21 +00:00
|
|
|
/* Check there is enough space. */
|
2015-11-13 08:09:28 +00:00
|
|
|
if (gc.data.size + ud->size > sizeof gc.data.data)
|
2013-01-18 02:16:21 +00:00
|
|
|
return (-1);
|
2009-10-20 17:33:33 +00:00
|
|
|
|
2015-11-13 08:09:28 +00:00
|
|
|
/* Append the data. */
|
|
|
|
memcpy(gc.data.data + gc.data.size, ud->data, ud->size);
|
|
|
|
gc.data.size += ud->size;
|
|
|
|
|
|
|
|
/* Set the new cell. */
|
|
|
|
grid_view_set_cell(gd, s->cx - 1, s->cy, &gc);
|
2009-10-20 17:33:33 +00:00
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2009-06-01 22:58:49 +00: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.
|
|
|
|
*/
|
2016-05-30 09:32:24 +00:00
|
|
|
static int
|
|
|
|
screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc,
|
|
|
|
u_int width)
|
2009-06-01 22:58:49 +00:00
|
|
|
{
|
|
|
|
struct screen *s = ctx->s;
|
|
|
|
struct grid *gd = s->grid;
|
2016-05-30 09:32:24 +00:00
|
|
|
struct grid_cell tmp_gc;
|
2009-06-01 22:58:49 +00:00
|
|
|
u_int xx;
|
2016-05-30 09:32:24 +00:00
|
|
|
int done = 0;
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2016-05-30 09:32:24 +00:00
|
|
|
if (gc->flags & GRID_FLAG_PADDING) {
|
2009-06-01 22:58:49 +00: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.
|
|
|
|
*/
|
|
|
|
xx = s->cx + 1;
|
|
|
|
while (--xx > 0) {
|
2016-05-30 09:32:24 +00:00
|
|
|
grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
|
|
|
|
if (~tmp_gc.flags & GRID_FLAG_PADDING)
|
2009-06-01 22:58:49 +00:00
|
|
|
break;
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Overwrite the character at the start of this padding. */
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
2016-05-30 09:32:24 +00:00
|
|
|
done = 1;
|
2010-06-21 00:11:12 +00:00
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
|
2010-06-21 00:11:12 +00:00
|
|
|
/*
|
2016-10-05 12:36:36 +00:00
|
|
|
* Overwrite any padding cells that belong to any UTF-8 characters
|
|
|
|
* we'll be overwriting with the current character.
|
2010-06-21 00:11:12 +00:00
|
|
|
*/
|
2016-10-05 12:36:36 +00:00
|
|
|
if (width != 1 ||
|
|
|
|
gc->data.width != 1 ||
|
|
|
|
gc->flags & GRID_FLAG_PADDING) {
|
2016-05-30 09:32:24 +00:00
|
|
|
xx = s->cx + width - 1;
|
|
|
|
while (++xx < screen_size_x(s)) {
|
|
|
|
grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
|
|
|
|
if (~tmp_gc.flags & GRID_FLAG_PADDING)
|
|
|
|
break;
|
|
|
|
grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
|
|
|
|
done = 1;
|
|
|
|
}
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2016-05-30 09:32:24 +00:00
|
|
|
|
|
|
|
return (done);
|
2009-06-01 22:58:49 +00:00
|
|
|
}
|
2011-03-07 23:46:27 +00:00
|
|
|
|
2011-05-18 20:24:29 +00:00
|
|
|
void
|
|
|
|
screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len)
|
|
|
|
{
|
|
|
|
struct tty_ctx ttyctx;
|
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2011-05-18 20:24:29 +00:00
|
|
|
ttyctx.ptr = str;
|
|
|
|
ttyctx.num = len;
|
|
|
|
|
|
|
|
tty_write(tty_cmd_setselection, &ttyctx);
|
|
|
|
}
|
|
|
|
|
2011-03-07 23:46:27 +00:00
|
|
|
void
|
|
|
|
screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len)
|
|
|
|
{
|
2016-05-27 23:02:17 +00:00
|
|
|
struct tty_ctx ttyctx;
|
2011-03-07 23:46:27 +00:00
|
|
|
|
2016-05-27 23:02:17 +00:00
|
|
|
screen_write_initctx(ctx, &ttyctx);
|
2011-03-07 23:46:27 +00:00
|
|
|
ttyctx.ptr = str;
|
|
|
|
ttyctx.num = len;
|
|
|
|
|
|
|
|
tty_write(tty_cmd_rawstring, &ttyctx);
|
|
|
|
}
|