Skip to content

remove ansi escapes for default icon #122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
remove ansi escapes for default icon
  • Loading branch information
solidiquis committed Apr 11, 2023
commit 34b881d617f8dab5c962a2a3aaa4b957dc32df01
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
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