Skip to content

Commit cc9621b

Browse files
committed
Fix directory display with trailing slashes in list output
1 parent c1bc86c commit cc9621b

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Categories Used:
6060
- Fix renaming broken when multi extension paths (https://github.com/ouch-org/ouch/pull/919)
6161
- Fix incorrectly overwriting input file when file signature is sniffed (https://github.com/ouch-org/ouch/pull/920)
6262
- Add safeguards before deleting directories (https://github.com/ouch-org/ouch/pull/930)
63+
- Fix directory display with trailing slashes in list output (https://github.com/ouch-org/ouch/commit/de22cbc)
6364

6465
### Tweaks
6566

src/list.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,16 @@ fn print_entry(out: &mut impl Write, name: impl fmt::Display, is_dir: bool) {
6161

6262
// Handle directory display
6363
let name_str = name.to_string();
64-
let display_name = name_str.strip_suffix('/').unwrap_or(&name_str);
64+
// Strip trailing slashes so we can consistently re-add one when needed.
65+
// This handles CLI `zip` which includes / in directory paths.
66+
let display_name = name_str.trim_end_matches('/');
6567

6668
let output = if BLUE.is_empty() {
67-
// Colors are deactivated, print final / to mark directories
69+
// Colors deactivated, print final / to mark directories
6870
format!("{display_name}/")
6971
} else if is_running_in_accessible_mode() {
70-
// Accessible mode: use colors but print final / for screen readers
71-
format!("{}{}{}/{}", *BLUE, *STYLE_BOLD, display_name, *ALL_RESET)
72+
// Accessible mode: colors + trailing / for screen readers
73+
format!("{}{}{display_name}/{}", *BLUE, *STYLE_BOLD, *ALL_RESET)
7274
} else {
7375
// Normal mode: use colors without trailing slash
7476
format!("{}{}{}{}", *BLUE, *STYLE_BOLD, display_name, *ALL_RESET)

0 commit comments

Comments
 (0)