feat: preserve leading_spaces

This commit is contained in:
electria 2026-09-30 15:18:15 -07:00
commit 9bacccfb71
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -22,6 +22,12 @@ fn main() {
}
pub fn parse_and_calc_humanreadable(mut input: String) -> String {
// no need to remove the characters here,
// as we ignore the them in all other logic already
let should_add_back_alignment = input.contains('&');
let should_add_back_backslash = input.contains('\\');
let leading_spaces = input.chars().take_while(|c| *c == ' ').count();
let should_add_back_equals = input
.find('=')
.inspect(|i| {
@ -29,15 +35,12 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String {
})
.is_some();
// no need to remove the characters here,
// as we ignore the them in all other logic already
let should_add_back_alignment = input.contains('&');
let should_add_back_backslash = input.contains('\\');
let result = parse_and_calc(&input);
let significant_digits = get_significant_digits(&result);
format!(
"{0}{result:.1$}{2}",
"{:leading_spaces$}{}{result:.significant_digits$}{}",
' ',
if should_add_back_equals && should_add_back_alignment {
"& = "
} else if should_add_back_equals {
@ -47,7 +50,6 @@ pub fn parse_and_calc_humanreadable(mut input: String) -> String {
} else {
""
},
get_significant_digits(&result),
if should_add_back_backslash { " \\" } else { "" }
)
}