Skip to content

Commit 5f7a35d

Browse files
committed
fix(tui): tilde str::replace bug in root path display for windows terminals
1 parent 6da142c commit 5f7a35d

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

src-rust/crates/tui/src/render.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2271,10 +2271,17 @@ fn render_footer(frame: &mut Frame, app: &App, area: Rect) {
22712271
if !parts.is_empty() {
22722272
parts.push(Span::raw(" "));
22732273
}
2274-
let display_dir = if dir.starts_with(std::env::var("HOME").as_deref().unwrap_or("")) {
2275-
dir.replace(std::env::var("HOME").as_deref().unwrap_or(""), "~")
2276-
} else {
2277-
dir.clone()
2274+
// Use dirs::home_dir() so this works on Windows (where $HOME
2275+
// is unset and the home is $USERPROFILE). Guard against an
2276+
// empty home string: `str::replace("", "~")` inserts "~"
2277+
// between every character, producing the infamous
2278+
// `~X~:~\~B~i~g~g~e~r~…` output.
2279+
let home = dirs::home_dir()
2280+
.and_then(|p| p.to_str().map(|s| s.to_string()))
2281+
.filter(|s| !s.is_empty());
2282+
let display_dir = match home {
2283+
Some(h) if dir.starts_with(&h) => dir.replacen(&h, "~", 1),
2284+
_ => dir.clone(),
22782285
};
22792286
parts.push(Span::styled(
22802287
display_dir,

0 commit comments

Comments
 (0)