Skip to content

Commit

Permalink
fix outdated files
Browse files Browse the repository at this point in the history
  • Loading branch information
r3dArch committed Oct 14, 2022
1 parent 97cd83e commit 06e4361
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 37 deletions.
57 changes: 31 additions & 26 deletions src/color.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
mod theme;

use crossterm::style::{Attribute, ContentStyle, StyledContent, Stylize};
use theme::Theme;

pub use crate::flags::color::ThemeOption;

use crossterm::style::Color;
use crossterm::style::{Attribute, ContentStyle, StyledContent, Stylize};
use lscolors::{Indicator, LsColors};
use std::path::Path;

pub use crate::flags::color::ThemeOption;
use crate::theme::{color::ColorTheme, Theme};

#[allow(dead_code)]
#[derive(Hash, Debug, Eq, PartialEq, Clone)]
pub enum Elem {
Expand Down Expand Up @@ -71,7 +68,7 @@ impl Elem {
matches!(self, Elem::Dir { uid: true } | Elem::File { uid: true, .. })
}

fn get_color(&self, theme: &theme::Theme) -> Color {
pub fn get_color(&self, theme: &ColorTheme) -> Color {
match self {
Elem::File {
exec: true,
Expand Down Expand Up @@ -131,16 +128,24 @@ impl Elem {
pub type ColoredString = StyledContent<String>;

pub struct Colors {
theme: Option<Theme>,
theme: Option<ColorTheme>,
lscolors: Option<LsColors>,
}

impl Colors {
pub fn new(t: ThemeOption) -> Self {
let theme = match t {
ThemeOption::NoColor => None,
ThemeOption::Default | ThemeOption::NoLscolors => Some(Theme::default()),
ThemeOption::Custom(ref file) => Some(Theme::from_path(file).unwrap_or_default()),
ThemeOption::Default | ThemeOption::NoLscolors => Some(Theme::default().color),
ThemeOption::Custom(ref file) => {
// TODO: drop the `themes` dir prefix, adding it here only for backwards compatibility
Some(
Theme::from_path::<ColorTheme>(
Path::new("themes").join(file).to_str().unwrap_or(file),
)
.unwrap_or_default(),
)
}
};
let lscolors = match t {
ThemeOption::Default | ThemeOption::Custom(_) => {
Expand Down Expand Up @@ -301,8 +306,8 @@ fn to_content_style(ls: &lscolors::Style) -> ContentStyle {
#[cfg(test)]
mod tests {
use super::Colors;
use crate::color::Theme;
use crate::color::ThemeOption;
use crate::theme::color::ColorTheme;
#[test]
fn test_color_new_no_color_theme() {
assert!(Colors::new(ThemeOption::NoColor).theme.is_none());
Expand All @@ -312,31 +317,31 @@ mod tests {
fn test_color_new_default_theme() {
assert_eq!(
Colors::new(ThemeOption::Default).theme,
Some(Theme::default_dark()),
Some(ColorTheme::default_dark()),
);
}

#[test]
fn test_color_new_bad_custom_theme() {
assert_eq!(
Colors::new(ThemeOption::Custom("not-existed".to_string())).theme,
Some(Theme::default_dark()),
Some(ColorTheme::default_dark()),
);
}
}

#[cfg(test)]
mod elem {
use super::Elem;
use crate::color::{theme, Theme};
use crate::theme::{color, color::ColorTheme};
use crossterm::style::Color;

#[cfg(test)]
fn test_theme() -> Theme {
Theme {
fn test_theme() -> ColorTheme {
ColorTheme {
user: Color::AnsiValue(230), // Cornsilk1
group: Color::AnsiValue(187), // LightYellow3
permission: theme::Permission {
permission: color::Permission {
read: Color::Green,
write: Color::Yellow,
exec: Color::Red,
Expand All @@ -346,19 +351,19 @@ mod elem {
acl: Color::DarkCyan,
context: Color::Cyan,
},
file_type: theme::FileType {
file: theme::File {
file_type: color::FileType {
file: color::File {
exec_uid: Color::AnsiValue(40), // Green3
uid_no_exec: Color::AnsiValue(184), // Yellow3
exec_no_uid: Color::AnsiValue(40), // Green3
no_exec_no_uid: Color::AnsiValue(184), // Yellow3
},
dir: theme::Dir {
dir: color::Dir {
uid: Color::AnsiValue(33), // DodgerBlue1
no_uid: Color::AnsiValue(33), // DodgerBlue1
},
pipe: Color::AnsiValue(44), // DarkTurquoise
symlink: theme::Symlink {
symlink: color::Symlink {
default: Color::AnsiValue(44), // DarkTurquoise
broken: Color::AnsiValue(124), // Red3
missing_target: Color::AnsiValue(124), // Red3
Expand All @@ -368,22 +373,22 @@ mod elem {
socket: Color::AnsiValue(44), // DarkTurquoise
special: Color::AnsiValue(44), // DarkTurquoise
},
date: theme::Date {
date: color::Date {
hour_old: Color::AnsiValue(40), // Green3
day_old: Color::AnsiValue(42), // SpringGreen2
older: Color::AnsiValue(36), // DarkCyan
},
size: theme::Size {
size: color::Size {
none: Color::AnsiValue(245), // Grey
small: Color::AnsiValue(229), // Wheat1
medium: Color::AnsiValue(216), // LightSalmon1
large: Color::AnsiValue(172), // Orange3
},
inode: theme::INode {
inode: color::INode {
valid: Color::AnsiValue(13), // Pink
invalid: Color::AnsiValue(245), // Grey
},
links: theme::Links {
links: color::Links {
valid: Color::AnsiValue(13), // Pink
invalid: Color::AnsiValue(245), // Grey
},
Expand Down
16 changes: 5 additions & 11 deletions src/core.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use crate::color::Colors;
use crate::display;
use crate::flags::{
ColorOption, Display, Flags, HyperlinkOption, IconOption, IconTheme, Layout, SortOrder,
ThemeOption,
};
use crate::icon::{self, Icons};
use crate::flags::{ColorOption, Display, Flags, HyperlinkOption, Layout, SortOrder, ThemeOption};
use crate::icon::Icons;
use crate::meta::Meta;
use crate::{print_error, print_output, sort, ExitCode};
use std::path::PathBuf;
Expand Down Expand Up @@ -47,11 +44,8 @@ impl Core {
_ => flags.color.theme.clone(),
};

let icon_theme = match (tty_available, flags.icons.when, flags.icons.theme) {
(_, IconOption::Never, _) | (false, IconOption::Auto, _) => icon::Theme::NoIcon,
(_, _, IconTheme::Fancy) => icon::Theme::Fancy,
(_, _, IconTheme::Unicode) => icon::Theme::Unicode,
};
let icon_when = flags.icons.when;
let icon_theme = flags.icons.theme.clone();

// TODO: Rework this so that flags passed downstream does not
// have Auto option for any (icon, color, hyperlink).
Expand Down Expand Up @@ -80,7 +74,7 @@ impl Core {
Self {
flags,
colors: Colors::new(color_theme),
icons: Icons::new(icon_theme, icon_separator),
icons: Icons::new(tty_available, icon_when, icon_theme, icon_separator),
sorters,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ mod flags;
mod icon;
mod meta;
mod sort;
mod theme;

use crate::config_file::Config;
use crate::core::Core;
Expand Down

0 comments on commit 06e4361

Please sign in to comment.