mirror of
https://github.com/ouch-org/ouch.git
synced 2025-07-19 08:00:31 +00:00
fix(list): remove duplicate trailing slashes for directorie
This commit is contained in:
parent
4479314bc2
commit
5d79880b67
34
src/list.rs
34
src/list.rs
@ -52,22 +52,28 @@ pub fn list_files(
|
|||||||
fn print_entry(out: &mut impl Write, name: impl std::fmt::Display, is_dir: bool) {
|
fn print_entry(out: &mut impl Write, name: impl std::fmt::Display, is_dir: bool) {
|
||||||
use crate::utils::colors::*;
|
use crate::utils::colors::*;
|
||||||
|
|
||||||
if is_dir {
|
if !is_dir {
|
||||||
// if colors are deactivated, print final / to mark directories
|
// Not a directory -> just print the file name
|
||||||
if BLUE.is_empty() {
|
|
||||||
let _ = writeln!(out, "{name}/");
|
|
||||||
// if in ACCESSIBLE mode, use colors but print final / in case colors
|
|
||||||
// aren't read out aloud with a screen reader or aren't printed on a
|
|
||||||
// braille reader
|
|
||||||
} else if is_running_in_accessible_mode() {
|
|
||||||
let _ = writeln!(out, "{}{}{}/{}", *BLUE, *STYLE_BOLD, name, *ALL_RESET);
|
|
||||||
} else {
|
|
||||||
let _ = writeln!(out, "{}{}{}{}", *BLUE, *STYLE_BOLD, name, *ALL_RESET);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// not a dir -> just print the file name
|
|
||||||
let _ = writeln!(out, "{name}");
|
let _ = writeln!(out, "{name}");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle directory display
|
||||||
|
let name_str = name.to_string();
|
||||||
|
let display_name = name_str.strip_suffix('/').unwrap_or(&name_str);
|
||||||
|
|
||||||
|
let output = if BLUE.is_empty() {
|
||||||
|
// Colors are deactivated, print final / to mark directories
|
||||||
|
format!("{display_name}/")
|
||||||
|
} else if is_running_in_accessible_mode() {
|
||||||
|
// Accessible mode: use colors but print final / for screen readers
|
||||||
|
format!("{}{}{}/{}", *BLUE, *STYLE_BOLD, display_name, *ALL_RESET)
|
||||||
|
} else {
|
||||||
|
// Normal mode: use colors without trailing slash
|
||||||
|
format!("{}{}{}{}", *BLUE, *STYLE_BOLD, display_name, *ALL_RESET)
|
||||||
|
};
|
||||||
|
|
||||||
|
let _ = writeln!(out, "{output}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Since archives store files as a list of entries -> without direct
|
/// Since archives store files as a list of entries -> without direct
|
||||||
|
Loading…
x
Reference in New Issue
Block a user