diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-10-27 11:10:26 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-10-27 11:15:07 -0400 |
commit | caeff0108d59d36a3c3fc62fd5ed788eaaf4f0a5 (patch) | |
tree | 8799ef9a18ea6e304140b0ff9dc5009235972415 | |
parent | 14ef89a442f7a027f52fd688b438c5fa627b6af7 (diff) | |
download | bfs-caeff0108d59d36a3c3fc62fd5ed788eaaf4f0a5.tar.xz |
eval: TTY-escape paths in the status bar
-rw-r--r-- | src/eval.c | 12 |
1 files changed, 8 insertions, 4 deletions
@@ -1137,6 +1137,12 @@ static void eval_status(struct bfs_eval *state, struct bfs_bar *bar, struct time pathlen = strlen(path); } + // Escape weird filename characters + if (dstrnescat(&status, path, pathlen, WESC_TTY) != 0) { + goto out; + } + pathlen = dstrlen(status); + // Try to make sure even wide characters fit in the status bar size_t pathmax = width - rhslen - 3; size_t pathwidth = 0; @@ -1144,7 +1150,7 @@ static void eval_status(struct bfs_eval *state, struct bfs_bar *bar, struct time mbstate_t mb; memset(&mb, 0, sizeof(mb)); for (size_t i = lhslen; lhslen < pathlen; lhslen = i) { - wint_t wc = xmbrtowc(path, &i, pathlen, &mb); + wint_t wc = xmbrtowc(status, &i, pathlen, &mb); int cwidth; if (wc == WEOF) { // Invalid byte sequence, assume a single-width '?' @@ -1161,10 +1167,8 @@ static void eval_status(struct bfs_eval *state, struct bfs_bar *bar, struct time } pathwidth += cwidth; } + dstresize(&status, lhslen); - if (dstrncat(&status, path, lhslen) != 0) { - goto out; - } if (dstrcat(&status, "...") != 0) { goto out; } |