add --no-symlink option

This commit is contained in:
Abin Simon 2019-05-18 19:19:29 +05:30 committed by Pierre Peltier
parent 4767ef8c11
commit e145697b4e
3 changed files with 39 additions and 23 deletions

View file

@ -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"),
)
}

View file

@ -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
}

View file

@ -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),
}
}