Make the grid_cell passed into screen_write_* const.

This commit is contained in:
nicm 2016-04-29 13:21:33 +00:00
parent 97417a1813
commit 5f2bfd9807
2 changed files with 55 additions and 55 deletions

View File

@ -64,11 +64,15 @@ screen_write_reset(struct screen_write_ctx *ctx)
/* Write character. */ /* Write character. */
void void
screen_write_putc(struct screen_write_ctx *ctx, struct grid_cell *gc, screen_write_putc(struct screen_write_ctx *ctx, const struct grid_cell *gcp,
u_char ch) u_char ch)
{ {
utf8_set(&gc->data, ch); struct grid_cell gc;
screen_write_cell(ctx, gc);
memcpy(&gc, gcp, sizeof gc);
utf8_set(&gc.data, ch);
screen_write_cell(ctx, &gc);
} }
/* Calculate string length, with embedded formatting. */ /* Calculate string length, with embedded formatting. */
@ -148,75 +152,74 @@ screen_write_strlen(const char *fmt, ...)
/* Write simple string (no UTF-8 or maximum length). */ /* Write simple string (no UTF-8 or maximum length). */
void void
screen_write_puts(struct screen_write_ctx *ctx, struct grid_cell *gc, screen_write_puts(struct screen_write_ctx *ctx, const struct grid_cell *gcp,
const char *fmt, ...) const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
screen_write_vnputs(ctx, -1, gc, fmt, ap); screen_write_vnputs(ctx, -1, gcp, fmt, ap);
va_end(ap); va_end(ap);
} }
/* Write string with length limit (-1 for unlimited). */ /* Write string with length limit (-1 for unlimited). */
void void
screen_write_nputs(struct screen_write_ctx *ctx, ssize_t maxlen, screen_write_nputs(struct screen_write_ctx *ctx, ssize_t maxlen,
struct grid_cell *gc, const char *fmt, ...) const struct grid_cell *gcp, const char *fmt, ...)
{ {
va_list ap; va_list ap;
va_start(ap, fmt); va_start(ap, fmt);
screen_write_vnputs(ctx, maxlen, gc, fmt, ap); screen_write_vnputs(ctx, maxlen, gcp, fmt, ap);
va_end(ap); va_end(ap);
} }
void void
screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen, screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
struct grid_cell *gc, const char *fmt, va_list ap) const struct grid_cell *gcp, const char *fmt, va_list ap)
{ {
struct grid_cell gc;
struct utf8_data *ud = &gc.data;
char *msg; char *msg;
struct utf8_data ud;
u_char *ptr; u_char *ptr;
size_t left, size = 0; size_t left, size = 0;
enum utf8_state more; enum utf8_state more;
memcpy(&gc, gcp, sizeof gc);
xvasprintf(&msg, fmt, ap); xvasprintf(&msg, fmt, ap);
ptr = msg; ptr = msg;
while (*ptr != '\0') { while (*ptr != '\0') {
if (*ptr > 0x7f && utf8_open(&ud, *ptr) == UTF8_MORE) { if (*ptr > 0x7f && utf8_open(ud, *ptr) == UTF8_MORE) {
ptr++; ptr++;
left = strlen(ptr); left = strlen(ptr);
if (left < (size_t)ud.size - 1) if (left < (size_t)ud->size - 1)
break; break;
while ((more = utf8_append(&ud, *ptr)) == UTF8_MORE) while ((more = utf8_append(ud, *ptr)) == UTF8_MORE)
ptr++; ptr++;
ptr++; ptr++;
if (more == UTF8_DONE) { if (more != UTF8_DONE)
if (maxlen > 0 && continue;
size + ud.width > (size_t) maxlen) { if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
while (size < (size_t) maxlen) { while (size < (size_t)maxlen) {
screen_write_putc(ctx, gc, ' '); screen_write_putc(ctx, &gc, ' ');
size++; size++;
}
break;
} }
size += ud.width; break;
utf8_copy(&gc->data, &ud);
screen_write_cell(ctx, gc);
} }
size += ud->width;
screen_write_cell(ctx, &gc);
} else { } else {
if (maxlen > 0 && size + 1 > (size_t) maxlen) if (maxlen > 0 && size + 1 > (size_t)maxlen)
break; break;
if (*ptr == '\001') if (*ptr == '\001')
gc->attr ^= GRID_ATTR_CHARSET; gc.attr ^= GRID_ATTR_CHARSET;
else if (*ptr > 0x1f && *ptr < 0x7f) { else if (*ptr > 0x1f && *ptr < 0x7f) {
size++; size++;
screen_write_putc(ctx, gc, *ptr); screen_write_putc(ctx, &gc, *ptr);
} }
ptr++; ptr++;
} }
@ -228,22 +231,22 @@ screen_write_vnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
/* Write string, similar to nputs, but with embedded formatting (#[]). */ /* Write string, similar to nputs, but with embedded formatting (#[]). */
void void
screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen, screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
struct grid_cell *gc, const char *fmt, ...) const struct grid_cell *gcp, const char *fmt, ...)
{ {
struct grid_cell lgc; struct grid_cell gc;
struct utf8_data ud; struct utf8_data *ud = &gc.data;
va_list ap; va_list ap;
char *msg; char *msg;
u_char *ptr, *last; u_char *ptr, *last;
size_t left, size = 0; size_t left, size = 0;
enum utf8_state more; enum utf8_state more;
memcpy(&gc, gcp, sizeof gc);
va_start(ap, fmt); va_start(ap, fmt);
xvasprintf(&msg, fmt, ap); xvasprintf(&msg, fmt, ap);
va_end(ap); va_end(ap);
memcpy(&lgc, gc, sizeof lgc);
ptr = msg; ptr = msg;
while (*ptr != '\0') { while (*ptr != '\0') {
if (ptr[0] == '#' && ptr[1] == '[') { if (ptr[0] == '#' && ptr[1] == '[') {
@ -255,42 +258,39 @@ screen_write_cnputs(struct screen_write_ctx *ctx, ssize_t maxlen,
} }
*last = '\0'; *last = '\0';
style_parse(gc, &lgc, ptr); style_parse(gcp, &gc, ptr);
ptr = last + 1; ptr = last + 1;
continue; continue;
} }
if (*ptr > 0x7f && utf8_open(&ud, *ptr) == UTF8_MORE) { if (*ptr > 0x7f && utf8_open(ud, *ptr) == UTF8_MORE) {
ptr++; ptr++;
left = strlen(ptr); left = strlen(ptr);
if (left < (size_t)ud.size - 1) if (left < (size_t)ud->size - 1)
break; break;
while ((more = utf8_append(&ud, *ptr)) == UTF8_MORE) while ((more = utf8_append(ud, *ptr)) == UTF8_MORE)
ptr++; ptr++;
ptr++; ptr++;
if (more == UTF8_DONE) { if (more != UTF8_DONE)
if (maxlen > 0 && continue;
size + ud.width > (size_t) maxlen) { if (maxlen > 0 && size + ud->width > (size_t)maxlen) {
while (size < (size_t) maxlen) { while (size < (size_t)maxlen) {
screen_write_putc(ctx, gc, ' '); screen_write_putc(ctx, &gc, ' ');
size++; size++;
}
break;
} }
size += ud.width; break;
utf8_copy(&lgc.data, &ud);
screen_write_cell(ctx, &lgc);
} }
size += ud->width;
screen_write_cell(ctx, &gc);
} else { } else {
if (maxlen > 0 && size + 1 > (size_t) maxlen) if (maxlen > 0 && size + 1 > (size_t)maxlen)
break; break;
if (*ptr > 0x1f && *ptr < 0x7f) { if (*ptr > 0x1f && *ptr < 0x7f) {
size++; size++;
screen_write_putc(ctx, &lgc, *ptr); screen_write_putc(ctx, &gc, *ptr);
} }
ptr++; ptr++;
} }

10
tmux.h
View File

@ -2034,15 +2034,15 @@ void screen_write_stop(struct screen_write_ctx *);
void screen_write_reset(struct screen_write_ctx *); void screen_write_reset(struct screen_write_ctx *);
size_t printflike(1, 2) screen_write_cstrlen(const char *, ...); size_t printflike(1, 2) screen_write_cstrlen(const char *, ...);
void printflike(4, 5) screen_write_cnputs(struct screen_write_ctx *, void printflike(4, 5) screen_write_cnputs(struct screen_write_ctx *,
ssize_t, struct grid_cell *, const char *, ...); ssize_t, const struct grid_cell *, const char *, ...);
size_t printflike(1, 2) screen_write_strlen(const char *, ...); size_t printflike(1, 2) screen_write_strlen(const char *, ...);
void printflike(3, 4) screen_write_puts(struct screen_write_ctx *, void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
struct grid_cell *, const char *, ...); const struct grid_cell *, const char *, ...);
void printflike(4, 5) screen_write_nputs(struct screen_write_ctx *, void printflike(4, 5) screen_write_nputs(struct screen_write_ctx *,
ssize_t, struct grid_cell *, const char *, ...); ssize_t, const struct grid_cell *, const char *, ...);
void screen_write_vnputs(struct screen_write_ctx *, ssize_t, void screen_write_vnputs(struct screen_write_ctx *, ssize_t,
struct grid_cell *, const char *, va_list); const struct grid_cell *, const char *, va_list);
void screen_write_putc(struct screen_write_ctx *, struct grid_cell *, void screen_write_putc(struct screen_write_ctx *, const struct grid_cell *,
u_char); u_char);
void screen_write_copy(struct screen_write_ctx *, struct screen *, u_int, void screen_write_copy(struct screen_write_ctx *, struct screen *, u_int,
u_int, u_int, u_int); u_int, u_int, u_int);