Fix alignment for non-digit session names

When session names are all digits, they're aligned right:

```
(0)   -  0: 1 windows
(1)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(2)   -  1: 1 windows
(3)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(4)   -  2: 1 windows
(5)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(6)   -  3: 1 windows
(7)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(8)   -  4: 1 windows
(9)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-a) -  5: 1 windows
(M-b) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-c) -  6: 1 windows
(M-d) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-e) -  7: 1 windows
(M-f) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-g) -  8: 1 windows
(M-h) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-i) -  9: 1 windows
(M-j) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-k) - 10: 1 windows (attached)
(M-l) └─> + 0: [tmux]*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
```

When not all digits, they're aligned left, with no additional padding:

```
(0)   - 0: 1 windows
(1)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(2)   - 1: 1 windows
(3)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(4)   - 2: 1 windows
(5)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(6)   - 3: 1 windows
(7)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(8)   - 4: 1 windows
(9)   └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-a) - 5: 1 windows
(M-b) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-c) - 6: 1 windows
(M-d) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-e) - 7: 1 windows
(M-f) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-g) - 8: 1 windows
(M-h) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-i) - 9: 1 windows
(M-j) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-k) - 10: 1 windows (attached)
(M-l) └─> + 0: [tmux]*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
(M-m) - foo: 1 windows
(M-n) └─> + 0: bash*: "dseomn@a4b80476102d:/tmp/tmp.mMXuTzbXGm"
```

Fixes #4442
This commit is contained in:
David Mandelberg
2025-03-28 21:59:57 -04:00
parent 096c4b3e63
commit e054b06174

View File

@@ -694,6 +694,7 @@ mode_tree_draw(struct mode_tree_data *mtd)
const char *tag, *symbol;
size_t size, n;
int keylen, pad, namelen[mtd->maxdepth + 1];
int names_all_digits[mtd->maxdepth + 1];
if (mtd->line_size == 0)
return;
@@ -717,13 +718,20 @@ mode_tree_draw(struct mode_tree_data *mtd)
keylen = mti->keylen + 3;
}
for (i = 0; i < mtd->maxdepth + 1; i++)
for (i = 0; i < mtd->maxdepth + 1; i++) {
namelen[i] = 0;
names_all_digits[i] = 1;
}
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);
for (j = 0; mti->name[j] && names_all_digits[line->depth];
j++) {
if (mti->name[j] < '0' || mti->name[j] > '9')
names_all_digits[line->depth] = 0;
}
}
for (i = 0; i < mtd->line_size; i++) {
@@ -776,8 +784,8 @@ 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->text != NULL) ? ": " : "" );
names_all_digits[line->depth] ? namelen[line->depth] : 0,
mti->name, tag, (mti->text != NULL) ? ": " : "" );
width = utf8_cstrwidth(text);
if (width > w)
width = w;