1
0
mirror of https://github.com/tmux/tmux.git synced 2025-04-17 09:18:48 +00:00

Only align panes and windows, not sessions, from David Mandelberg in

GitHub issue 4444.
This commit is contained in:
nicm 2025-04-02 09:31:00 +00:00
parent 9b37b9285e
commit 4bf38da4d4
3 changed files with 23 additions and 6 deletions

View File

@ -102,6 +102,7 @@ struct mode_tree_item {
int draw_as_parent;
int no_tag;
int align;
struct mode_tree_list children;
TAILQ_ENTRY(mode_tree_item) entry;
@ -667,6 +668,16 @@ mode_tree_no_tag(struct mode_tree_item *mti)
mti->no_tag = 1;
}
/*
* Set the alignment of mti->name: -1 to align left, 0 (default) to not align,
* or 1 to align right.
*/
void
mode_tree_align(struct mode_tree_item *mti, int align)
{
mti->align = align;
}
void
mode_tree_remove(struct mode_tree_data *mtd, struct mode_tree_item *mti)
{
@ -693,7 +704,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
char *text, *start, *key;
const char *tag, *symbol;
size_t size, n;
int keylen, pad, namelen[mtd->maxdepth + 1];
int keylen, pad, alignlen[mtd->maxdepth + 1];
if (mtd->line_size == 0)
return;
@ -718,12 +729,13 @@ mode_tree_draw(struct mode_tree_data *mtd)
}
for (i = 0; i < mtd->maxdepth + 1; i++)
namelen[i] = 0;
alignlen[i] = 0;
for (i = 0; i < mtd->line_size; i++) {
line = &mtd->line_list[i];
mti = line->item;
if ((int)strlen(mti->name) > namelen[line->depth])
namelen[line->depth] = strlen(mti->name);
if (mti->align &&
(int)strlen(mti->name) > alignlen[line->depth])
alignlen[line->depth] = strlen(mti->name);
}
for (i = 0; i < mtd->line_size; i++) {
@ -776,7 +788,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
else
tag = "";
xasprintf(&text, "%-*s%s%*s%s%s", keylen, key, start,
namelen[line->depth], mti->name, tag,
mti->align * alignlen[line->depth], mti->name, tag,
(mti->text != NULL) ? ": " : "" );
width = utf8_cstrwidth(text);
if (width > w)

1
tmux.h
View File

@ -3306,6 +3306,7 @@ struct mode_tree_item *mode_tree_add(struct mode_tree_data *,
const char *, int);
void mode_tree_draw_as_parent(struct mode_tree_item *);
void mode_tree_no_tag(struct mode_tree_item *);
void mode_tree_align(struct mode_tree_item *, int);
void mode_tree_remove(struct mode_tree_data *, struct mode_tree_item *);
void mode_tree_draw(struct mode_tree_data *);
int mode_tree_key(struct mode_tree_data *, struct client *, key_code *,

View File

@ -300,6 +300,7 @@ window_tree_build_pane(struct session *s, struct winlink *wl,
{
struct window_tree_modedata *data = modedata;
struct window_tree_itemdata *item;
struct mode_tree_item *mti;
char *name, *text;
u_int idx;
struct format_tree *ft;
@ -318,9 +319,11 @@ window_tree_build_pane(struct session *s, struct winlink *wl,
xasprintf(&name, "%u", idx);
format_free(ft);
mode_tree_add(data->data, parent, item, (uint64_t)wp, name, text, -1);
mti = mode_tree_add(data->data, parent, item, (uint64_t)wp, name, text,
-1);
free(text);
free(name);
mode_tree_align(mti, 1);
}
static int
@ -375,6 +378,7 @@ window_tree_build_window(struct session *s, struct winlink *wl,
expanded);
free(text);
free(name);
mode_tree_align(mti, 1);
if ((wp = TAILQ_FIRST(&wl->window->panes)) == NULL)
goto empty;