mirror of
https://github.com/lsd-rs/lsd
synced 2024-12-13 21:52:37 +00:00
fix padding of name and symlink
Will fix the issue where even the padding would have the background color.
This commit is contained in:
parent
e145697b4e
commit
119ddb3aa4
3 changed files with 29 additions and 41 deletions
|
@ -266,7 +266,7 @@ fn display_folder_path(meta: &Meta) -> String {
|
|||
|
||||
fn get_short_output(meta: &Meta, colors: &Colors, icons: &Icons, flags: &Flags) -> String {
|
||||
let strings: &[ANSIString] = &[
|
||||
meta.name.render(colors, icons, None),
|
||||
meta.name.render(colors, icons),
|
||||
meta.indicator.render(&flags),
|
||||
];
|
||||
|
||||
|
@ -298,28 +298,31 @@ fn get_long_output(
|
|||
Block::Date => strings.push(meta.date.render(colors, padding_rules.date, &flags)),
|
||||
Block::Name => {
|
||||
if flags.no_symlink {
|
||||
strings.push(meta.name.render(colors, icons, Some(padding_rules.name)));
|
||||
strings.push(meta.name.render(colors, icons));
|
||||
strings
|
||||
.push(ANSIString::from(" ".to_string().repeat(
|
||||
padding_rules.name - meta.name.name_string(icons).len(),
|
||||
)))
|
||||
} else {
|
||||
match meta.symlink.symlink_string() {
|
||||
Some(_) => {
|
||||
strings.push(meta.name.render(colors, icons, None));
|
||||
Some(s) => {
|
||||
strings.push(meta.name.render(colors, icons));
|
||||
strings.push(meta.indicator.render(&flags));
|
||||
strings.push(meta.symlink.render(
|
||||
colors,
|
||||
Some(
|
||||
padding_rules.name_with_symlink
|
||||
- meta.name.name_string(icons).len(),
|
||||
),
|
||||
));
|
||||
strings.push(meta.symlink.render(colors));
|
||||
strings.push(ANSIString::from(" ".to_string().repeat(
|
||||
padding_rules.name_with_symlink
|
||||
- meta.name.name_string(icons).len()
|
||||
- s.len(),
|
||||
)))
|
||||
}
|
||||
None => {
|
||||
strings.push(meta.name.render(
|
||||
colors,
|
||||
icons,
|
||||
Some(padding_rules.name_with_symlink + 3),
|
||||
));
|
||||
strings.push(meta.name.render(colors, icons));
|
||||
strings.push(meta.indicator.render(&flags));
|
||||
strings.push(meta.symlink.render(colors, None));
|
||||
strings.push(meta.symlink.render(colors));
|
||||
strings.push(ANSIString::from(" ".to_string().repeat(
|
||||
padding_rules.name_with_symlink + 3
|
||||
- meta.name.name_string(icons).len(),
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -460,7 +463,6 @@ mod tests {
|
|||
let output = name.render(
|
||||
&Colors::new(color::Theme::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon),
|
||||
None,
|
||||
);
|
||||
|
||||
assert_eq!(get_visible_width(&output), *l);
|
||||
|
@ -492,7 +494,6 @@ mod tests {
|
|||
.render(
|
||||
&Colors::new(color::Theme::NoColor),
|
||||
&Icons::new(icon::Theme::Fancy),
|
||||
None,
|
||||
)
|
||||
.to_string();
|
||||
|
||||
|
@ -524,7 +525,6 @@ mod tests {
|
|||
.render(
|
||||
&Colors::new(color::Theme::NoLscolors),
|
||||
&Icons::new(icon::Theme::NoIcon),
|
||||
None,
|
||||
)
|
||||
.to_string();
|
||||
|
||||
|
@ -560,7 +560,6 @@ mod tests {
|
|||
.render(
|
||||
&Colors::new(color::Theme::NoColor),
|
||||
&Icons::new(icon::Theme::NoIcon),
|
||||
None,
|
||||
)
|
||||
.to_string();
|
||||
|
||||
|
|
|
@ -47,13 +47,8 @@ impl Name {
|
|||
content
|
||||
}
|
||||
|
||||
pub fn render(&self, colors: &Colors, icons: &Icons, name_alignment: Option<usize>) -> ColoredString {
|
||||
let mut content = self.name_string(&icons);
|
||||
if let Some(na) = name_alignment {
|
||||
for _ in 0..(na - content.len()) {
|
||||
content.push(' ');
|
||||
}
|
||||
}
|
||||
pub fn render(&self, colors: &Colors, icons: &Icons) -> ColoredString {
|
||||
let content = self.name_string(&icons);
|
||||
|
||||
let elem = match self.file_type {
|
||||
FileType::CharDevice => Elem::CharDevice,
|
||||
|
@ -136,7 +131,7 @@ mod test {
|
|||
|
||||
assert_eq!(
|
||||
Colour::Fixed(184).paint(" file.txt"),
|
||||
name.render(&colors, &icons, None)
|
||||
name.render(&colors, &icons)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -154,7 +149,7 @@ mod test {
|
|||
|
||||
assert_eq!(
|
||||
Colour::Fixed(33).paint(" directory"),
|
||||
meta.name.render(&colors, &icons, None)
|
||||
meta.name.render(&colors, &icons)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -181,7 +176,7 @@ mod test {
|
|||
|
||||
assert_eq!(
|
||||
Colour::Fixed(44).paint(" target.tmp"),
|
||||
name.render(&colors, &icons, None)
|
||||
name.render(&colors, &icons)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -207,7 +202,7 @@ mod test {
|
|||
|
||||
assert_eq!(
|
||||
Colour::Fixed(184).paint(" pipe.tmp"),
|
||||
name.render(&colors, &icons, None)
|
||||
name.render(&colors, &icons)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -226,7 +221,7 @@ mod test {
|
|||
|
||||
assert_eq!(
|
||||
"file.txt",
|
||||
meta.name.render(&colors, &icons, None).to_string().as_str()
|
||||
meta.name.render(&colors, &icons).to_string().as_str()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,14 +51,8 @@ impl SymLink {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, colors: &Colors, symlink_alignment: Option<usize>) -> ColoredString {
|
||||
if let Some(mut target_string) = self.symlink_string() {
|
||||
if let Some(sa) = symlink_alignment {
|
||||
for _ in 0..(sa - target_string.len()) {
|
||||
target_string.push(' ');
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render(&self, colors: &Colors) -> ColoredString {
|
||||
if let Some(target_string) = self.symlink_string() {
|
||||
let elem = if self.valid {
|
||||
&Elem::SymLink
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue