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 {
|
fn get_short_output(meta: &Meta, colors: &Colors, icons: &Icons, flags: &Flags) -> String {
|
||||||
let strings: &[ANSIString] = &[
|
let strings: &[ANSIString] = &[
|
||||||
meta.name.render(colors, icons, None),
|
meta.name.render(colors, icons),
|
||||||
meta.indicator.render(&flags),
|
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::Date => strings.push(meta.date.render(colors, padding_rules.date, &flags)),
|
||||||
Block::Name => {
|
Block::Name => {
|
||||||
if flags.no_symlink {
|
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 {
|
} else {
|
||||||
match meta.symlink.symlink_string() {
|
match meta.symlink.symlink_string() {
|
||||||
Some(_) => {
|
Some(s) => {
|
||||||
strings.push(meta.name.render(colors, icons, None));
|
strings.push(meta.name.render(colors, icons));
|
||||||
strings.push(meta.indicator.render(&flags));
|
strings.push(meta.indicator.render(&flags));
|
||||||
strings.push(meta.symlink.render(
|
strings.push(meta.symlink.render(colors));
|
||||||
colors,
|
strings.push(ANSIString::from(" ".to_string().repeat(
|
||||||
Some(
|
padding_rules.name_with_symlink
|
||||||
padding_rules.name_with_symlink
|
- meta.name.name_string(icons).len()
|
||||||
- meta.name.name_string(icons).len(),
|
- s.len(),
|
||||||
),
|
)))
|
||||||
));
|
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
strings.push(meta.name.render(
|
strings.push(meta.name.render(colors, icons));
|
||||||
colors,
|
|
||||||
icons,
|
|
||||||
Some(padding_rules.name_with_symlink + 3),
|
|
||||||
));
|
|
||||||
strings.push(meta.indicator.render(&flags));
|
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(
|
let output = name.render(
|
||||||
&Colors::new(color::Theme::NoColor),
|
&Colors::new(color::Theme::NoColor),
|
||||||
&Icons::new(icon::Theme::NoIcon),
|
&Icons::new(icon::Theme::NoIcon),
|
||||||
None,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(get_visible_width(&output), *l);
|
assert_eq!(get_visible_width(&output), *l);
|
||||||
|
@ -492,7 +494,6 @@ mod tests {
|
||||||
.render(
|
.render(
|
||||||
&Colors::new(color::Theme::NoColor),
|
&Colors::new(color::Theme::NoColor),
|
||||||
&Icons::new(icon::Theme::Fancy),
|
&Icons::new(icon::Theme::Fancy),
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
|
@ -524,7 +525,6 @@ mod tests {
|
||||||
.render(
|
.render(
|
||||||
&Colors::new(color::Theme::NoLscolors),
|
&Colors::new(color::Theme::NoLscolors),
|
||||||
&Icons::new(icon::Theme::NoIcon),
|
&Icons::new(icon::Theme::NoIcon),
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
|
@ -560,7 +560,6 @@ mod tests {
|
||||||
.render(
|
.render(
|
||||||
&Colors::new(color::Theme::NoColor),
|
&Colors::new(color::Theme::NoColor),
|
||||||
&Icons::new(icon::Theme::NoIcon),
|
&Icons::new(icon::Theme::NoIcon),
|
||||||
None,
|
|
||||||
)
|
)
|
||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
|
|
|
@ -47,13 +47,8 @@ impl Name {
|
||||||
content
|
content
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render(&self, colors: &Colors, icons: &Icons, name_alignment: Option<usize>) -> ColoredString {
|
pub fn render(&self, colors: &Colors, icons: &Icons) -> ColoredString {
|
||||||
let mut content = self.name_string(&icons);
|
let content = self.name_string(&icons);
|
||||||
if let Some(na) = name_alignment {
|
|
||||||
for _ in 0..(na - content.len()) {
|
|
||||||
content.push(' ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let elem = match self.file_type {
|
let elem = match self.file_type {
|
||||||
FileType::CharDevice => Elem::CharDevice,
|
FileType::CharDevice => Elem::CharDevice,
|
||||||
|
@ -136,7 +131,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Colour::Fixed(184).paint(" file.txt"),
|
Colour::Fixed(184).paint(" file.txt"),
|
||||||
name.render(&colors, &icons, None)
|
name.render(&colors, &icons)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,7 +149,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Colour::Fixed(33).paint(" directory"),
|
Colour::Fixed(33).paint(" directory"),
|
||||||
meta.name.render(&colors, &icons, None)
|
meta.name.render(&colors, &icons)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,7 +176,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Colour::Fixed(44).paint(" target.tmp"),
|
Colour::Fixed(44).paint(" target.tmp"),
|
||||||
name.render(&colors, &icons, None)
|
name.render(&colors, &icons)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -207,7 +202,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
Colour::Fixed(184).paint(" pipe.tmp"),
|
Colour::Fixed(184).paint(" pipe.tmp"),
|
||||||
name.render(&colors, &icons, None)
|
name.render(&colors, &icons)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,7 +221,7 @@ mod test {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
"file.txt",
|
"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 {
|
pub fn render(&self, colors: &Colors) -> ColoredString {
|
||||||
if let Some(mut target_string) = self.symlink_string() {
|
if let Some(target_string) = self.symlink_string() {
|
||||||
if let Some(sa) = symlink_alignment {
|
|
||||||
for _ in 0..(sa - target_string.len()) {
|
|
||||||
target_string.push(' ');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let elem = if self.valid {
|
let elem = if self.valid {
|
||||||
&Elem::SymLink
|
&Elem::SymLink
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue