Skip to content

Commit

Permalink
Merge pull request #122 from solidiquis/bug/default-icon-ansi-escape
Browse files Browse the repository at this point in the history
remove ansi escapes for default icon
  • Loading branch information
solidiquis authored Apr 11, 2023
2 parents 0a91720 + 0c1e5ff commit 4b8d729
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "erdtree"
version = "1.8.0"
version = "1.8.1"
edition = "2021"
authors = ["Benjamin Nguyen <[email protected]>"]
description = """
Expand Down
6 changes: 3 additions & 3 deletions src/icons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,7 +40,7 @@ pub fn col(num: u8, code: &str) -> String {
}

/// Default fallback icon.
static DEFAULT_ICON: Lazy<String> = 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
Expand Down
2 changes: 1 addition & 1 deletion src/render/context/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod test;
#[derive(Parser, Debug)]
#[command(name = "erdtree")]
#[command(author = "Benjamin Nguyen. <[email protected]>")]
#[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
Expand Down
10 changes: 8 additions & 2 deletions src/render/tree/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
}
}

Expand Down Expand Up @@ -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
};
Expand Down

0 comments on commit 4b8d729

Please sign in to comment.