diff options
-rw-r--r-- | screen-write.c | 38 | ||||
-rw-r--r-- | tmux.h | 4 | ||||
-rw-r--r-- | window-customize.c | 101 |
3 files changed, 74 insertions, 69 deletions
diff --git a/screen-write.c b/screen-write.c index b168d0b6..9571cbec 100644 --- a/screen-write.c +++ b/screen-write.c @@ -361,15 +361,14 @@ screen_write_strlen(const char *fmt, ...) } /* Write string wrapped over lines. */ -void -screen_write_text(struct screen_write_ctx *ctx, u_int width, u_int lines, - const struct grid_cell *gcp, const char *fmt, ...) +int +screen_write_text(struct screen_write_ctx *ctx, u_int cx, u_int width, + u_int lines, int more, const struct grid_cell *gcp, const char *fmt, ...) { struct screen *s = ctx->s; - u_int cx = s->cx, cy = s->cy; va_list ap; char *tmp; - u_int i, end, next, idx = 0, at; + u_int cy = s->cy, i, end, next, idx = 0, at, left; struct utf8_data *text; struct grid_cell gc; @@ -382,13 +381,14 @@ screen_write_text(struct screen_write_ctx *ctx, u_int width, u_int lines, text = utf8_fromcstr(tmp); free(tmp); - while (text[idx].size != 0) { + left = (cx + width) - s->cx; + for (;;) { /* Find the end of what can fit on the line. */ at = 0; for (end = idx; text[end].size != 0; end++) { if (text[end].size == 1 && text[end].data[0] == '\n') break; - if (at + text[end].width > width) + if (at + text[end].width > left) break; at += text[end].width; } @@ -422,14 +422,32 @@ screen_write_text(struct screen_write_ctx *ctx, u_int width, u_int lines, } /* If at the bottom, stop. */ - if (s->cy == cy + lines - 1) + idx = next; + if (s->cy == cy + lines - 1 || text[idx].size == 0) break; + screen_write_cursormove(ctx, cx, s->cy + 1, 0); - idx = next; + left = width; } - screen_write_cursormove(ctx, cx, s->cy, 0); + /* + * Fail if on the last line and there is more to come or at the end, or + * if the text was not entirely consumed. + */ + if ((s->cy == cy + lines - 1 && (!more || s->cx == cx + width)) || + text[idx].size != 0) { + free(text); + return (0); + } free(text); + + /* + * If no more to come, move to the next line. Otherwise, leave on + * the same line (except if at the end). + */ + if (!more || s->cx == cx + width) + screen_write_cursormove(ctx, cx, s->cy + 1, 0); + return (1); } /* Write simple string (no maximum length). */ @@ -2471,8 +2471,8 @@ void screen_write_start_callback(struct screen_write_ctx *, struct screen *, void screen_write_stop(struct screen_write_ctx *); void screen_write_reset(struct screen_write_ctx *); size_t printflike(1, 2) screen_write_strlen(const char *, ...); -void printflike(5, 6) screen_write_text(struct screen_write_ctx *, u_int, u_int, - const struct grid_cell *, const char *, ...); +int printflike(7, 8) screen_write_text(struct screen_write_ctx *, u_int, u_int, + u_int, int, const struct grid_cell *, const char *, ...); void printflike(3, 4) screen_write_puts(struct screen_write_ctx *, const struct grid_cell *, const char *, ...); void printflike(4, 5) screen_write_nputs(struct screen_write_ctx *, diff --git a/window-customize.c b/window-customize.c index 1030201d..e180b001 100644 --- a/window-customize.c +++ b/window-customize.c @@ -491,10 +491,10 @@ window_customize_draw(void *modedata, void *itemdata, text = "This option doesn't have a description."; else text = oe->text; - screen_write_text(ctx, sx, sy, &grid_default_cell, "%s", text); - if (s->cy >= cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy, 0, &grid_default_cell, "%s", + text)) goto out; - screen_write_cursormove(ctx, s->cx, s->cy + 1, 0); + screen_write_cursormove(ctx, cx, s->cy + 1, 0); /* skip line */ if (s->cy >= cy + sy - 1) goto out; @@ -509,25 +509,24 @@ window_customize_draw(void *modedata, void *itemdata, text = "session"; else text = "server"; - screen_write_text(ctx, sx, sy - (s->cy - cy), &grid_default_cell, - "This is a %s option.", text); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, + &grid_default_cell, "This is a %s option.", text)) goto out; if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_ARRAY)) { if (idx != -1) { - screen_write_text(ctx, sx, sy - (s->cy - cy), - &grid_default_cell, - "This is an array option, index %u.", idx); + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), + 0, &grid_default_cell, + "This is an array option, index %u.", idx)) + goto out; } else { - screen_write_text(ctx, sx, sy - (s->cy - cy), - &grid_default_cell, "This is an array option."); + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), + 0, &grid_default_cell, "This is an array option.")) + goto out; } if (idx == -1) goto out; - if (s->cy > cy + sy - 1) - goto out; } - screen_write_cursormove(ctx, s->cx, s->cy + 1, 0); + screen_write_cursormove(ctx, cx, s->cy + 1, 0); /* skip line */ if (s->cy >= cy + sy - 1) goto out; @@ -539,19 +538,15 @@ window_customize_draw(void *modedata, void *itemdata, default_value = NULL; } } - screen_write_nputs(ctx, sx, &grid_default_cell, "Option value: %s%s%s", - value, space, unit); - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, + &grid_default_cell, "Option value: %s%s%s", value, space, unit)) goto out; - if (oe == NULL || oe->type == OPTIONS_TABLE_STRING) { expanded = format_expand(ft, value); if (strcmp(expanded, value) != 0) { - screen_write_nputs(ctx, sx, &grid_default_cell, - "This expands to: %s", expanded); - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), + 0, &grid_default_cell, "This expands to: %s", + expanded)) goto out; } free(expanded); @@ -562,44 +557,38 @@ window_customize_draw(void *modedata, void *itemdata, strlcat(choices, ", ", sizeof choices); } choices[strlen(choices) - 2] = '\0'; - screen_write_nputs(ctx, sx, &grid_default_cell, - "Available values are: %s", choices); - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, + &grid_default_cell, "Available values are: %s", + choices)) goto out; } if (oe != NULL && oe->type == OPTIONS_TABLE_COLOUR) { - screen_write_nputs(ctx, sx, &grid_default_cell, - "This is a colour option: "); - if (sx > 24) { - memcpy(&gc, &grid_default_cell, sizeof gc); - gc.fg = options_get_number(item->oo, name); - screen_write_nputs(ctx, sx - 24, &gc, "EXAMPLE"); - } - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 1, + &grid_default_cell, "This is a colour option: ")) + goto out; + memcpy(&gc, &grid_default_cell, sizeof gc); + gc.fg = options_get_number(item->oo, name); + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, &gc, + "EXAMPLE")) goto out; } if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_STYLE)) { - screen_write_nputs(ctx, sx, &grid_default_cell, - "This is a style option: "); - if (sx > 24) { - style_apply(&gc, item->oo, name, ft); - screen_write_nputs(ctx, sx - 24, &gc, "EXAMPLE"); - } - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 1, + &grid_default_cell, "This is a style option: ")) + goto out; + style_apply(&gc, item->oo, name, ft); + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, &gc, + "EXAMPLE")) goto out; } if (default_value != NULL) { - screen_write_nputs(ctx, sx, &grid_default_cell, - "The default is: %s%s%s", default_value, space, unit); - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, + &grid_default_cell, "The default is: %s%s%s", default_value, + space, unit)) goto out; } - screen_write_cursormove(ctx, cx, s->cy + 1, 0); + screen_write_cursormove(ctx, cx, s->cy + 1, 0); /* skip line */ if (s->cy > cy + sy - 1) goto out; if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_ARRAY)) { @@ -626,11 +615,10 @@ window_customize_draw(void *modedata, void *itemdata, parent = options_get_only(wo, name); if (parent != NULL) { value = options_to_string(parent, -1 , 0); - screen_write_nputs(ctx, sx, &grid_default_cell, + if (!screen_write_text(ctx, s->cx, sx, + sy - (s->cy - cy), 0, &grid_default_cell, "Window value (from window %u): %s%s%s", fs.wl->idx, - value, space, unit); - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + value, space, unit)) goto out; } } @@ -638,10 +626,9 @@ window_customize_draw(void *modedata, void *itemdata, parent = options_get_only(go, name); if (parent != NULL) { value = options_to_string(parent, -1 , 0); - screen_write_nputs(ctx, sx, &grid_default_cell, - "Global value: %s%s%s", value, space, unit); - screen_write_cursormove(ctx, cx, s->cy + 1, 0); - if (s->cy > cy + sy - 1) + if (!screen_write_text(ctx, s->cx, sx, + sy - (s->cy - cy), 0, &grid_default_cell, + "Global value: %s%s%s", value, space, unit)) goto out; } } |