From 34b881d617f8dab5c962a2a3aaa4b957dc32df01 Mon Sep 17 00:00:00 2001 From: Benjamin Nguyen Date: Tue, 11 Apr 2023 00:58:55 -0700 Subject: [PATCH 1/2] remove ansi escapes for default icon --- src/icons.rs | 6 +++--- src/render/tree/node/mod.rs | 10 ++++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/icons.rs b/src/icons.rs index f2f02a76..b5980f8e 100644 --- a/src/icons.rs +++ b/src/icons.rs @@ -30,8 +30,8 @@ pub fn icon_from_file_name(name: &OsStr) -> Option<&'static str> { } /// Returns the default fallback icon. -pub fn get_default_icon<'a>() -> &'a str { - DEFAULT_ICON.as_str() +pub fn get_default_icon<'a>() -> (u8, &'a str) { + *DEFAULT_ICON } /// Convenience method to paint fixed colors. @@ -40,7 +40,7 @@ pub fn col(num: u8, code: &str) -> String { } /// Default fallback icon. -static DEFAULT_ICON: Lazy = Lazy::new(|| col(66, "\u{f15b}")); +static DEFAULT_ICON: Lazy<(u8, &str)> = Lazy::new(|| (66, "\u{f15b}")); /// Lazily evaluated static hash-map of special file-types and their corresponding styled icons. /// These icons will take on the color properties of their associated file which is based on diff --git a/src/render/tree/node/mod.rs b/src/render/tree/node/mod.rs index 0ee7ffe6..eb57ceca 100644 --- a/src/render/tree/node/mod.rs +++ b/src/render/tree/node/mod.rs @@ -321,7 +321,12 @@ impl Node { return icon; } - Some(Cow::from(get_default_icon())) + if no_color { + Some(Cow::from(get_default_icon().1)) + } else { + let (code, icon) = get_default_icon(); + Some(Cow::from(icons::col(code, icon))) + } } } @@ -355,7 +360,8 @@ impl TryFrom<(DirEntry, &Context)> for Node { }; let icon = if ctx.icons { - Self::compute_icon(&dir_entry, link_target.as_ref(), style, ctx.no_color) + let no_color = ctx.no_color || !tty::stdout_is_tty(); + Self::compute_icon(&dir_entry, link_target.as_ref(), style, no_color) } else { None }; From 0c1e5ff42644e02be629bbe3526b8ce90298fa36 Mon Sep 17 00:00:00 2001 From: Benjamin Nguyen Date: Tue, 11 Apr 2023 01:00:27 -0700 Subject: [PATCH 2/2] version bump --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/render/context/mod.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6f7899be..a1dd1f8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,7 @@ dependencies = [ [[package]] name = "erdtree" -version = "1.8.0" +version = "1.8.1" dependencies = [ "ansi_term", "clap", diff --git a/Cargo.toml b/Cargo.toml index a10b2b95..ceab5774 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "erdtree" -version = "1.8.0" +version = "1.8.1" edition = "2021" authors = ["Benjamin Nguyen "] description = """ diff --git a/src/render/context/mod.rs b/src/render/context/mod.rs index aea04de8..d18af56e 100644 --- a/src/render/context/mod.rs +++ b/src/render/context/mod.rs @@ -26,7 +26,7 @@ mod test; #[derive(Parser, Debug)] #[command(name = "erdtree")] #[command(author = "Benjamin Nguyen. ")] -#[command(version = "1.8.0")] +#[command(version = "1.8.1")] #[command(about = "erdtree (et) is a multi-threaded file-tree visualization and disk usage analysis tool.", long_about = None)] pub struct Context { /// Include aggregate file count in tree output