1
0
mirror of https://github.com/tmux/tmux.git synced 2025-04-25 14:35:39 +00:00

Wrap all lines in customize mode, not just the description.

This commit is contained in:
Nicholas Marriott 2020-05-09 15:29:14 +01:00
parent 690d72adb3
commit 013d857ef8
3 changed files with 75 additions and 70 deletions

View File

@ -361,15 +361,14 @@ screen_write_strlen(const char *fmt, ...)
} }
/* Write string wrapped over lines. */ /* Write string wrapped over lines. */
void int
screen_write_text(struct screen_write_ctx *ctx, u_int width, u_int lines, screen_write_text(struct screen_write_ctx *ctx, u_int cx, u_int width,
const struct grid_cell *gcp, const char *fmt, ...) u_int lines, int more, const struct grid_cell *gcp, const char *fmt, ...)
{ {
struct screen *s = ctx->s; struct screen *s = ctx->s;
u_int cx = s->cx, cy = s->cy;
va_list ap; va_list ap;
char *tmp; 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 utf8_data *text;
struct grid_cell gc; 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); text = utf8_fromcstr(tmp);
free(tmp); free(tmp);
while (text[idx].size != 0) { left = (cx + width) - s->cx;
for (;;) {
/* Find the end of what can fit on the line. */ /* Find the end of what can fit on the line. */
at = 0; at = 0;
for (end = idx; text[end].size != 0; end++) { for (end = idx; text[end].size != 0; end++) {
if (text[end].size == 1 && text[end].data[0] == '\n') if (text[end].size == 1 && text[end].data[0] == '\n')
break; break;
if (at + text[end].width > width) if (at + text[end].width > left)
break; break;
at += text[end].width; 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 at the bottom, stop. */
if (s->cy == cy + lines - 1)
break;
screen_write_cursormove(ctx, cx, s->cy + 1, 0);
idx = next; idx = next;
if (s->cy == cy + lines - 1 || text[idx].size == 0)
break;
screen_write_cursormove(ctx, cx, s->cy + 1, 0);
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); 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). */ /* Write simple string (no maximum length). */

4
tmux.h
View File

@ -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_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_strlen(const char *, ...); 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, int printflike(7, 8) screen_write_text(struct screen_write_ctx *, u_int, u_int,
const struct grid_cell *, const char *, ...); u_int, int, const struct grid_cell *, const char *, ...);
void printflike(3, 4) screen_write_puts(struct screen_write_ctx *, void printflike(3, 4) screen_write_puts(struct screen_write_ctx *,
const 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 *,

View File

@ -491,10 +491,10 @@ window_customize_draw(void *modedata, void *itemdata,
text = "This option doesn't have a description."; text = "This option doesn't have a description.";
else else
text = oe->text; text = oe->text;
screen_write_text(ctx, sx, sy, &grid_default_cell, "%s", text); if (!screen_write_text(ctx, cx, sx, sy, 0, &grid_default_cell, "%s",
if (s->cy >= cy + sy - 1) text))
goto out; 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) if (s->cy >= cy + sy - 1)
goto out; goto out;
@ -509,25 +509,24 @@ window_customize_draw(void *modedata, void *itemdata,
text = "session"; text = "session";
else else
text = "server"; text = "server";
screen_write_text(ctx, sx, sy - (s->cy - cy), &grid_default_cell, if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0,
"This is a %s option.", text); &grid_default_cell, "This is a %s option.", text))
if (s->cy > cy + sy - 1)
goto out; goto out;
if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_ARRAY)) { if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_ARRAY)) {
if (idx != -1) { if (idx != -1) {
screen_write_text(ctx, sx, sy - (s->cy - cy), if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy),
&grid_default_cell, 0, &grid_default_cell,
"This is an array option, index %u.", idx); "This is an array option, index %u.", idx))
goto out;
} else { } else {
screen_write_text(ctx, sx, sy - (s->cy - cy), if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy),
&grid_default_cell, "This is an array option."); 0, &grid_default_cell, "This is an array option."))
goto out;
} }
if (idx == -1) if (idx == -1)
goto out; 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) if (s->cy >= cy + sy - 1)
goto out; goto out;
@ -539,19 +538,15 @@ window_customize_draw(void *modedata, void *itemdata,
default_value = NULL; default_value = NULL;
} }
} }
screen_write_nputs(ctx, sx, &grid_default_cell, "Option value: %s%s%s", if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0,
value, space, unit); &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)
goto out; goto out;
if (oe == NULL || oe->type == OPTIONS_TABLE_STRING) { if (oe == NULL || oe->type == OPTIONS_TABLE_STRING) {
expanded = format_expand(ft, value); expanded = format_expand(ft, value);
if (strcmp(expanded, value) != 0) { if (strcmp(expanded, value) != 0) {
screen_write_nputs(ctx, sx, &grid_default_cell, if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy),
"This expands to: %s", expanded); 0, &grid_default_cell, "This expands to: %s",
screen_write_cursormove(ctx, cx, s->cy + 1, 0); expanded))
if (s->cy > cy + sy - 1)
goto out; goto out;
} }
free(expanded); free(expanded);
@ -562,44 +557,38 @@ window_customize_draw(void *modedata, void *itemdata,
strlcat(choices, ", ", sizeof choices); strlcat(choices, ", ", sizeof choices);
} }
choices[strlen(choices) - 2] = '\0'; choices[strlen(choices) - 2] = '\0';
screen_write_nputs(ctx, sx, &grid_default_cell, if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0,
"Available values are: %s", choices); &grid_default_cell, "Available values are: %s",
screen_write_cursormove(ctx, cx, s->cy + 1, 0); choices))
if (s->cy > cy + sy - 1)
goto out; goto out;
} }
if (oe != NULL && oe->type == OPTIONS_TABLE_COLOUR) { if (oe != NULL && oe->type == OPTIONS_TABLE_COLOUR) {
screen_write_nputs(ctx, sx, &grid_default_cell, if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 1,
"This is a colour option: "); &grid_default_cell, "This is a colour option: "))
if (sx > 24) { goto out;
memcpy(&gc, &grid_default_cell, sizeof gc); memcpy(&gc, &grid_default_cell, sizeof gc);
gc.fg = options_get_number(item->oo, name); gc.fg = options_get_number(item->oo, name);
screen_write_nputs(ctx, sx - 24, &gc, "EXAMPLE"); if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, &gc,
} "EXAMPLE"))
screen_write_cursormove(ctx, cx, s->cy + 1, 0);
if (s->cy > cy + sy - 1)
goto out; goto out;
} }
if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_STYLE)) { if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_STYLE)) {
screen_write_nputs(ctx, sx, &grid_default_cell, if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 1,
"This is a style option: "); &grid_default_cell, "This is a style option: "))
if (sx > 24) { goto out;
style_apply(&gc, item->oo, name, ft); style_apply(&gc, item->oo, name, ft);
screen_write_nputs(ctx, sx - 24, &gc, "EXAMPLE"); if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0, &gc,
} "EXAMPLE"))
screen_write_cursormove(ctx, cx, s->cy + 1, 0);
if (s->cy > cy + sy - 1)
goto out; goto out;
} }
if (default_value != NULL) { if (default_value != NULL) {
screen_write_nputs(ctx, sx, &grid_default_cell, if (!screen_write_text(ctx, cx, sx, sy - (s->cy - cy), 0,
"The default is: %s%s%s", default_value, space, unit); &grid_default_cell, "The default is: %s%s%s", default_value,
screen_write_cursormove(ctx, cx, s->cy + 1, 0); space, unit))
if (s->cy > cy + sy - 1)
goto out; 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) if (s->cy > cy + sy - 1)
goto out; goto out;
if (oe != NULL && (oe->flags & OPTIONS_TABLE_IS_ARRAY)) { 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); parent = options_get_only(wo, name);
if (parent != NULL) { if (parent != NULL) {
value = options_to_string(parent, -1 , 0); 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, "Window value (from window %u): %s%s%s", fs.wl->idx,
value, space, unit); value, space, unit))
screen_write_cursormove(ctx, cx, s->cy + 1, 0);
if (s->cy > cy + sy - 1)
goto out; goto out;
} }
} }
@ -638,10 +626,9 @@ window_customize_draw(void *modedata, void *itemdata,
parent = options_get_only(go, name); parent = options_get_only(go, name);
if (parent != NULL) { if (parent != NULL) {
value = options_to_string(parent, -1 , 0); value = options_to_string(parent, -1 , 0);
screen_write_nputs(ctx, sx, &grid_default_cell, if (!screen_write_text(ctx, s->cx, sx,
"Global value: %s%s%s", value, space, unit); sy - (s->cy - cy), 0, &grid_default_cell,
screen_write_cursormove(ctx, cx, s->cy + 1, 0); "Global value: %s%s%s", value, space, unit))
if (s->cy > cy + sy - 1)
goto out; goto out;
} }
} }