fix all spacing issues

This commit is contained in:
Abin Simon 2019-06-17 12:12:03 +05:30 committed by Pierre Peltier
parent 7177c187da
commit f1275b0e60
2 changed files with 19 additions and 18 deletions

View file

@ -57,8 +57,8 @@ fn inner_display_one_line(
group: detect_group_length(&metas), group: detect_group_length(&metas),
size: detect_size_lengths(&metas, &flags), size: detect_size_lengths(&metas, &flags),
date: detect_date_length(&metas, &flags), date: detect_date_length(&metas, &flags),
name: detect_name_length(&metas, &icons), name: detect_name_length(&metas, &icons, &flags),
name_with_symlink: detect_name_with_symlink_length(&metas, &icons), name_with_symlink: detect_name_with_symlink_length(&metas, &icons, &flags),
}) })
} }
@ -190,8 +190,8 @@ fn inner_display_tree(
group: detect_group_length(&metas), group: detect_group_length(&metas),
size: detect_size_lengths(&metas, flags), size: detect_size_lengths(&metas, flags),
date: detect_date_length(&metas, flags), date: detect_date_length(&metas, flags),
name: detect_name_length(&metas, &icons), name: detect_name_length(&metas, &icons, &flags),
name_with_symlink: detect_name_with_symlink_length(&metas, &icons), name_with_symlink: detect_name_with_symlink_length(&metas, &icons, &flags),
}) })
} }
@ -301,10 +301,12 @@ fn get_long_output(
Block::Name => { Block::Name => {
if flags.no_symlink { if flags.no_symlink {
strings.push(meta.name.render(colors, icons)); strings.push(meta.name.render(colors, icons));
strings strings.push(meta.indicator.render(&flags));
.push(ANSIString::from(" ".to_string().repeat( strings.push(ANSIString::from(" ".to_string().repeat(
padding_rules.name - meta.name.name_string(icons).len(), padding_rules.name
))) - meta.indicator.len(&flags)
- meta.name.name_string(icons).len(),
)))
} else { } else {
match meta.symlink.symlink_string() { match meta.symlink.symlink_string() {
Some(s) => { Some(s) => {
@ -313,6 +315,7 @@ fn get_long_output(
strings.push(meta.symlink.render(colors)); strings.push(meta.symlink.render(colors));
strings.push(ANSIString::from(" ".to_string().repeat( strings.push(ANSIString::from(" ".to_string().repeat(
padding_rules.name_with_symlink padding_rules.name_with_symlink
- 3 // 3 = ( arrow + 2 spaces) for symlink;
- meta.name.name_string(icons).len() - meta.name.name_string(icons).len()
- meta.indicator.len(&flags) - meta.indicator.len(&flags)
- s.len(), - s.len(),
@ -323,7 +326,7 @@ fn get_long_output(
strings.push(meta.indicator.render(&flags)); strings.push(meta.indicator.render(&flags));
strings.push(meta.symlink.render(colors)); strings.push(meta.symlink.render(colors));
strings.push(ANSIString::from(" ".to_string().repeat( strings.push(ANSIString::from(" ".to_string().repeat(
padding_rules.name_with_symlink + 3 padding_rules.name_with_symlink
- meta.name.name_string(icons).len() - meta.name.name_string(icons).len()
- meta.indicator.len(&flags), - meta.indicator.len(&flags),
))) )))
@ -409,25 +412,26 @@ fn detect_size_lengths(metas: &[Meta], flags: &Flags) -> (usize, usize) {
(max_value_length, max_unit_size) (max_value_length, max_unit_size)
} }
fn detect_name_length(metas: &[Meta], icons: &Icons) -> usize { fn detect_name_length(metas: &[Meta], icons: &Icons, flags: &Flags) -> usize {
let mut max_value_length: usize = 0; let mut max_value_length: usize = 0;
for meta in metas { for meta in metas {
if meta.name.name_string(&icons).len() > max_value_length { let len = meta.name.name_string(&icons).len() + meta.indicator.len(&flags);
max_value_length = meta.name.name_string(&icons).len(); if len > max_value_length {
max_value_length = len;
} }
} }
max_value_length max_value_length
} }
fn detect_name_with_symlink_length(metas: &[Meta], icons: &Icons) -> usize { fn detect_name_with_symlink_length(metas: &[Meta], icons: &Icons, flags: &Flags) -> usize {
let mut max_value_length: usize = 0; let mut max_value_length: usize = 0;
for meta in metas { for meta in metas {
let mut len = meta.name.name_string(&icons).len(); let mut len = meta.name.name_string(&icons).len() + meta.indicator.len(&flags);
if let Some(syml) = meta.symlink.symlink_string() { if let Some(syml) = meta.symlink.symlink_string() {
len += syml.len(); len += syml.len() + 3 // 3 = ( arrow + 2 spaces) for symlink;
} }
if len > max_value_length { if len > max_value_length {
max_value_length = len; max_value_length = len;

View file

@ -23,7 +23,6 @@ pub fn by_meta(a: &Meta, b: &Meta, flags: &Flags) -> Ordering {
} }
fn by_size(a: &Meta, b: &Meta, flags: &Flags) -> Ordering { fn by_size(a: &Meta, b: &Meta, flags: &Flags) -> Ordering {
if flags.sort_order == SortOrder::Default { if flags.sort_order == SortOrder::Default {
b.size.get_bytes().cmp(&a.size.get_bytes()) b.size.get_bytes().cmp(&a.size.get_bytes())
} else { } else {
@ -31,8 +30,6 @@ fn by_size(a: &Meta, b: &Meta, flags: &Flags) -> Ordering {
} }
} }
fn by_name(a: &Meta, b: &Meta, flags: &Flags) -> Ordering { fn by_name(a: &Meta, b: &Meta, flags: &Flags) -> Ordering {
if flags.sort_order == SortOrder::Default { if flags.sort_order == SortOrder::Default {
a.name.cmp(&b.name) a.name.cmp(&b.name)