summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierre Peltier <pierre.peltier@adevinta.com>2019-10-29 14:23:36 +0100
committerAbin Simon <abinsimon10@gmail.com>2019-12-06 11:35:03 +0530
commit6064fc3b65e2b44b96c89f28e9f679682bec7bee (patch)
tree881bf55a87797a2304509d1d15de40b3ef2e7ee4
parente4d7b7de964f7a12e7f1f5f88f14d06763fc359f (diff)
Handle the no-symlink flag
-rw-r--r--src/display.rs33
-rw-r--r--src/flags.rs22
2 files changed, 23 insertions, 32 deletions
diff --git a/src/display.rs b/src/display.rs
index db232fa..7db99df 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -242,23 +242,22 @@ fn get_output<'a>(
Block::SizeUnit => strings.push(meta.size.render_unit(colors, flags)),
Block::Date => strings.push(meta.date.render(colors, &flags)),
Block::Name => {
- let s: &[ColoredString] = &[
- meta.name.render(colors, icons),
- meta.indicator.render(&flags),
- ];
-
- let res = ANSIStrings(s).to_string();
- strings.push(ColoredString::from(res));
- }
- Block::NameWithSymlink => {
- let s2: &[ColoredString] = &[
- meta.name.render(colors, icons),
- meta.indicator.render(&flags),
- meta.symlink.render(colors),
- ];
-
- let res = ANSIStrings(s2).to_string();
- strings.push(ColoredString::from(res));
+ let s: String = if flags.no_symlink {
+ ANSIStrings(&[
+ meta.name.render(colors, icons),
+ meta.indicator.render(&flags),
+ ])
+ .to_string()
+ } else {
+ ANSIStrings(&[
+ meta.name.render(colors, icons),
+ meta.indicator.render(&flags),
+ meta.symlink.render(colors),
+ ])
+ .to_string()
+ };
+
+ strings.push(ColoredString::from(s));
}
};
}
diff --git a/src/flags.rs b/src/flags.rs
index 56a2739..b44b240 100644
--- a/src/flags.rs
+++ b/src/flags.rs
@@ -18,6 +18,7 @@ pub struct Flags {
pub icon_theme: IconTheme,
pub recursion_depth: usize,
pub blocks: Vec<Block>,
+ pub no_symlink: bool,
pub total_size: bool,
pub ignore_globs: GlobSet,
}
@@ -94,7 +95,7 @@ impl Flags {
None => usize::max_value(),
};
- let mut blocks: Vec<Block> = if !blocks_inputs.is_empty() {
+ let blocks: Vec<Block> = if !blocks_inputs.is_empty() {
blocks_inputs.into_iter().map(|b| Block::from(b)).collect()
} else if matches.is_present("long") {
vec![
@@ -103,20 +104,12 @@ impl Flags {
Block::Group,
Block::Size,
Block::Date,
- Block::NameWithSymlink,
+ Block::Name,
]
} else {
- vec![Block::NameWithSymlink]
+ vec![Block::Name]
};
- if matches.is_present("no-symlink") {
- if let Ok(idx) = blocks.binary_search(&Block::NameWithSymlink) {
- blocks[idx] = Block::Name;
- }
- }
-
- let total_size = matches.is_present("total-size");
-
let mut ignore_globs_builder = GlobSetBuilder::new();
for pattern in ignore_globs_inputs {
let glob = match Glob::new(pattern) {
@@ -175,7 +168,8 @@ impl Flags {
} else {
DirOrderFlag::from(dir_order_inputs[dir_order_inputs.len() - 1])
},
- total_size,
+ no_symlink: matches.is_present("no-symlink"),
+ total_size: matches.is_present("total-size"),
})
}
}
@@ -198,6 +192,7 @@ impl Default for Flags {
icon: WhenFlag::Auto,
icon_theme: IconTheme::Fancy,
blocks: vec![],
+ no_symlink: false,
total_size: false,
ignore_globs: GlobSet::empty(),
}
@@ -206,7 +201,6 @@ impl Default for Flags {
#[derive(Clone, Debug, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Block {
- // FileType,
Permission,
User,
Group,
@@ -215,7 +209,6 @@ pub enum Block {
SizeUnit,
Date,
Name,
- NameWithSymlink,
}
impl<'a> From<&'a str> for Block {
fn from(block: &'a str) -> Self {
@@ -229,7 +222,6 @@ impl<'a> From<&'a str> for Block {
"size_unit" => Block::SizeUnit,
"date" => Block::Date,
"name" => Block::Name,
- "name-with-symlink" => Block::NameWithSymlink,
_ => panic!("invalid \"time\" flag: {}", block),
}
}