Annotation of src/usr.bin/tmux/screen-write.c, Revision 1.145
1.145 ! nicm 1: /* $OpenBSD: screen-write.c,v 1.144 2019/03/12 07:39:27 nicm Exp $ */
1.1 nicm 2:
3: /*
1.84 nicm 4: * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20:
1.56 nicm 21: #include <stdlib.h>
1.1 nicm 22: #include <string.h>
23:
24: #include "tmux.h"
25:
1.87 nicm 26: static void screen_write_initctx(struct screen_write_ctx *,
27: struct tty_ctx *);
1.109 nicm 28: static void screen_write_collect_clear(struct screen_write_ctx *, u_int,
29: u_int);
30: static void screen_write_collect_scroll(struct screen_write_ctx *);
1.111 nicm 31: static void screen_write_collect_flush(struct screen_write_ctx *, int);
1.87 nicm 32:
1.89 nicm 33: static int screen_write_overwrite(struct screen_write_ctx *,
34: struct grid_cell *, u_int);
1.104 nicm 35: static const struct grid_cell *screen_write_combine(struct screen_write_ctx *,
36: const struct utf8_data *, u_int *);
1.1 nicm 37:
1.88 nicm 38: static const struct grid_cell screen_write_pad_cell = {
1.91 nicm 39: GRID_FLAG_PADDING, 0, 8, 8, { { 0 }, 0, 0, 0 }
1.88 nicm 40: };
41:
1.109 nicm 42: struct screen_write_collect_item {
43: u_int x;
1.118 nicm 44: int wrapped;
1.109 nicm 45:
46: u_int used;
47: char data[256];
48:
49: struct grid_cell gc;
50:
1.126 nicm 51: TAILQ_ENTRY(screen_write_collect_item) entry;
1.109 nicm 52: };
53: struct screen_write_collect_line {
54: TAILQ_HEAD(, screen_write_collect_item) items;
55: };
1.92 nicm 56:
1.139 nicm 57: static void
58: screen_write_offset_timer(__unused int fd, __unused short events, void *data)
59: {
60: struct window *w = data;
61:
62: tty_update_window_offset(w);
63: }
64:
65: /* Set cursor position. */
66: static void
67: screen_write_set_cursor(struct screen_write_ctx *ctx, int cx, int cy)
68: {
69: struct window_pane *wp = ctx->wp;
70: struct window *w;
71: struct screen *s = ctx->s;
72: struct timeval tv = { .tv_usec = 10000 };
73:
74: if (cx != -1 && (u_int)cx == s->cx && cy != -1 && (u_int)cy == s->cy)
75: return;
76:
1.144 nicm 77: if (cx != -1) {
1.145 ! nicm 78: if ((u_int)cx > screen_size_x(s)) /* allow last column */
1.144 nicm 79: cx = screen_size_x(s) - 1;
1.139 nicm 80: s->cx = cx;
1.144 nicm 81: }
82: if (cy != -1) {
83: if ((u_int)cy > screen_size_y(s) - 1)
84: cy = screen_size_y(s) - 1;
1.139 nicm 85: s->cy = cy;
1.144 nicm 86: }
1.139 nicm 87:
88: if (wp == NULL)
89: return;
90: w = wp->window;
91:
92: if (!event_initialized(&w->offset_timer))
93: evtimer_set(&w->offset_timer, screen_write_offset_timer, w);
94: if (!evtimer_pending(&w->offset_timer, NULL))
95: evtimer_add(&w->offset_timer, &tv);
96: }
97:
1.92 nicm 98: /* Initialize writing with a window. */
1.1 nicm 99: void
1.71 nicm 100: screen_write_start(struct screen_write_ctx *ctx, struct window_pane *wp,
101: struct screen *s)
1.1 nicm 102: {
1.139 nicm 103: char tmp[32];
1.109 nicm 104: u_int y;
105:
106: memset(ctx, 0, sizeof *ctx);
1.92 nicm 107:
1.1 nicm 108: ctx->wp = wp;
109: if (wp != NULL && s == NULL)
110: ctx->s = wp->screen;
111: else
112: ctx->s = s;
1.92 nicm 113:
1.109 nicm 114: ctx->list = xcalloc(screen_size_y(ctx->s), sizeof *ctx->list);
115: for (y = 0; y < screen_size_y(ctx->s); y++)
116: TAILQ_INIT(&ctx->list[y].items);
117: ctx->item = xcalloc(1, sizeof *ctx->item);
1.92 nicm 118:
1.122 nicm 119: ctx->scrolled = 0;
120: ctx->bg = 8;
121:
1.139 nicm 122: if (wp != NULL) {
123: snprintf(tmp, sizeof tmp, "pane %%%u (at %u,%u)", wp->id,
124: wp->xoff, wp->yoff);
125: }
1.92 nicm 126: log_debug("%s: size %ux%u, %s", __func__, screen_size_x(ctx->s),
1.108 nicm 127: screen_size_y(ctx->s), wp == NULL ? "no pane" : tmp);
1.1 nicm 128: }
129:
130: /* Finish writing. */
131: void
1.92 nicm 132: screen_write_stop(struct screen_write_ctx *ctx)
133: {
1.109 nicm 134: screen_write_collect_end(ctx);
1.111 nicm 135: screen_write_collect_flush(ctx, 0);
1.92 nicm 136:
1.109 nicm 137: log_debug("%s: %u cells (%u written, %u skipped)", __func__,
138: ctx->cells, ctx->written, ctx->skipped);
1.92 nicm 139:
1.109 nicm 140: free(ctx->item);
141: free(ctx->list); /* flush will have emptied */
1.52 nicm 142: }
143:
144: /* Reset screen state. */
145: void
146: screen_write_reset(struct screen_write_ctx *ctx)
147: {
1.61 nicm 148: struct screen *s = ctx->s;
1.52 nicm 149:
1.61 nicm 150: screen_reset_tabs(s);
151: screen_write_scrollregion(ctx, 0, screen_size_y(s) - 1);
1.63 nicm 152:
1.141 nicm 153: s->mode = MODE_CURSOR | MODE_WRAP;
1.52 nicm 154:
1.99 nicm 155: screen_write_clearscreen(ctx, 8);
1.144 nicm 156: screen_write_set_cursor(ctx, 0, 0);
1.1 nicm 157: }
158:
159: /* Write character. */
160: void
1.86 nicm 161: screen_write_putc(struct screen_write_ctx *ctx, const struct grid_cell *gcp,
1.69 nicm 162: u_char ch)
1.1 nicm 163: {
1.86 nicm 164: struct grid_cell gc;
165:
166: memcpy(&gc, gcp, sizeof gc);
167:
168: utf8_set(&gc.data, ch);
169: screen_write_cell(ctx, &gc);
1.1 nicm 170: }
171:
1.24 nicm 172: /* Calculate string length, with embedded formatting. */
1.71 nicm 173: size_t
1.75 nicm 174: screen_write_cstrlen(const char *fmt, ...)
1.24 nicm 175: {
176: va_list ap;
177: char *msg, *msg2, *ptr, *ptr2;
178: size_t size;
179:
180: va_start(ap, fmt);
181: xvasprintf(&msg, fmt, ap);
182: va_end(ap);
183: msg2 = xmalloc(strlen(msg) + 1);
184:
185: ptr = msg;
186: ptr2 = msg2;
187: while (*ptr != '\0') {
188: if (ptr[0] == '#' && ptr[1] == '[') {
189: while (*ptr != ']' && *ptr != '\0')
190: ptr++;
191: if (*ptr == ']')
192: ptr++;
193: continue;
194: }
195: *ptr2++ = *ptr++;
196: }
197: *ptr2 = '\0';
198:
1.75 nicm 199: size = screen_write_strlen("%s", msg2);
1.24 nicm 200:
1.56 nicm 201: free(msg);
202: free(msg2);
1.24 nicm 203:
204: return (size);
205: }
206:
1.2 nicm 207: /* Calculate string length. */
1.71 nicm 208: size_t
1.75 nicm 209: screen_write_strlen(const char *fmt, ...)
1.2 nicm 210: {
1.36 nicm 211: va_list ap;
212: char *msg;
1.76 nicm 213: struct utf8_data ud;
1.36 nicm 214: u_char *ptr;
215: size_t left, size = 0;
1.79 nicm 216: enum utf8_state more;
1.2 nicm 217:
218: va_start(ap, fmt);
219: xvasprintf(&msg, fmt, ap);
220: va_end(ap);
221:
222: ptr = msg;
223: while (*ptr != '\0') {
1.79 nicm 224: if (*ptr > 0x7f && utf8_open(&ud, *ptr) == UTF8_MORE) {
1.36 nicm 225: ptr++;
1.2 nicm 226:
227: left = strlen(ptr);
1.77 nicm 228: if (left < (size_t)ud.size - 1)
1.36 nicm 229: break;
1.79 nicm 230: while ((more = utf8_append(&ud, *ptr)) == UTF8_MORE)
1.2 nicm 231: ptr++;
1.36 nicm 232: ptr++;
233:
1.79 nicm 234: if (more == UTF8_DONE)
1.78 nicm 235: size += ud.width;
1.2 nicm 236: } else {
1.75 nicm 237: if (*ptr > 0x1f && *ptr < 0x7f)
238: size++;
1.2 nicm 239: ptr++;
240: }
1.7 ray 241: }
1.2 nicm 242:
1.56 nicm 243: free(msg);
1.2 nicm 244: return (size);
245: }
246:
1.3 nicm 247: /* Write simple string (no UTF-8 or maximum length). */
1.71 nicm 248: void
1.86 nicm 249: screen_write_puts(struct screen_write_ctx *ctx, const struct grid_cell *gcp,
1.71 nicm 250: const char *fmt, ...)
1.1 nicm 251: {
252: va_list ap;
253:
254: va_start(ap, fmt);
1.86 nicm 255: screen_write_vnputs(ctx, -1, gcp, fmt, ap);
1.2 nicm 256: va_end(ap);
257: }
258:
259: /* Write string with length limit (-1 for unlimited). */
1.71 nicm 260: void
261: screen_write_nputs(struct screen_write_ctx *ctx, ssize_t maxlen,
1.86 nicm 262: const struct grid_cell *gcp, const char *fmt, ...)
1.2 nicm 263: {
264: va_list ap;
265:
266: va_start(ap, fmt);
1.86 nicm 267: screen_write_vnputs(ctx, maxlen, gcp, fmt, ap);
1.2 nicm 268: va_end(ap);
269: }
270:
271: void
1.3 nicm 272: screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
1.86 nicm 273: const struct grid_cell *gcp, const char *fmt, va_list ap)
1.2 nicm 274: {
1.86 nicm 275: struct grid_cell gc;
276: struct utf8_data *ud = &gc.data;
1.36 nicm 277: char *msg;
278: u_char *ptr;
279: size_t left, size = 0;
1.79 nicm 280: enum utf8_state more;
1.2 nicm 281:
1.86 nicm 282: memcpy(&gc, gcp, sizeof gc);
1.1 nicm 283: xvasprintf(&msg, fmt, ap);
284:
1.2 nicm 285: ptr = msg;
286: while (*ptr != '\0') {
1.86 nicm 287: if (*ptr > 0x7f && utf8_open(ud, *ptr) == UTF8_MORE) {
1.36 nicm 288: ptr++;
1.2 nicm 289:
290: left = strlen(ptr);
1.86 nicm 291: if (left < (size_t)ud->size - 1)
1.36 nicm 292: break;
1.86 nicm 293: while ((more = utf8_append(ud, *ptr)) == UTF8_MORE)
1.2 nicm 294: ptr++;
1.36 nicm 295: ptr++;
1.7 ray 296:
1.86 nicm 297: if (more != UTF8_DONE)
298: continue;
299: if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
300: while (size < (size_t)maxlen) {
301: screen_write_putc(ctx, &gc, ' ');
302: size++;
1.2 nicm 303: }
1.86 nicm 304: break;
1.2 nicm 305: }
1.86 nicm 306: size += ud->width;
307: screen_write_cell(ctx, &gc);
1.2 nicm 308: } else {
1.86 nicm 309: if (maxlen > 0 && size + 1 > (size_t)maxlen)
1.2 nicm 310: break;
311:
1.57 nicm 312: if (*ptr == '\001')
1.86 nicm 313: gc.attr ^= GRID_ATTR_CHARSET;
1.75 nicm 314: else if (*ptr > 0x1f && *ptr < 0x7f) {
1.57 nicm 315: size++;
1.86 nicm 316: screen_write_putc(ctx, &gc, *ptr);
1.57 nicm 317: }
1.2 nicm 318: ptr++;
319: }
320: }
1.1 nicm 321:
1.56 nicm 322: free(msg);
1.24 nicm 323: }
324:
325: /* Write string, similar to nputs, but with embedded formatting (#[]). */
1.71 nicm 326: void
1.75 nicm 327: screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
1.86 nicm 328: const struct grid_cell *gcp, const char *fmt, ...)
1.24 nicm 329: {
1.86 nicm 330: struct grid_cell gc;
331: struct utf8_data *ud = &gc.data;
1.24 nicm 332: va_list ap;
333: char *msg;
1.36 nicm 334: u_char *ptr, *last;
1.24 nicm 335: size_t left, size = 0;
1.79 nicm 336: enum utf8_state more;
1.24 nicm 337:
1.86 nicm 338: memcpy(&gc, gcp, sizeof gc);
339:
1.24 nicm 340: va_start(ap, fmt);
341: xvasprintf(&msg, fmt, ap);
342: va_end(ap);
343:
344: ptr = msg;
345: while (*ptr != '\0') {
346: if (ptr[0] == '#' && ptr[1] == '[') {
347: ptr += 2;
348: last = ptr + strcspn(ptr, "]");
349: if (*last == '\0') {
350: /* No ]. Not much point in doing anything. */
351: break;
352: }
353: *last = '\0';
354:
1.86 nicm 355: style_parse(gcp, &gc, ptr);
1.24 nicm 356: ptr = last + 1;
357: continue;
358: }
1.86 nicm 359: if (*ptr > 0x7f && utf8_open(ud, *ptr) == UTF8_MORE) {
1.36 nicm 360: ptr++;
1.24 nicm 361:
362: left = strlen(ptr);
1.86 nicm 363: if (left < (size_t)ud->size - 1)
1.36 nicm 364: break;
1.86 nicm 365: while ((more = utf8_append(ud, *ptr)) == UTF8_MORE)
1.24 nicm 366: ptr++;
1.36 nicm 367: ptr++;
1.24 nicm 368:
1.86 nicm 369: if (more != UTF8_DONE)
370: continue;
371: if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
372: while (size < (size_t)maxlen) {
373: screen_write_putc(ctx, &gc, ' ');
374: size++;
1.24 nicm 375: }
1.86 nicm 376: break;
1.24 nicm 377: }
1.86 nicm 378: size += ud->width;
379: screen_write_cell(ctx, &gc);
1.24 nicm 380: } else {
1.86 nicm 381: if (maxlen > 0 && size + 1 > (size_t)maxlen)
1.24 nicm 382: break;
383:
1.142 nicm 384: if (*ptr == '\001')
385: gc.attr ^= GRID_ATTR_CHARSET;
386: else if (*ptr > 0x1f && *ptr < 0x7f) {
1.75 nicm 387: size++;
1.86 nicm 388: screen_write_putc(ctx, &gc, *ptr);
1.75 nicm 389: }
1.24 nicm 390: ptr++;
391: }
392: }
393:
1.56 nicm 394: free(msg);
1.1 nicm 395: }
396:
1.132 nicm 397: /* Copy from another screen. Assumes target region is big enough. */
1.1 nicm 398: void
1.95 nicm 399: screen_write_copy(struct screen_write_ctx *ctx, struct screen *src, u_int px,
1.132 nicm 400: u_int py, u_int nx, u_int ny, bitstr_t *mbs, const struct grid_cell *mgc)
1.1 nicm 401: {
402: struct screen *s = ctx->s;
403: struct grid *gd = src->grid;
1.77 nicm 404: struct grid_cell gc;
1.102 nicm 405: u_int xx, yy, cx, cy, b;
1.1 nicm 406:
1.125 nicm 407: if (nx == 0 || ny == 0)
408: return;
409:
1.1 nicm 410: cx = s->cx;
411: cy = s->cy;
1.96 nicm 412:
1.1 nicm 413: for (yy = py; yy < py + ny; yy++) {
1.96 nicm 414: for (xx = px; xx < px + nx; xx++) {
415: grid_get_cell(gd, xx, yy, &gc);
1.132 nicm 416: if (mbs != NULL) {
1.102 nicm 417: b = (yy * screen_size_x(src)) + xx;
1.132 nicm 418: if (bit_test(mbs, b)) {
419: gc.attr = mgc->attr;
420: gc.fg = mgc->fg;
421: gc.bg = mgc->bg;
1.102 nicm 422: }
423: }
1.135 nicm 424: if (xx + gc.data.width <= px + nx)
425: screen_write_cell(ctx, &gc);
1.96 nicm 426: }
1.132 nicm 427: cy++;
1.144 nicm 428: screen_write_set_cursor(ctx, cx, cy);
1.132 nicm 429: }
430: }
431:
432: /*
433: * Copy from another screen but without the selection stuff. Also assumes the
434: * target region is already big enough and already cleared.
435: */
436: void
437: screen_write_fast_copy(struct screen_write_ctx *ctx, struct screen *src,
438: u_int px, u_int py, u_int nx, u_int ny)
439: {
440: struct screen *s = ctx->s;
441: struct grid *gd = src->grid;
442: struct grid_cell gc;
443: u_int xx, yy, cx, cy;
1.96 nicm 444:
1.132 nicm 445: if (nx == 0 || ny == 0)
446: return;
447:
448: cy = s->cy;
449: for (yy = py; yy < py + ny; yy++) {
1.134 nicm 450: if (yy >= gd->hsize + gd->sy)
451: break;
1.132 nicm 452: cx = s->cx;
453: for (xx = px; xx < px + nx; xx++) {
1.137 nicm 454: if (xx >= grid_get_line(gd, yy)->cellsize)
1.132 nicm 455: break;
456: grid_get_cell(gd, xx, yy, &gc);
1.135 nicm 457: if (xx + gc.data.width > px + nx)
458: break;
1.132 nicm 459: if (!grid_cells_equal(&gc, &grid_default_cell))
460: grid_view_set_cell(ctx->s->grid, cx, cy, &gc);
461: cx++;
462: }
1.1 nicm 463: cy++;
1.125 nicm 464: }
465: }
466:
1.129 nicm 467: /* Draw a horizontal line on screen. */
1.125 nicm 468: void
1.129 nicm 469: screen_write_hline(struct screen_write_ctx *ctx, u_int nx, int left, int right)
1.125 nicm 470: {
471: struct screen *s = ctx->s;
472: struct grid_cell gc;
473: u_int cx, cy, i;
474:
475: cx = s->cx;
476: cy = s->cy;
477:
478: memcpy(&gc, &grid_default_cell, sizeof gc);
479: gc.attr |= GRID_ATTR_CHARSET;
480:
481: screen_write_putc(ctx, &gc, left ? 't' : 'q');
482: for (i = 1; i < nx - 1; i++)
483: screen_write_putc(ctx, &gc, 'q');
484: screen_write_putc(ctx, &gc, right ? 'u' : 'q');
1.129 nicm 485:
1.144 nicm 486: screen_write_set_cursor(ctx, cx, cy);
1.129 nicm 487: }
488:
489: /* Draw a horizontal line on screen. */
490: void
1.130 nicm 491: screen_write_vline(struct screen_write_ctx *ctx, u_int ny, int top, int bottom)
1.129 nicm 492: {
493: struct screen *s = ctx->s;
494: struct grid_cell gc;
495: u_int cx, cy, i;
496:
497: cx = s->cx;
498: cy = s->cy;
499:
500: memcpy(&gc, &grid_default_cell, sizeof gc);
501: gc.attr |= GRID_ATTR_CHARSET;
502:
503: screen_write_putc(ctx, &gc, top ? 'w' : 'x');
504: for (i = 1; i < ny - 1; i++) {
1.144 nicm 505: screen_write_set_cursor(ctx, cx, cy + i);
1.129 nicm 506: screen_write_putc(ctx, &gc, 'x');
507: }
1.144 nicm 508: screen_write_set_cursor(ctx, cx, cy + ny - 1);
1.129 nicm 509: screen_write_putc(ctx, &gc, bottom ? 'v' : 'x');
1.125 nicm 510:
1.144 nicm 511: screen_write_set_cursor(ctx, cx, cy);
1.125 nicm 512: }
513:
514: /* Draw a box on screen. */
515: void
516: screen_write_box(struct screen_write_ctx *ctx, u_int nx, u_int ny)
517: {
518: struct screen *s = ctx->s;
519: struct grid_cell gc;
520: u_int cx, cy, i;
521:
522: cx = s->cx;
523: cy = s->cy;
524:
525: memcpy(&gc, &grid_default_cell, sizeof gc);
526: gc.attr |= GRID_ATTR_CHARSET;
527:
528: screen_write_putc(ctx, &gc, 'l');
529: for (i = 1; i < nx - 1; i++)
530: screen_write_putc(ctx, &gc, 'q');
531: screen_write_putc(ctx, &gc, 'k');
532:
1.144 nicm 533: screen_write_set_cursor(ctx, cx, cy + ny - 1);
1.125 nicm 534: screen_write_putc(ctx, &gc, 'm');
535: for (i = 1; i < nx - 1; i++)
536: screen_write_putc(ctx, &gc, 'q');
537: screen_write_putc(ctx, &gc, 'j');
538:
539: for (i = 1; i < ny - 1; i++) {
1.144 nicm 540: screen_write_set_cursor(ctx, cx, cy + i);
1.125 nicm 541: screen_write_putc(ctx, &gc, 'x');
542: }
543: for (i = 1; i < ny - 1; i++) {
1.144 nicm 544: screen_write_set_cursor(ctx, cx + nx - 1, cy + i);
1.125 nicm 545: screen_write_putc(ctx, &gc, 'x');
546: }
547:
1.144 nicm 548: screen_write_set_cursor(ctx, cx, cy);
1.125 nicm 549: }
550:
1.132 nicm 551: /*
552: * Write a preview version of a window. Assumes target area is big enough and
553: * already cleared.
554: */
1.125 nicm 555: void
556: screen_write_preview(struct screen_write_ctx *ctx, struct screen *src, u_int nx,
557: u_int ny)
558: {
559: struct screen *s = ctx->s;
560: struct grid_cell gc;
561: u_int cx, cy, px, py;
562:
563: cx = s->cx;
564: cy = s->cy;
565:
566: /*
567: * If the cursor is on, pick the area around the cursor, otherwise use
568: * the top left.
569: */
570: if (src->mode & MODE_CURSOR) {
571: px = src->cx;
572: if (px < nx / 3)
573: px = 0;
574: else
575: px = px - nx / 3;
576: if (px + nx > screen_size_x(src)) {
577: if (nx > screen_size_x(src))
578: px = 0;
579: else
580: px = screen_size_x(src) - nx;
581: }
582: py = src->cy;
583: if (py < ny / 3)
584: py = 0;
585: else
586: py = py - ny / 3;
587: if (py + ny > screen_size_y(src)) {
588: if (ny > screen_size_y(src))
589: py = 0;
590: else
591: py = screen_size_y(src) - ny;
592: }
593: } else {
594: px = 0;
595: py = 0;
596: }
597:
1.132 nicm 598: screen_write_fast_copy(ctx, src, px, src->grid->hsize + py, nx, ny);
1.125 nicm 599:
600: if (src->mode & MODE_CURSOR) {
601: grid_view_get_cell(src->grid, src->cx, src->cy, &gc);
602: gc.attr |= GRID_ATTR_REVERSE;
1.144 nicm 603: screen_write_set_cursor(ctx, cx + (src->cx - px),
1.125 nicm 604: cy + (src->cy - py));
605: screen_write_cell(ctx, &gc);
1.1 nicm 606: }
607: }
608:
1.17 nicm 609: /* Set up context for TTY command. */
1.87 nicm 610: static void
611: screen_write_initctx(struct screen_write_ctx *ctx, struct tty_ctx *ttyctx)
1.1 nicm 612: {
1.87 nicm 613: struct screen *s = ctx->s;
1.123 nicm 614:
615: memset(ttyctx, 0, sizeof *ttyctx);
1.1 nicm 616:
1.17 nicm 617: ttyctx->wp = ctx->wp;
1.1 nicm 618:
1.17 nicm 619: ttyctx->ocx = s->cx;
620: ttyctx->ocy = s->cy;
621:
622: ttyctx->orlower = s->rlower;
623: ttyctx->orupper = s->rupper;
1.87 nicm 624: }
1.31 nicm 625:
1.61 nicm 626: /* Set a mode. */
627: void
628: screen_write_mode_set(struct screen_write_ctx *ctx, int mode)
629: {
630: struct screen *s = ctx->s;
631:
632: s->mode |= mode;
633: }
634:
635: /* Clear a mode. */
636: void
637: screen_write_mode_clear(struct screen_write_ctx *ctx, int mode)
638: {
639: struct screen *s = ctx->s;
640:
641: s->mode &= ~mode;
642: }
643:
1.1 nicm 644: /* Cursor up by ny. */
645: void
646: screen_write_cursorup(struct screen_write_ctx *ctx, u_int ny)
647: {
648: struct screen *s = ctx->s;
1.139 nicm 649: u_int cx = s->cx, cy = s->cy;
1.1 nicm 650:
651: if (ny == 0)
652: ny = 1;
653:
1.139 nicm 654: if (cy < s->rupper) {
1.12 nicm 655: /* Above region. */
1.139 nicm 656: if (ny > cy)
657: ny = cy;
1.12 nicm 658: } else {
659: /* Below region. */
1.139 nicm 660: if (ny > cy - s->rupper)
661: ny = cy - s->rupper;
1.12 nicm 662: }
1.139 nicm 663: if (cx == screen_size_x(s))
664: cx--;
665:
666: cy -= ny;
1.1 nicm 667:
1.139 nicm 668: screen_write_set_cursor(ctx, cx, cy);
1.1 nicm 669: }
670:
671: /* Cursor down by ny. */
672: void
673: screen_write_cursordown(struct screen_write_ctx *ctx, u_int ny)
674: {
675: struct screen *s = ctx->s;
1.139 nicm 676: u_int cx = s->cx, cy = s->cy;
1.1 nicm 677:
678: if (ny == 0)
679: ny = 1;
680:
1.139 nicm 681: if (cy > s->rlower) {
1.12 nicm 682: /* Below region. */
1.139 nicm 683: if (ny > screen_size_y(s) - 1 - cy)
684: ny = screen_size_y(s) - 1 - cy;
1.12 nicm 685: } else {
686: /* Above region. */
1.139 nicm 687: if (ny > s->rlower - cy)
688: ny = s->rlower - cy;
1.12 nicm 689: }
1.139 nicm 690: if (cx == screen_size_x(s))
691: cx--;
692: else if (ny == 0)
1.1 nicm 693: return;
694:
1.139 nicm 695: cy += ny;
696:
697: screen_write_set_cursor(ctx, cx, cy);
1.1 nicm 698: }
699:
1.101 nicm 700: /* Cursor right by nx. */
1.1 nicm 701: void
702: screen_write_cursorright(struct screen_write_ctx *ctx, u_int nx)
703: {
704: struct screen *s = ctx->s;
1.139 nicm 705: u_int cx = s->cx, cy = s->cy;
1.1 nicm 706:
707: if (nx == 0)
708: nx = 1;
709:
1.139 nicm 710: if (nx > screen_size_x(s) - 1 - cx)
711: nx = screen_size_x(s) - 1 - cx;
1.1 nicm 712: if (nx == 0)
713: return;
714:
1.139 nicm 715: cx += nx;
716:
717: screen_write_set_cursor(ctx, cx, cy);
1.1 nicm 718: }
719:
720: /* Cursor left by nx. */
721: void
722: screen_write_cursorleft(struct screen_write_ctx *ctx, u_int nx)
723: {
724: struct screen *s = ctx->s;
1.139 nicm 725: u_int cx = s->cx, cy = s->cy;
1.1 nicm 726:
727: if (nx == 0)
728: nx = 1;
729:
1.139 nicm 730: if (nx > cx)
731: nx = cx;
1.1 nicm 732: if (nx == 0)
733: return;
734:
1.139 nicm 735: cx -= nx;
736:
737: screen_write_set_cursor(ctx, cx, cy);
1.5 nicm 738: }
739:
1.29 nicm 740: /* Backspace; cursor left unless at start of wrapped line when can move up. */
741: void
742: screen_write_backspace(struct screen_write_ctx *ctx)
743: {
744: struct screen *s = ctx->s;
745: struct grid_line *gl;
1.139 nicm 746: u_int cx = s->cx, cy = s->cy;
1.29 nicm 747:
1.139 nicm 748: if (cx == 0) {
749: if (cy == 0)
1.29 nicm 750: return;
1.139 nicm 751: gl = grid_get_line(s->grid, s->grid->hsize + cy - 1);
1.29 nicm 752: if (gl->flags & GRID_LINE_WRAPPED) {
1.139 nicm 753: cy--;
754: cx = screen_size_x(s) - 1;
1.29 nicm 755: }
756: } else
1.139 nicm 757: cx--;
758:
759: screen_write_set_cursor(ctx, cx, cy);
1.29 nicm 760: }
761:
1.5 nicm 762: /* VT100 alignment test. */
763: void
764: screen_write_alignmenttest(struct screen_write_ctx *ctx)
765: {
766: struct screen *s = ctx->s;
1.17 nicm 767: struct tty_ctx ttyctx;
1.5 nicm 768: struct grid_cell gc;
769: u_int xx, yy;
770:
771: memcpy(&gc, &grid_default_cell, sizeof gc);
1.77 nicm 772: utf8_set(&gc.data, 'E');
1.7 ray 773:
1.5 nicm 774: for (yy = 0; yy < screen_size_y(s); yy++) {
775: for (xx = 0; xx < screen_size_x(s); xx++)
776: grid_view_set_cell(s->grid, xx, yy, &gc);
777: }
1.7 ray 778:
1.139 nicm 779: screen_write_set_cursor(ctx, 0, 0);
1.5 nicm 780:
781: s->rupper = 0;
782: s->rlower = screen_size_y(s) - 1;
1.143 nicm 783:
784: screen_write_initctx(ctx, &ttyctx);
1.5 nicm 785:
1.109 nicm 786: screen_write_collect_clear(ctx, 0, screen_size_y(s) - 1);
1.17 nicm 787: tty_write(tty_cmd_alignmenttest, &ttyctx);
1.1 nicm 788: }
789:
790: /* Insert nx characters. */
791: void
1.99 nicm 792: screen_write_insertcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
1.1 nicm 793: {
794: struct screen *s = ctx->s;
1.17 nicm 795: struct tty_ctx ttyctx;
1.1 nicm 796:
797: if (nx == 0)
798: nx = 1;
799:
1.9 nicm 800: if (nx > screen_size_x(s) - s->cx)
801: nx = screen_size_x(s) - s->cx;
1.1 nicm 802: if (nx == 0)
803: return;
804:
1.107 nicm 805: if (s->cx > screen_size_x(s) - 1)
806: return;
807:
1.87 nicm 808: screen_write_initctx(ctx, &ttyctx);
1.107 nicm 809: ttyctx.bg = bg;
1.1 nicm 810:
1.107 nicm 811: grid_view_insert_cells(s->grid, s->cx, s->cy, nx, bg);
1.1 nicm 812:
1.111 nicm 813: screen_write_collect_flush(ctx, 0);
1.17 nicm 814: ttyctx.num = nx;
815: tty_write(tty_cmd_insertcharacter, &ttyctx);
1.1 nicm 816: }
817:
818: /* Delete nx characters. */
819: void
1.99 nicm 820: screen_write_deletecharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
1.1 nicm 821: {
822: struct screen *s = ctx->s;
1.17 nicm 823: struct tty_ctx ttyctx;
1.1 nicm 824:
825: if (nx == 0)
826: nx = 1;
827:
1.9 nicm 828: if (nx > screen_size_x(s) - s->cx)
829: nx = screen_size_x(s) - s->cx;
1.1 nicm 830: if (nx == 0)
831: return;
832:
1.107 nicm 833: if (s->cx > screen_size_x(s) - 1)
834: return;
835:
1.87 nicm 836: screen_write_initctx(ctx, &ttyctx);
1.107 nicm 837: ttyctx.bg = bg;
1.1 nicm 838:
1.107 nicm 839: grid_view_delete_cells(s->grid, s->cx, s->cy, nx, bg);
1.1 nicm 840:
1.111 nicm 841: screen_write_collect_flush(ctx, 0);
1.17 nicm 842: ttyctx.num = nx;
843: tty_write(tty_cmd_deletecharacter, &ttyctx);
1.59 nicm 844: }
845:
846: /* Clear nx characters. */
847: void
1.121 nicm 848: screen_write_clearcharacter(struct screen_write_ctx *ctx, u_int nx, u_int bg)
1.59 nicm 849: {
850: struct screen *s = ctx->s;
851: struct tty_ctx ttyctx;
852:
853: if (nx == 0)
854: nx = 1;
855:
856: if (nx > screen_size_x(s) - s->cx)
857: nx = screen_size_x(s) - s->cx;
858: if (nx == 0)
859: return;
860:
1.107 nicm 861: if (s->cx > screen_size_x(s) - 1)
862: return;
863:
1.87 nicm 864: screen_write_initctx(ctx, &ttyctx);
1.121 nicm 865: ttyctx.bg = bg;
1.59 nicm 866:
1.124 nicm 867: grid_view_clear(s->grid, s->cx, s->cy, nx, 1, bg);
1.59 nicm 868:
1.111 nicm 869: screen_write_collect_flush(ctx, 0);
1.59 nicm 870: ttyctx.num = nx;
871: tty_write(tty_cmd_clearcharacter, &ttyctx);
1.1 nicm 872: }
873:
874: /* Insert ny lines. */
875: void
1.99 nicm 876: screen_write_insertline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
1.1 nicm 877: {
878: struct screen *s = ctx->s;
1.107 nicm 879: struct grid *gd = s->grid;
1.17 nicm 880: struct tty_ctx ttyctx;
1.1 nicm 881:
882: if (ny == 0)
883: ny = 1;
884:
1.11 nicm 885: if (s->cy < s->rupper || s->cy > s->rlower) {
886: if (ny > screen_size_y(s) - s->cy)
887: ny = screen_size_y(s) - s->cy;
888: if (ny == 0)
889: return;
890:
1.87 nicm 891: screen_write_initctx(ctx, &ttyctx);
1.107 nicm 892: ttyctx.bg = bg;
1.11 nicm 893:
1.107 nicm 894: grid_view_insert_lines(gd, s->cy, ny, bg);
1.11 nicm 895:
1.111 nicm 896: screen_write_collect_flush(ctx, 0);
1.17 nicm 897: ttyctx.num = ny;
898: tty_write(tty_cmd_insertline, &ttyctx);
1.11 nicm 899: return;
900: }
901:
902: if (ny > s->rlower + 1 - s->cy)
903: ny = s->rlower + 1 - s->cy;
1.1 nicm 904: if (ny == 0)
905: return;
1.41 nicm 906:
1.87 nicm 907: screen_write_initctx(ctx, &ttyctx);
1.107 nicm 908: ttyctx.bg = bg;
1.1 nicm 909:
910: if (s->cy < s->rupper || s->cy > s->rlower)
1.107 nicm 911: grid_view_insert_lines(gd, s->cy, ny, bg);
912: else
913: grid_view_insert_lines_region(gd, s->rlower, s->cy, ny, bg);
1.1 nicm 914:
1.111 nicm 915: screen_write_collect_flush(ctx, 0);
1.17 nicm 916: ttyctx.num = ny;
917: tty_write(tty_cmd_insertline, &ttyctx);
1.1 nicm 918: }
919:
920: /* Delete ny lines. */
921: void
1.99 nicm 922: screen_write_deleteline(struct screen_write_ctx *ctx, u_int ny, u_int bg)
1.1 nicm 923: {
924: struct screen *s = ctx->s;
1.107 nicm 925: struct grid *gd = s->grid;
1.17 nicm 926: struct tty_ctx ttyctx;
1.1 nicm 927:
928: if (ny == 0)
929: ny = 1;
930:
1.11 nicm 931: if (s->cy < s->rupper || s->cy > s->rlower) {
932: if (ny > screen_size_y(s) - s->cy)
933: ny = screen_size_y(s) - s->cy;
934: if (ny == 0)
935: return;
936:
1.87 nicm 937: screen_write_initctx(ctx, &ttyctx);
1.107 nicm 938: ttyctx.bg = bg;
1.11 nicm 939:
1.107 nicm 940: grid_view_delete_lines(gd, s->cy, ny, bg);
1.11 nicm 941:
1.111 nicm 942: screen_write_collect_flush(ctx, 0);
1.17 nicm 943: ttyctx.num = ny;
944: tty_write(tty_cmd_deleteline, &ttyctx);
1.11 nicm 945: return;
946: }
1.41 nicm 947:
1.11 nicm 948: if (ny > s->rlower + 1 - s->cy)
949: ny = s->rlower + 1 - s->cy;
1.1 nicm 950: if (ny == 0)
951: return;
952:
1.87 nicm 953: screen_write_initctx(ctx, &ttyctx);
1.107 nicm 954: ttyctx.bg = bg;
1.1 nicm 955:
956: if (s->cy < s->rupper || s->cy > s->rlower)
1.107 nicm 957: grid_view_delete_lines(gd, s->cy, ny, bg);
958: else
959: grid_view_delete_lines_region(gd, s->rlower, s->cy, ny, bg);
1.1 nicm 960:
1.111 nicm 961: screen_write_collect_flush(ctx, 0);
1.17 nicm 962: ttyctx.num = ny;
963: tty_write(tty_cmd_deleteline, &ttyctx);
1.1 nicm 964: }
965:
966: /* Clear line at cursor. */
967: void
1.99 nicm 968: screen_write_clearline(struct screen_write_ctx *ctx, u_int bg)
1.1 nicm 969: {
1.92 nicm 970: struct screen *s = ctx->s;
971: struct grid_line *gl;
972: struct tty_ctx ttyctx;
973: u_int sx = screen_size_x(s);
1.1 nicm 974:
1.137 nicm 975: gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
1.140 nicm 976: if (gl->cellsize == 0 && COLOUR_DEFAULT(bg))
1.92 nicm 977: return;
1.1 nicm 978:
1.108 nicm 979: screen_write_initctx(ctx, &ttyctx);
980: ttyctx.bg = bg;
981:
1.99 nicm 982: grid_view_clear(s->grid, 0, s->cy, sx, 1, bg);
983:
1.109 nicm 984: screen_write_collect_clear(ctx, s->cy, 1);
1.114 nicm 985: screen_write_collect_flush(ctx, 0);
1.17 nicm 986: tty_write(tty_cmd_clearline, &ttyctx);
1.1 nicm 987: }
988:
989: /* Clear to end of line from cursor. */
990: void
1.99 nicm 991: screen_write_clearendofline(struct screen_write_ctx *ctx, u_int bg)
1.1 nicm 992: {
1.92 nicm 993: struct screen *s = ctx->s;
994: struct grid_line *gl;
995: struct tty_ctx ttyctx;
996: u_int sx = screen_size_x(s);
1.1 nicm 997:
1.137 nicm 998: gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
1.140 nicm 999: if (s->cx > sx - 1 || (s->cx >= gl->cellsize && COLOUR_DEFAULT(bg)))
1.92 nicm 1000: return;
1.108 nicm 1001:
1002: screen_write_initctx(ctx, &ttyctx);
1003: ttyctx.bg = bg;
1.1 nicm 1004:
1.99 nicm 1005: grid_view_clear(s->grid, s->cx, s->cy, sx - s->cx, 1, bg);
1006:
1.109 nicm 1007: if (s->cx == 0)
1008: screen_write_collect_clear(ctx, s->cy, 1);
1.114 nicm 1009: screen_write_collect_flush(ctx, 0);
1.41 nicm 1010: tty_write(tty_cmd_clearendofline, &ttyctx);
1.1 nicm 1011: }
1012:
1013: /* Clear to start of line from cursor. */
1014: void
1.99 nicm 1015: screen_write_clearstartofline(struct screen_write_ctx *ctx, u_int bg)
1.1 nicm 1016: {
1017: struct screen *s = ctx->s;
1.17 nicm 1018: struct tty_ctx ttyctx;
1.92 nicm 1019: u_int sx = screen_size_x(s);
1.1 nicm 1020:
1.87 nicm 1021: screen_write_initctx(ctx, &ttyctx);
1.99 nicm 1022: ttyctx.bg = bg;
1.1 nicm 1023:
1.109 nicm 1024: if (s->cx > sx - 1)
1.99 nicm 1025: grid_view_clear(s->grid, 0, s->cy, sx, 1, bg);
1.109 nicm 1026: else
1.99 nicm 1027: grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1, bg);
1.1 nicm 1028:
1.109 nicm 1029: if (s->cx > sx - 1)
1030: screen_write_collect_clear(ctx, s->cy, 1);
1.114 nicm 1031: screen_write_collect_flush(ctx, 0);
1.17 nicm 1032: tty_write(tty_cmd_clearstartofline, &ttyctx);
1.1 nicm 1033: }
1034:
1.101 nicm 1035: /* Move cursor to px,py. */
1.1 nicm 1036: void
1037: screen_write_cursormove(struct screen_write_ctx *ctx, u_int px, u_int py)
1038: {
1039: struct screen *s = ctx->s;
1040:
1.144 nicm 1041: if (s->mode & MODE_ORIGIN) {
1042: if (py > s->rlower - s->rupper)
1043: py = s->rlower;
1044: else
1045: py += s->rupper;
1046: }
1.145 ! nicm 1047:
! 1048: if (px > screen_size_x(s) - 1)
! 1049: px = screen_size_x(s) - 1;
! 1050: if (py > screen_size_y(s) - 1)
! 1051: py = screen_size_y(s) - 1;
1.1 nicm 1052:
1.139 nicm 1053: screen_write_set_cursor(ctx, px, py);
1.1 nicm 1054: }
1055:
1.101 nicm 1056: /* Reverse index (up with scroll). */
1.1 nicm 1057: void
1.122 nicm 1058: screen_write_reverseindex(struct screen_write_ctx *ctx, u_int bg)
1.1 nicm 1059: {
1060: struct screen *s = ctx->s;
1.17 nicm 1061: struct tty_ctx ttyctx;
1.1 nicm 1062:
1.87 nicm 1063: screen_write_initctx(ctx, &ttyctx);
1.122 nicm 1064: ttyctx.bg = bg;
1.1 nicm 1065:
1.109 nicm 1066: if (s->cy == s->rupper)
1.122 nicm 1067: grid_view_scroll_region_down(s->grid, s->rupper, s->rlower, bg);
1.109 nicm 1068: else if (s->cy > 0)
1.139 nicm 1069: screen_write_set_cursor(ctx, -1, s->cy - 1);
1.1 nicm 1070:
1.111 nicm 1071: screen_write_collect_flush(ctx, 0);
1.17 nicm 1072: tty_write(tty_cmd_reverseindex, &ttyctx);
1.1 nicm 1073: }
1074:
1075: /* Set scroll region. */
1076: void
1.83 nicm 1077: screen_write_scrollregion(struct screen_write_ctx *ctx, u_int rupper,
1078: u_int rlower)
1.1 nicm 1079: {
1080: struct screen *s = ctx->s;
1081:
1082: if (rupper > screen_size_y(s) - 1)
1083: rupper = screen_size_y(s) - 1;
1084: if (rlower > screen_size_y(s) - 1)
1085: rlower = screen_size_y(s) - 1;
1.13 nicm 1086: if (rupper >= rlower) /* cannot be one line */
1.1 nicm 1087: return;
1088:
1.111 nicm 1089: screen_write_collect_flush(ctx, 0);
1.110 nicm 1090:
1.1 nicm 1091: /* Cursor moves to top-left. */
1.139 nicm 1092: screen_write_set_cursor(ctx, 0, 0);
1.1 nicm 1093:
1094: s->rupper = rupper;
1095: s->rlower = rlower;
1096: }
1097:
1.34 nicm 1098: /* Line feed. */
1.1 nicm 1099: void
1.122 nicm 1100: screen_write_linefeed(struct screen_write_ctx *ctx, int wrapped, u_int bg)
1.1 nicm 1101: {
1.20 nicm 1102: struct screen *s = ctx->s;
1.109 nicm 1103: struct grid *gd = s->grid;
1.20 nicm 1104: struct grid_line *gl;
1.1 nicm 1105:
1.137 nicm 1106: gl = grid_get_line(gd, gd->hsize + s->cy);
1.20 nicm 1107: if (wrapped)
1108: gl->flags |= GRID_LINE_WRAPPED;
1.73 nicm 1109: else
1110: gl->flags &= ~GRID_LINE_WRAPPED;
1.20 nicm 1111:
1.114 nicm 1112: log_debug("%s: at %u,%u (region %u-%u)", __func__, s->cx, s->cy,
1113: s->rupper, s->rlower);
1114:
1.122 nicm 1115: if (bg != ctx->bg) {
1116: screen_write_collect_flush(ctx, 1);
1117: ctx->bg = bg;
1118: }
1119:
1.92 nicm 1120: if (s->cy == s->rlower) {
1.122 nicm 1121: grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg);
1.109 nicm 1122: screen_write_collect_scroll(ctx);
1.110 nicm 1123: ctx->scrolled++;
1.109 nicm 1124: } else if (s->cy < screen_size_y(s) - 1)
1.139 nicm 1125: screen_write_set_cursor(ctx, -1, s->cy + 1);
1.1 nicm 1126: }
1127:
1.110 nicm 1128: /* Scroll up. */
1129: void
1.122 nicm 1130: screen_write_scrollup(struct screen_write_ctx *ctx, u_int lines, u_int bg)
1.110 nicm 1131: {
1132: struct screen *s = ctx->s;
1133: struct grid *gd = s->grid;
1134: u_int i;
1135:
1136: if (lines == 0)
1137: lines = 1;
1138: else if (lines > s->rlower - s->rupper + 1)
1139: lines = s->rlower - s->rupper + 1;
1140:
1.122 nicm 1141: if (bg != ctx->bg) {
1142: screen_write_collect_flush(ctx, 1);
1143: ctx->bg = bg;
1144: }
1145:
1.110 nicm 1146: for (i = 0; i < lines; i++) {
1.122 nicm 1147: grid_view_scroll_region_up(gd, s->rupper, s->rlower, bg);
1.110 nicm 1148: screen_write_collect_scroll(ctx);
1149: }
1150: ctx->scrolled += lines;
1151: }
1152:
1.1 nicm 1153: /* Carriage return (cursor to start of line). */
1154: void
1155: screen_write_carriagereturn(struct screen_write_ctx *ctx)
1156: {
1.139 nicm 1157: screen_write_set_cursor(ctx, 0, -1);
1.1 nicm 1158: }
1159:
1160: /* Clear to end of screen from cursor. */
1161: void
1.99 nicm 1162: screen_write_clearendofscreen(struct screen_write_ctx *ctx, u_int bg)
1.1 nicm 1163: {
1164: struct screen *s = ctx->s;
1.107 nicm 1165: struct grid *gd = s->grid;
1.17 nicm 1166: struct tty_ctx ttyctx;
1.92 nicm 1167: u_int sx = screen_size_x(s), sy = screen_size_y(s);
1.1 nicm 1168:
1.87 nicm 1169: screen_write_initctx(ctx, &ttyctx);
1.99 nicm 1170: ttyctx.bg = bg;
1.1 nicm 1171:
1.46 nicm 1172: /* Scroll into history if it is enabled and clearing entire screen. */
1.109 nicm 1173: if (s->cx == 0 && s->cy == 0 && (gd->flags & GRID_HISTORY))
1.107 nicm 1174: grid_view_clear_history(gd, bg);
1.109 nicm 1175: else {
1176: if (s->cx <= sx - 1)
1.107 nicm 1177: grid_view_clear(gd, s->cx, s->cy, sx - s->cx, 1, bg);
1178: grid_view_clear(gd, 0, s->cy + 1, sx, sy - (s->cy + 1), bg);
1.46 nicm 1179: }
1.1 nicm 1180:
1.109 nicm 1181: screen_write_collect_clear(ctx, s->cy + 1, sy - (s->cy + 1));
1.111 nicm 1182: screen_write_collect_flush(ctx, 0);
1.17 nicm 1183: tty_write(tty_cmd_clearendofscreen, &ttyctx);
1.1 nicm 1184: }
1185:
1186: /* Clear to start of screen. */
1187: void
1.105 nicm 1188: screen_write_clearstartofscreen(struct screen_write_ctx *ctx, u_int bg)
1.1 nicm 1189: {
1190: struct screen *s = ctx->s;
1.17 nicm 1191: struct tty_ctx ttyctx;
1.92 nicm 1192: u_int sx = screen_size_x(s);
1.1 nicm 1193:
1.87 nicm 1194: screen_write_initctx(ctx, &ttyctx);
1.105 nicm 1195: ttyctx.bg = bg;
1.1 nicm 1196:
1.109 nicm 1197: if (s->cy > 0)
1.105 nicm 1198: grid_view_clear(s->grid, 0, 0, sx, s->cy, bg);
1.109 nicm 1199: if (s->cx > sx - 1)
1.120 nicm 1200: grid_view_clear(s->grid, 0, s->cy, sx, 1, bg);
1.109 nicm 1201: else
1.120 nicm 1202: grid_view_clear(s->grid, 0, s->cy, s->cx + 1, 1, bg);
1.1 nicm 1203:
1.109 nicm 1204: screen_write_collect_clear(ctx, 0, s->cy);
1.111 nicm 1205: screen_write_collect_flush(ctx, 0);
1.17 nicm 1206: tty_write(tty_cmd_clearstartofscreen, &ttyctx);
1.1 nicm 1207: }
1208:
1209: /* Clear entire screen. */
1210: void
1.99 nicm 1211: screen_write_clearscreen(struct screen_write_ctx *ctx, u_int bg)
1.1 nicm 1212: {
1213: struct screen *s = ctx->s;
1.17 nicm 1214: struct tty_ctx ttyctx;
1.92 nicm 1215: u_int sx = screen_size_x(s), sy = screen_size_y(s);
1.1 nicm 1216:
1.87 nicm 1217: screen_write_initctx(ctx, &ttyctx);
1.99 nicm 1218: ttyctx.bg = bg;
1.1 nicm 1219:
1.46 nicm 1220: /* Scroll into history if it is enabled. */
1221: if (s->grid->flags & GRID_HISTORY)
1.99 nicm 1222: grid_view_clear_history(s->grid, bg);
1.83 nicm 1223: else
1.99 nicm 1224: grid_view_clear(s->grid, 0, 0, sx, sy, bg);
1.1 nicm 1225:
1.109 nicm 1226: screen_write_collect_clear(ctx, 0, sy);
1.17 nicm 1227: tty_write(tty_cmd_clearscreen, &ttyctx);
1.51 nicm 1228: }
1229:
1230: /* Clear entire history. */
1231: void
1232: screen_write_clearhistory(struct screen_write_ctx *ctx)
1233: {
1234: struct screen *s = ctx->s;
1235: struct grid *gd = s->grid;
1236:
1.99 nicm 1237: grid_move_lines(gd, 0, gd->hsize, gd->sy, 8);
1.93 nicm 1238: gd->hscrolled = gd->hsize = 0;
1.1 nicm 1239: }
1240:
1.109 nicm 1241: /* Clear a collected line. */
1242: static void
1243: screen_write_collect_clear(struct screen_write_ctx *ctx, u_int y, u_int n)
1244: {
1245: struct screen_write_collect_item *ci, *tmp;
1246: u_int i;
1247: size_t size;
1248:
1249: for (i = y ; i < y + n; i++) {
1250: if (TAILQ_EMPTY(&ctx->list[i].items))
1251: continue;
1252: size = 0;
1253: TAILQ_FOREACH_SAFE(ci, &ctx->list[i].items, entry, tmp) {
1254: size += ci->used;
1255: TAILQ_REMOVE(&ctx->list[i].items, ci, entry);
1256: free(ci);
1257: }
1258: ctx->skipped += size;
1.114 nicm 1259: log_debug("%s: dropped %zu bytes (line %u)", __func__, size, i);
1.109 nicm 1260: }
1261: }
1262:
1263: /* Scroll collected lines up. */
1264: static void
1265: screen_write_collect_scroll(struct screen_write_ctx *ctx)
1266: {
1267: struct screen *s = ctx->s;
1268: struct screen_write_collect_line *cl;
1269: u_int y;
1270:
1.114 nicm 1271: log_debug("%s: at %u,%u (region %u-%u)", __func__, s->cx, s->cy,
1272: s->rupper, s->rlower);
1273:
1.109 nicm 1274: screen_write_collect_clear(ctx, s->rupper, 1);
1275: for (y = s->rupper; y < s->rlower; y++) {
1276: cl = &ctx->list[y + 1];
1277: TAILQ_CONCAT(&ctx->list[y].items, &cl->items, entry);
1278: TAILQ_INIT(&cl->items);
1279: }
1280: }
1281:
1282: /* Flush collected lines. */
1283: static void
1.111 nicm 1284: screen_write_collect_flush(struct screen_write_ctx *ctx, int scroll_only)
1.109 nicm 1285: {
1286: struct screen *s = ctx->s;
1287: struct screen_write_collect_item *ci, *tmp;
1.116 nicm 1288: u_int y, cx, cy, items = 0;
1.109 nicm 1289: struct tty_ctx ttyctx;
1.116 nicm 1290: size_t written = 0;
1.110 nicm 1291:
1292: if (ctx->scrolled != 0) {
1293: log_debug("%s: scrolled %u (region %u-%u)", __func__,
1294: ctx->scrolled, s->rupper, s->rlower);
1295: if (ctx->scrolled > s->rlower - s->rupper + 1)
1296: ctx->scrolled = s->rlower - s->rupper + 1;
1297:
1298: screen_write_initctx(ctx, &ttyctx);
1299: ttyctx.num = ctx->scrolled;
1.122 nicm 1300: ttyctx.bg = ctx->bg;
1.110 nicm 1301: tty_write(tty_cmd_scrollup, &ttyctx);
1302: }
1303: ctx->scrolled = 0;
1.122 nicm 1304: ctx->bg = 8;
1305:
1.111 nicm 1306: if (scroll_only)
1307: return;
1.109 nicm 1308:
1309: cx = s->cx; cy = s->cy;
1310: for (y = 0; y < screen_size_y(s); y++) {
1311: TAILQ_FOREACH_SAFE(ci, &ctx->list[y].items, entry, tmp) {
1.144 nicm 1312: screen_write_set_cursor(ctx, ci->x, y);
1.109 nicm 1313: screen_write_initctx(ctx, &ttyctx);
1314: ttyctx.cell = &ci->gc;
1.118 nicm 1315: ttyctx.wrapped = ci->wrapped;
1.109 nicm 1316: ttyctx.ptr = ci->data;
1317: ttyctx.num = ci->used;
1318: tty_write(tty_cmd_cells, &ttyctx);
1.116 nicm 1319:
1320: items++;
1321: written += ci->used;
1.109 nicm 1322:
1323: TAILQ_REMOVE(&ctx->list[y].items, ci, entry);
1324: free(ci);
1325: }
1326: }
1327: s->cx = cx; s->cy = cy;
1.116 nicm 1328:
1329: log_debug("%s: flushed %u items (%zu bytes)", __func__, items, written);
1330: ctx->written += written;
1.109 nicm 1331: }
1332:
1333: /* Finish and store collected cells. */
1334: void
1335: screen_write_collect_end(struct screen_write_ctx *ctx)
1336: {
1337: struct screen *s = ctx->s;
1338: struct screen_write_collect_item *ci = ctx->item;
1339: struct grid_cell gc;
1.131 nicm 1340: u_int xx;
1.109 nicm 1341:
1342: if (ci->used == 0)
1343: return;
1344: ci->data[ci->used] = '\0';
1345:
1346: ci->x = s->cx;
1347: TAILQ_INSERT_TAIL(&ctx->list[s->cy].items, ci, entry);
1348: ctx->item = xcalloc(1, sizeof *ctx->item);
1349:
1350: log_debug("%s: %u %s (at %u,%u)", __func__, ci->used, ci->data, s->cx,
1351: s->cy);
1352:
1.131 nicm 1353: if (s->cx != 0) {
1354: for (xx = s->cx; xx > 0; xx--) {
1355: grid_view_get_cell(s->grid, xx, s->cy, &gc);
1356: if (~gc.flags & GRID_FLAG_PADDING)
1357: break;
1.136 nicm 1358: grid_view_set_cell(s->grid, xx, s->cy,
1359: &grid_default_cell);
1.131 nicm 1360: }
1.139 nicm 1361: if (gc.data.width > 1) {
1.136 nicm 1362: grid_view_set_cell(s->grid, xx, s->cy,
1363: &grid_default_cell);
1.139 nicm 1364: }
1.131 nicm 1365: }
1366:
1.109 nicm 1367: memcpy(&gc, &ci->gc, sizeof gc);
1368: grid_view_set_cells(s->grid, s->cx, s->cy, &gc, ci->data, ci->used);
1.139 nicm 1369: screen_write_set_cursor(ctx, s->cx + ci->used, -1);
1.131 nicm 1370:
1371: for (xx = s->cx; xx < screen_size_x(s); xx++) {
1372: grid_view_get_cell(s->grid, xx, s->cy, &gc);
1373: if (~gc.flags & GRID_FLAG_PADDING)
1374: break;
1375: grid_view_set_cell(s->grid, xx, s->cy, &grid_default_cell);
1376: }
1.109 nicm 1377: }
1378:
1379: /* Write cell data, collecting if necessary. */
1380: void
1381: screen_write_collect_add(struct screen_write_ctx *ctx,
1382: const struct grid_cell *gc)
1383: {
1384: struct screen *s = ctx->s;
1385: struct screen_write_collect_item *ci;
1386: u_int sx = screen_size_x(s);
1387: int collect;
1388:
1389: /*
1390: * Don't need to check that the attributes and whatnot are still the
1.116 nicm 1391: * same - input_parse will end the collection when anything that isn't
1392: * a plain character is encountered. Also nothing should make it here
1393: * that isn't a single ASCII character.
1.109 nicm 1394: */
1395:
1396: collect = 1;
1.136 nicm 1397: if (gc->data.width != 1 || gc->data.size != 1 || *gc->data.data >= 0x7f)
1.109 nicm 1398: collect = 0;
1399: else if (gc->attr & GRID_ATTR_CHARSET)
1400: collect = 0;
1401: else if (~s->mode & MODE_WRAP)
1402: collect = 0;
1403: else if (s->mode & MODE_INSERT)
1404: collect = 0;
1.138 nicm 1405: else if (s->sel != NULL)
1.109 nicm 1406: collect = 0;
1407: if (!collect) {
1408: screen_write_collect_end(ctx);
1.116 nicm 1409: screen_write_collect_flush(ctx, 0);
1.109 nicm 1410: screen_write_cell(ctx, gc);
1411: return;
1412: }
1413: ctx->cells++;
1414:
1415: if (s->cx > sx - 1 || ctx->item->used > sx - 1 - s->cx)
1416: screen_write_collect_end(ctx);
1.118 nicm 1417: ci = ctx->item; /* may have changed */
1418:
1.109 nicm 1419: if (s->cx > sx - 1) {
1.114 nicm 1420: log_debug("%s: wrapped at %u,%u", __func__, s->cx, s->cy);
1.118 nicm 1421: ci->wrapped = 1;
1.122 nicm 1422: screen_write_linefeed(ctx, 1, 8);
1.139 nicm 1423: screen_write_set_cursor(ctx, 0, -1);
1.109 nicm 1424: }
1425:
1426: if (ci->used == 0)
1427: memcpy(&ci->gc, gc, sizeof ci->gc);
1428: ci->data[ci->used++] = gc->data.data[0];
1429: if (ci->used == (sizeof ci->data) - 1)
1430: screen_write_collect_end(ctx);
1431: }
1432:
1.1 nicm 1433: /* Write cell data. */
1434: void
1.60 nicm 1435: screen_write_cell(struct screen_write_ctx *ctx, const struct grid_cell *gc)
1.1 nicm 1436: {
1437: struct screen *s = ctx->s;
1438: struct grid *gd = s->grid;
1.109 nicm 1439: struct grid_line *gl;
1440: struct grid_cell_entry *gce;
1441: struct grid_cell tmp_gc, now_gc;
1.15 nicm 1442: struct tty_ctx ttyctx;
1.92 nicm 1443: u_int sx = screen_size_x(s), sy = screen_size_y(s);
1.115 nicm 1444: u_int width = gc->data.width, xx, last, cx, cy;
1.109 nicm 1445: int selected, skip = 1;
1.1 nicm 1446:
1.109 nicm 1447: /* Ignore padding cells. */
1.1 nicm 1448: if (gc->flags & GRID_FLAG_PADDING)
1449: return;
1.109 nicm 1450: ctx->cells++;
1.32 nicm 1451:
1.109 nicm 1452: /* If the width is zero, combine onto the previous character. */
1.1 nicm 1453: if (width == 0) {
1.112 nicm 1454: screen_write_collect_flush(ctx, 0);
1.104 nicm 1455: if ((gc = screen_write_combine(ctx, &gc->data, &xx)) != 0) {
1.115 nicm 1456: cx = s->cx; cy = s->cy;
1.144 nicm 1457: screen_write_set_cursor(ctx, xx, s->cy);
1.87 nicm 1458: screen_write_initctx(ctx, &ttyctx);
1.104 nicm 1459: ttyctx.cell = gc;
1460: tty_write(tty_cmd_cell, &ttyctx);
1.115 nicm 1461: s->cx = cx; s->cy = cy;
1.1 nicm 1462: }
1463: return;
1464: }
1.112 nicm 1465:
1466: /* Flush any existing scrolling. */
1467: screen_write_collect_flush(ctx, 1);
1.1 nicm 1468:
1.109 nicm 1469: /* If this character doesn't fit, ignore it. */
1470: if ((~s->mode & MODE_WRAP) &&
1471: width > 1 &&
1472: (width > sx || (s->cx != sx && s->cx > sx - width)))
1473: return;
1474:
1.6 nicm 1475: /* If in insert mode, make space for the cells. */
1.98 nicm 1476: if (s->mode & MODE_INSERT) {
1.109 nicm 1477: grid_view_insert_cells(s->grid, s->cx, s->cy, width, 8);
1478: skip = 0;
1479: }
1.6 nicm 1480:
1.20 nicm 1481: /* Check this will fit on the current line and wrap if not. */
1.92 nicm 1482: if ((s->mode & MODE_WRAP) && s->cx > sx - width) {
1.128 nicm 1483: log_debug("%s: wrapped at %u,%u", __func__, s->cx, s->cy);
1.122 nicm 1484: screen_write_linefeed(ctx, 1, 8);
1.139 nicm 1485: screen_write_set_cursor(ctx, 0, -1);
1.128 nicm 1486: screen_write_collect_flush(ctx, 1);
1.1 nicm 1487: }
1488:
1.64 nicm 1489: /* Sanity check cursor position. */
1.92 nicm 1490: if (s->cx > sx - width || s->cy > sy - 1)
1.1 nicm 1491: return;
1.106 nicm 1492: screen_write_initctx(ctx, &ttyctx);
1493:
1.1 nicm 1494: /* Handle overwriting of UTF-8 characters. */
1.137 nicm 1495: gl = grid_get_line(s->grid, s->grid->hsize + s->cy);
1.92 nicm 1496: if (gl->flags & GRID_LINE_EXTENDED) {
1497: grid_view_get_cell(gd, s->cx, s->cy, &now_gc);
1498: if (screen_write_overwrite(ctx, &now_gc, width))
1499: skip = 0;
1500: }
1.1 nicm 1501:
1502: /*
1503: * If the new character is UTF-8 wide, fill in padding cells. Have
1504: * already ensured there is enough room.
1505: */
1.89 nicm 1506: for (xx = s->cx + 1; xx < s->cx + width; xx++) {
1.131 nicm 1507: log_debug("%s: new padding at %u,%u", __func__, xx, s->cy);
1.88 nicm 1508: grid_view_set_cell(gd, xx, s->cy, &screen_write_pad_cell);
1.89 nicm 1509: skip = 0;
1510: }
1511:
1512: /* If no change, do not draw. */
1.92 nicm 1513: if (skip) {
1514: if (s->cx >= gl->cellsize)
1515: skip = grid_cells_equal(gc, &grid_default_cell);
1516: else {
1517: gce = &gl->celldata[s->cx];
1518: if (gce->flags & GRID_FLAG_EXTENDED)
1519: skip = 0;
1.95 nicm 1520: else if (gc->flags != gce->flags)
1.92 nicm 1521: skip = 0;
1522: else if (gc->attr != gce->data.attr)
1523: skip = 0;
1524: else if (gc->fg != gce->data.fg)
1525: skip = 0;
1526: else if (gc->bg != gce->data.bg)
1527: skip = 0;
1.95 nicm 1528: else if (gc->data.width != 1)
1529: skip = 0;
1.109 nicm 1530: else if (gc->data.size != 1)
1531: skip = 0;
1.95 nicm 1532: else if (gce->data.data != gc->data.data[0])
1.92 nicm 1533: skip = 0;
1534: }
1535: }
1.1 nicm 1536:
1.127 nicm 1537: /* Update the selected flag and set the cell. */
1.90 nicm 1538: selected = screen_check_selection(s, s->cx, s->cy);
1.109 nicm 1539: if (selected && (~gc->flags & GRID_FLAG_SELECTED)) {
1.90 nicm 1540: memcpy(&tmp_gc, gc, sizeof tmp_gc);
1541: tmp_gc.flags |= GRID_FLAG_SELECTED;
1542: grid_view_set_cell(gd, s->cx, s->cy, &tmp_gc);
1.109 nicm 1543: } else if (!selected && (gc->flags & GRID_FLAG_SELECTED)) {
1.90 nicm 1544: memcpy(&tmp_gc, gc, sizeof tmp_gc);
1545: tmp_gc.flags &= ~GRID_FLAG_SELECTED;
1546: grid_view_set_cell(gd, s->cx, s->cy, &tmp_gc);
1547: } else if (!skip)
1.89 nicm 1548: grid_view_set_cell(gd, s->cx, s->cy, gc);
1.109 nicm 1549: if (selected)
1550: skip = 0;
1.1 nicm 1551:
1.64 nicm 1552: /*
1553: * Move the cursor. If not wrapping, stick at the last character and
1554: * replace it.
1555: */
1.65 nicm 1556: last = !(s->mode & MODE_WRAP);
1.92 nicm 1557: if (s->cx <= sx - last - width)
1.139 nicm 1558: screen_write_set_cursor(ctx, s->cx + width, -1);
1.64 nicm 1559: else
1.139 nicm 1560: screen_write_set_cursor(ctx, sx - last, -1);
1.1 nicm 1561:
1.89 nicm 1562: /* Create space for character in insert mode. */
1.109 nicm 1563: if (s->mode & MODE_INSERT) {
1.113 nicm 1564: screen_write_collect_flush(ctx, 0);
1.17 nicm 1565: ttyctx.num = width;
1566: tty_write(tty_cmd_insertcharacter, &ttyctx);
1567: }
1.89 nicm 1568:
1569: /* Write to the screen. */
1.109 nicm 1570: if (!skip) {
1571: if (selected) {
1572: screen_select_cell(s, &tmp_gc, gc);
1573: ttyctx.cell = &tmp_gc;
1574: } else
1575: ttyctx.cell = gc;
1.16 nicm 1576: tty_write(tty_cmd_cell, &ttyctx);
1.92 nicm 1577: ctx->written++;
1578: } else
1579: ctx->skipped++;
1.35 nicm 1580: }
1581:
1582: /* Combine a UTF-8 zero-width character onto the previous. */
1.104 nicm 1583: static const struct grid_cell *
1584: screen_write_combine(struct screen_write_ctx *ctx, const struct utf8_data *ud,
1585: u_int *xx)
1.35 nicm 1586: {
1587: struct screen *s = ctx->s;
1588: struct grid *gd = s->grid;
1.104 nicm 1589: static struct grid_cell gc;
1590: u_int n;
1.35 nicm 1591:
1592: /* Can't combine if at 0. */
1593: if (s->cx == 0)
1.104 nicm 1594: return (NULL);
1.35 nicm 1595:
1.60 nicm 1596: /* Empty data is out. */
1597: if (ud->size == 0)
1.37 nicm 1598: fatalx("UTF-8 data empty");
1599:
1.60 nicm 1600: /* Retrieve the previous cell. */
1.119 nicm 1601: for (n = 1; n <= s->cx; n++) {
1.104 nicm 1602: grid_view_get_cell(gd, s->cx - n, s->cy, &gc);
1603: if (~gc.flags & GRID_FLAG_PADDING)
1604: break;
1605: }
1.119 nicm 1606: if (n > s->cx)
1.104 nicm 1607: return (NULL);
1608: *xx = s->cx - n;
1.35 nicm 1609:
1.60 nicm 1610: /* Check there is enough space. */
1.77 nicm 1611: if (gc.data.size + ud->size > sizeof gc.data.data)
1.104 nicm 1612: return (NULL);
1613:
1614: log_debug("%s: %.*s onto %.*s at %u,%u", __func__, (int)ud->size,
1615: ud->data, (int)gc.data.size, gc.data.data, *xx, s->cy);
1.35 nicm 1616:
1.77 nicm 1617: /* Append the data. */
1618: memcpy(gc.data.data + gc.data.size, ud->data, ud->size);
1619: gc.data.size += ud->size;
1620:
1621: /* Set the new cell. */
1.104 nicm 1622: grid_view_set_cell(gd, *xx, s->cy, &gc);
1.35 nicm 1623:
1.104 nicm 1624: return (&gc);
1.1 nicm 1625: }
1626:
1627: /*
1628: * UTF-8 wide characters are a bit of an annoyance. They take up more than one
1629: * cell on the screen, so following cells must not be drawn by marking them as
1630: * padding.
1631: *
1632: * So far, so good. The problem is, when overwriting a padding cell, or a UTF-8
1633: * character, it is necessary to also overwrite any other cells which covered
1634: * by the same character.
1635: */
1.89 nicm 1636: static int
1637: screen_write_overwrite(struct screen_write_ctx *ctx, struct grid_cell *gc,
1638: u_int width)
1.1 nicm 1639: {
1640: struct screen *s = ctx->s;
1641: struct grid *gd = s->grid;
1.89 nicm 1642: struct grid_cell tmp_gc;
1.1 nicm 1643: u_int xx;
1.89 nicm 1644: int done = 0;
1.1 nicm 1645:
1.89 nicm 1646: if (gc->flags & GRID_FLAG_PADDING) {
1.1 nicm 1647: /*
1648: * A padding cell, so clear any following and leading padding
1649: * cells back to the character. Don't overwrite the current
1650: * cell as that happens later anyway.
1651: */
1652: xx = s->cx + 1;
1653: while (--xx > 0) {
1.89 nicm 1654: grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
1655: if (~tmp_gc.flags & GRID_FLAG_PADDING)
1.1 nicm 1656: break;
1.131 nicm 1657: log_debug("%s: padding at %u,%u", __func__, xx, s->cy);
1.1 nicm 1658: grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
1659: }
1660:
1661: /* Overwrite the character at the start of this padding. */
1.131 nicm 1662: log_debug("%s: character at %u,%u", __func__, xx, s->cy);
1.1 nicm 1663: grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
1.89 nicm 1664: done = 1;
1.43 nicm 1665: }
1.1 nicm 1666:
1.43 nicm 1667: /*
1.95 nicm 1668: * Overwrite any padding cells that belong to any UTF-8 characters
1669: * we'll be overwriting with the current character.
1.43 nicm 1670: */
1.95 nicm 1671: if (width != 1 ||
1672: gc->data.width != 1 ||
1673: gc->flags & GRID_FLAG_PADDING) {
1.89 nicm 1674: xx = s->cx + width - 1;
1675: while (++xx < screen_size_x(s)) {
1676: grid_view_get_cell(gd, xx, s->cy, &tmp_gc);
1677: if (~tmp_gc.flags & GRID_FLAG_PADDING)
1678: break;
1.131 nicm 1679: log_debug("%s: overwrite at %u,%u", __func__, xx, s->cy);
1.89 nicm 1680: grid_view_set_cell(gd, xx, s->cy, &grid_default_cell);
1681: done = 1;
1682: }
1.1 nicm 1683: }
1.89 nicm 1684:
1685: return (done);
1.50 nicm 1686: }
1687:
1.107 nicm 1688: /* Set external clipboard. */
1.50 nicm 1689: void
1690: screen_write_setselection(struct screen_write_ctx *ctx, u_char *str, u_int len)
1691: {
1692: struct tty_ctx ttyctx;
1693:
1.87 nicm 1694: screen_write_initctx(ctx, &ttyctx);
1.50 nicm 1695: ttyctx.ptr = str;
1696: ttyctx.num = len;
1697:
1698: tty_write(tty_cmd_setselection, &ttyctx);
1.47 nicm 1699: }
1700:
1.107 nicm 1701: /* Write unmodified string. */
1.47 nicm 1702: void
1703: screen_write_rawstring(struct screen_write_ctx *ctx, u_char *str, u_int len)
1704: {
1.87 nicm 1705: struct tty_ctx ttyctx;
1.47 nicm 1706:
1.87 nicm 1707: screen_write_initctx(ctx, &ttyctx);
1.47 nicm 1708: ttyctx.ptr = str;
1709: ttyctx.num = len;
1710:
1711: tty_write(tty_cmd_rawstring, &ttyctx);
1.1 nicm 1712: }