mirror of
https://github.com/lsd-rs/lsd.git
synced 2026-02-16 20:24:47 +02:00
Handle the no-symlink flag
This commit is contained in:
committed by
Abin Simon
parent
e4d7b7de96
commit
6064fc3b65
@@ -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 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()
|
||||
};
|
||||
|
||||
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));
|
||||
strings.push(ColoredString::from(s));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
22
src/flags.rs
22
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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user