🔨 move symlink arrow to root level

This commit is contained in:
zwPapEr 2020-11-01 22:50:32 +08:00 committed by Abin Simon
parent 448cfd5a2c
commit 95535cb67c
5 changed files with 27 additions and 35 deletions

View file

@ -260,12 +260,9 @@ no-symlink: false
# Possible values: false, true
total-size: false
# == Styling ==
# How lsd looks like
#
# symlink-arrow: chars both ascii and utf8
styling:
symlink-arrow: ⇒
# == Symlink arrow ==
# Specifies how the symlink arrow display, chars in both ascii and utf8
symlink-arrow: ⇒
```
## External Configurations

View file

@ -286,7 +286,7 @@ fn get_output<'a>(
ANSIStrings(&[
meta.name.render(colors, icons, &display_option),
meta.indicator.render(&flags),
meta.symlink.render(colors, &flags.styles),
meta.symlink.render(colors, &flags),
])
.to_string()
};

View file

@ -10,7 +10,7 @@ pub mod layout;
pub mod recursion;
pub mod size;
pub mod sorting;
pub mod styling;
pub mod symlink_arrow;
pub mod symlinks;
pub mod total_size;
@ -33,7 +33,7 @@ pub use sorting::DirGrouping;
pub use sorting::SortColumn;
pub use sorting::SortOrder;
pub use sorting::Sorting;
pub use styling::SymlinkArrow;
pub use symlink_arrow::SymlinkArrow;
pub use symlinks::NoSymlink;
pub use total_size::TotalSize;
@ -61,12 +61,6 @@ pub struct Flags {
pub size: SizeFlag,
pub sorting: Sorting,
pub total_size: TotalSize,
pub styles: Styles,
}
/// A struct to hold the style flags for the application.
#[derive(Clone, Debug, Default)]
pub struct Styles {
pub symlink_arrow: SymlinkArrow,
}
@ -93,9 +87,7 @@ impl Flags {
recursion: Recursion::configure_from(matches, config)?,
sorting: Sorting::configure_from(matches, config),
total_size: TotalSize::configure_from(matches, config),
styles: Styles {
symlink_arrow: SymlinkArrow::configure_from(matches, config),
},
symlink_arrow: SymlinkArrow::configure_from(matches, config),
})
}
}

View file

@ -23,7 +23,7 @@ impl Configurable<Self> for SymlinkArrow {
/// Otherwise this returns [None].
fn from_config(config: &Config) -> Option<Self> {
if let Some(yaml) = &config.yaml {
match &yaml["styling"]["symlink-arrow"] {
match &yaml["symlink-arrow"] {
Yaml::BadValue => None,
Yaml::String(value) => Some(SymlinkArrow(value.to_string())),
_ => {
@ -62,8 +62,7 @@ mod test {
use super::SymlinkArrow;
#[test]
fn test_symlink_arrow_from_config_utf8() {
let yaml_string = "styling:
symlink-arrow: ";
let yaml_string = "symlink-arrow: ↹";
let yaml = YamlLoader::load_from_str(yaml_string).unwrap()[0].clone();
assert_eq!(
Some(SymlinkArrow(String::from("\u{21B9}"))),
@ -73,8 +72,7 @@ mod test {
#[test]
fn test_symlink_arrow_from_config_type_error() {
let yaml_string = "styling:
symlink-arrow: false";
let yaml_string = "symlink-arrow: false";
let yaml = YamlLoader::load_from_str(yaml_string).unwrap()[0].clone();
assert_eq!(None, SymlinkArrow::from_config(&Config::with_yaml(yaml)));
}

View file

@ -1,5 +1,5 @@
use crate::color::{ColoredString, Colors, Elem};
use crate::flags::Styles;
use crate::flags::Flags;
use ansi_term::{ANSIString, ANSIStrings};
use std::fs::read_link;
use std::path::Path;
@ -52,7 +52,7 @@ impl SymLink {
}
}
pub fn render(&self, colors: &Colors, styles: &Styles) -> ColoredString {
pub fn render(&self, colors: &Colors, flag: &Flags) -> ColoredString {
if let Some(target_string) = self.symlink_string() {
let elem = if self.valid {
&Elem::SymLink
@ -61,7 +61,7 @@ impl SymLink {
};
let strings: &[ColoredString] = &[
ColoredString::from(format!(" {} ", styles.symlink_arrow)), // ⇒ \u{21d2}
ColoredString::from(format!(" {} ", flag.symlink_arrow)), // ⇒ \u{21d2}
colors.colorize(target_string, elem),
];
@ -75,24 +75,27 @@ impl SymLink {
#[cfg(test)]
mod tests {
use super::Styles;
use super::SymLink;
use crate::app;
use crate::color::{Colors, Theme};
use crate::flags::styling::SymlinkArrow;
use crate::config_file::Config;
use crate::flags::Flags;
use yaml_rust::YamlLoader;
#[test]
fn test_symlink_render_default_valid_target_nocolor() {
let link = SymLink {
target: Some("/target".to_string()),
valid: true,
};
let yaml_string = "---";
let yaml = YamlLoader::load_from_str(yaml_string).unwrap()[0].clone();
let argv = vec!["lsd"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
assert_eq!(
format!("{}", " ⇒ /target"),
link.render(
&Colors::new(Theme::NoColor),
&Styles {
symlink_arrow: SymlinkArrow::default()
}
&Flags::configure_from(&matches, &Config::with_yaml(yaml)).unwrap()
)
.to_string()
);
@ -104,13 +107,15 @@ mod tests {
target: Some("/target".to_string()),
valid: false,
};
let yaml_string = "---";
let yaml = YamlLoader::load_from_str(yaml_string).unwrap()[0].clone();
let argv = vec!["lsd"];
let matches = app::build().get_matches_from_safe(argv).unwrap();
assert_eq!(
format!("{}", " ⇒ /target"),
link.render(
&Colors::new(Theme::NoColor),
&Styles {
symlink_arrow: SymlinkArrow::default()
}
&Flags::configure_from(&matches, &Config::with_yaml(yaml)).unwrap()
)
.to_string()
);