T13: a label built from a path shows control characters as their pictures, so a name with a newline no longer aborts gpui's line shaping in Files or the session row; on macOS a name meets Git's mark in composed form, as git writes it; the rev-parse prefix keeps its own newlines
CI / platforms (windows-latest) (push) Failing after 8s
CI / macos (push) Failing after 9m56s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-14 19:25:58 -04:00
1 parent 8369d96b36
commit 937dab8552
7 files changed
+167 -22

No files matched your search

+25 -3
View File
@@ -27,13 +27,25 @@ pub struct Session {
pub _events: Subscription,
}
/// `folder` as a row shows it: the home folder as `~`.
/// `folder` as a row shows it: the home folder as `~`, on one line.
pub fn shown(folder: &Path, home: Option<&Path>) -> String {
match home.and_then(|home| folder.strip_prefix(home).ok()) {
let shown = match home.and_then(|home| folder.strip_prefix(home).ok()) {
Some(rest) if rest.as_os_str().is_empty() => "~".into(),
Some(rest) => format!("~{MAIN_SEPARATOR}{}", rest.display()),
None => folder.display().to_string(),
}
};
one_line(&shown)
}
/// `text` on one line, as gpui shapes labels: each control character as its picture, `␊` for a newline.
pub fn one_line(text: &str) -> String {
text.chars()
.map(|c| match c {
'\0'..='\x1f' => char::from_u32(0x2400 + c as u32).expect("a control picture"),
'\x7f' => '\u{2421}',
c => c,
})
.collect()
}
/// The session shown once session `closed` of `left + 1` is gone, `active` having been shown.
@@ -102,6 +114,16 @@ mod tests {
"a sibling is no child"
);
assert_eq!(shown("/tmp"), "/tmp");
assert_eq!(
shown("/Users/ely/line\nbreak"),
format!("~{MAIN_SEPARATOR}line␊break")
);
}
#[test]
fn control_characters_show_as_their_pictures() {
assert_eq!(one_line("a\nb\tc\rd\0e\u{7f}"), "a␊b␉c␍d␀e␡");
assert_eq!(one_line("café ✓"), "café ✓", "printable text stays");
}
#[test]