From e145697b4e9af28d6c93259879b8d29731d9551f Mon Sep 17 00:00:00 2001 From: Abin Simon <abinsimon10@gmail.com> Date: Sat, 18 May 2019 19:19:29 +0530 Subject: [PATCH] add --no-symlink option --- src/app.rs | 8 +++++++- src/display.rs | 46 +++++++++++++++++++++++++++------------------- src/flags.rs | 8 +++++--- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/src/app.rs b/src/app.rs index f90bcb8..ac183aa 100644 --- a/src/app.rs +++ b/src/app.rs @@ -171,7 +171,7 @@ pub fn build() -> App<'static, 'static> { .multiple(true) .number_of_values(1) .require_delimiter(true) - .possible_values(&["permission", "user", "group", "size", "date", "name","namewithoutsymlink" ]) + .possible_values(&["permission", "user", "group", "size", "date", "name"]) .default_value("permission,user,group,size,date,name") .help("Specify the blocks that will be displayed and in what order"), ) @@ -180,4 +180,10 @@ pub fn build() -> App<'static, 'static> { .long("classic") .help("Enable classic mode (no colors or icons)"), ) + .arg( + Arg::with_name("no-symlink") + .long("no-symlink") + .multiple(true) + .help("Do not display symlink target"), + ) } diff --git a/src/display.rs b/src/display.rs index 1dacb23..b348dee 100644 --- a/src/display.rs +++ b/src/display.rs @@ -296,26 +296,34 @@ fn get_long_output( &flags, )), Block::Date => strings.push(meta.date.render(colors, padding_rules.date, &flags)), - Block::Name => strings.push(meta.name.render(colors, icons, Some(padding_rules.name))), - Block::NameWithSymlink => match meta.symlink.symlink_string() { - Some(_) => { - strings.push(meta.name.render(colors, icons, None)); - strings.push(meta.indicator.render(&flags)); - strings.push(meta.symlink.render( - colors, - Some(padding_rules.name_with_symlink - meta.name.name_string(icons).len()), - )); + Block::Name => { + if flags.no_symlink { + strings.push(meta.name.render(colors, icons, Some(padding_rules.name))); + } else { + match meta.symlink.symlink_string() { + Some(_) => { + strings.push(meta.name.render(colors, icons, None)); + strings.push(meta.indicator.render(&flags)); + strings.push(meta.symlink.render( + colors, + Some( + padding_rules.name_with_symlink + - meta.name.name_string(icons).len(), + ), + )); + } + None => { + strings.push(meta.name.render( + colors, + icons, + Some(padding_rules.name_with_symlink + 3), + )); + strings.push(meta.indicator.render(&flags)); + strings.push(meta.symlink.render(colors, None)); + } + } } - None => { - strings.push(meta.name.render( - colors, - icons, - Some(padding_rules.name_with_symlink + 3), - )); - strings.push(meta.indicator.render(&flags)); - strings.push(meta.symlink.render(colors, None)); - } - }, + } }; strings.push(ANSIString::from(" ")); // TODO do not add this space to the end } diff --git a/src/flags.rs b/src/flags.rs index 6d7de6c..4890127 100644 --- a/src/flags.rs +++ b/src/flags.rs @@ -16,6 +16,7 @@ pub struct Flags { pub icon_theme: IconTheme, pub recursion_depth: usize, pub blocks: Vec<Block>, + pub no_symlink: bool, } impl Flags { @@ -89,6 +90,7 @@ impl Flags { } None => usize::max_value(), }; + let no_symlink = matches.is_present("no-symlink"); Ok(Self { display, @@ -122,6 +124,7 @@ impl Flags { } else { DirOrderFlag::from(dir_order_inputs[dir_order_inputs.len() - 1]) }, + no_symlink, }) } } @@ -150,6 +153,7 @@ impl Default for Flags { Block::Date, Block::Name, ], + no_symlink: false, } } } @@ -163,7 +167,6 @@ pub enum Block { Size, Date, Name, - NameWithSymlink, } impl<'a> From<&'a str> for Block { fn from(block: &'a str) -> Self { @@ -174,8 +177,7 @@ impl<'a> From<&'a str> for Block { "group" => Block::Group, "size" => Block::Size, "date" => Block::Date, - "name" => Block::NameWithSymlink, - "namewithoutsymlink" => Block::Name, + "name" => Block::Name, _ => panic!("invalid \"time\" flag: {}", block), } }