diff --git a/src/app.rs b/src/app.rs index 9ea99c4..94df165 100644 --- a/src/app.rs +++ b/src/app.rs @@ -32,6 +32,15 @@ pub fn build() -> App<'static, 'static> { .multiple(true) .help("When to print the icons"), ) + .arg( + Arg::with_name("theme") + .long("theme") + .possible_value("default") + .possible_value("unicode") + .default_value("default") + .multiple(true) + .help("Whether to use extended or unicode icons"), + ) .arg( Arg::with_name("indicators") .short("F") diff --git a/src/core.rs b/src/core.rs index db3fa44..3435da9 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,7 +1,7 @@ use batch::Batch; use color::{self, Colors}; use display::Display; -use flags::{Flags, WhenFlag}; +use flags::{Flags, ThemeFlag, WhenFlag}; use icon::{self, Icons}; use meta::{FileType, Meta}; use std::path::{Path, PathBuf}; @@ -28,12 +28,10 @@ impl Core { _ => color::Theme::Default, }; - let icon_theme = match (tty_available, flags.icon) { - (true, WhenFlag::Never) => icon::Theme::NoIcon, - (false, WhenFlag::Never) => icon::Theme::NoIcon, - (false, WhenFlag::Auto) => icon::Theme::NoIcon, - (false, WhenFlag::Always) => icon::Theme::Default, - _ => icon::Theme::Default, + let icon_theme = match (tty_available, flags.icon, flags.icon_theme) { + (_, WhenFlag::Never, _) | (false, WhenFlag::Auto, _) => icon::Theme::NoIcon, + (_, _, ThemeFlag::Default) => icon::Theme::Default, + (_, _, ThemeFlag::Unicode) => icon::Theme::Unicode, }; if !tty_available { diff --git a/src/flags.rs b/src/flags.rs index f1fb675..56a9144 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -14,6 +14,7 @@ pub struct Flags { pub date: DateFlag, pub color: WhenFlag, pub icon: WhenFlag, + pub icon_theme: ThemeFlag, pub recursion_depth: usize, } @@ -21,6 +22,7 @@ impl Flags { pub fn from_matches(matches: &ArgMatches) -> Result { let color_inputs: Vec<&str> = matches.values_of("color").unwrap().collect(); let icon_inputs: Vec<&str> = matches.values_of("icon").unwrap().collect(); + let icon_theme_inputs: Vec<&str> = matches.values_of("theme").unwrap().collect(); let date_inputs: Vec<&str> = matches.values_of("date").unwrap().collect(); let dir_order_inputs: Vec<&str> = matches.values_of("group-dirs").unwrap().collect(); @@ -70,6 +72,7 @@ impl Flags { date: DateFlag::from(date_inputs[date_inputs.len() - 1]), color: WhenFlag::from(color_inputs[color_inputs.len() - 1]), icon: WhenFlag::from(icon_inputs[icon_inputs.len() - 1]), + icon_theme: ThemeFlag::from(icon_theme_inputs[icon_inputs.len() - 1]), directory_order: DirOrderFlag::from(dir_order_inputs[dir_order_inputs.len() - 1]), }) } @@ -91,6 +94,7 @@ impl Default for Flags { date: DateFlag::Date, color: WhenFlag::Auto, icon: WhenFlag::Auto, + icon_theme: ThemeFlag::Default, } } } @@ -159,6 +163,22 @@ impl<'a> From<&'a str> for DirOrderFlag { } } +#[derive(Clone, Debug, Copy, PartialEq, Eq)] +pub enum ThemeFlag { + Unicode, + Default, +} + +impl<'a> From<&'a str> for ThemeFlag { + fn from(theme: &'a str) -> Self { + match theme { + "default" => ThemeFlag::Default, + "unicode" => ThemeFlag::Unicode, + _ => panic!("invalid \"theme\" flag: {}", theme), + } + } +} + #[cfg(test)] mod test { use super::Flags; diff --git a/src/icon.rs b/src/icon.rs index 23c67f0..36bd4ed 100644 --- a/src/icon.rs +++ b/src/icon.rs @@ -24,7 +24,10 @@ impl Icons { pub fn new(theme: Theme) -> Self { let display_icons = theme == Theme::Default || theme == Theme::Unicode; let (icons_by_name, icons_by_extension) = if theme == Theme::Default { - (Self::get_default_icons_by_name(), Self::get_default_icons_by_extension()) + ( + Self::get_default_icons_by_name(), + Self::get_default_icons_by_extension(), + ) } else { (HashMap::new(), HashMap::new()) }; diff --git a/src/main.rs b/src/main.rs index 6b97871..3a6e93b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,12 @@ -#![cfg_attr(feature = "cargo-clippy", allow( - clippy::cast_precision_loss, - clippy::cast_sign_loss, - clippy::match_same_arms, - clippy::cast_possible_wrap -))] +#![cfg_attr( + feature = "cargo-clippy", + allow( + clippy::cast_precision_loss, + clippy::cast_sign_loss, + clippy::match_same_arms, + clippy::cast_possible_wrap + ) +)] #[macro_use] extern crate clap;