mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-14 22:22:26 +00:00
Added --theme
option to select icon theme
Possible values are `default` and `unicode`.
This commit is contained in:
parent
662f3ddf38
commit
bc3e47c6d7
5 changed files with 47 additions and 14 deletions
|
@ -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")
|
||||
|
|
12
src/core.rs
12
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 {
|
||||
|
|
20
src/flags.rs
20
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<Self, Error> {
|
||||
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;
|
||||
|
|
|
@ -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())
|
||||
};
|
||||
|
|
15
src/main.rs
15
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;
|
||||
|
|
Loading…
Reference in a new issue