dont issue trailing whitespaces

This commit is contained in:
Abraham Toriz 2021-06-29 07:20:52 -05:00
parent 5d3b50d552
commit cfcc514fa3
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
1 changed files with 18 additions and 14 deletions

View File

@ -148,7 +148,7 @@ impl Formatter {
for [id, date, start, end, duration, note] in lines { for [id, date, start, end, duration, note] in lines {
let first_line = format!( let first_line = format!(
"{} {} {} {} {} ", "{} {} {} {} {}",
lpad(&id, 3.max(lengths[0])), lpad(&id, 3.max(lengths[0])),
rpad(&date, 18), rpad(&date, 18),
rpad(&start, 10), rpad(&start, 10),
@ -156,14 +156,18 @@ impl Formatter {
lpad(&duration, 8.max(lengths[4])), lpad(&duration, 8.max(lengths[4])),
); );
let space_left = term_width.saturating_sub(first_line.len()).max(40); let space_left = term_width.saturating_sub(first_line.len() + 1).max(40);
let note_lines = constrained_lines(&note, space_left); let note_lines = constrained_lines(&note, space_left);
for (i, note_line) in note_lines.into_iter().enumerate() { for (i, note_line) in note_lines.into_iter().enumerate() {
if i == 0 { if i == 0 {
writeln!(out, "{}{}", first_line, note_line)?; if note_line.len() != 0 {
writeln!(out, "{} {}", first_line, note_line)?;
} else {
writeln!(out, "{}", first_line)?;
}
} else { } else {
writeln!(out, "{}{}", " ".repeat(first_line.len()), note_line)?; writeln!(out, "{} {}", " ".repeat(first_line.len()), note_line)?;
} }
if note_line.len() > max_note_length { if note_line.len() > max_note_length {
@ -262,10 +266,10 @@ mod tests {
Day Start End Duration Notes Day Start End Duration Notes
Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1 Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1
16:00:00 - 18:00:00 2:00:00 entry 2 16:00:00 - 18:00:00 2:00:00 entry 2
4:00:00 4:00:00
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3 Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3
18:00:00 - 2:00:00 entry 4 18:00:00 - 2:00:00 entry 4
4:00:00 4:00:00
--------------------------------------------------------- ---------------------------------------------------------
Total 8:00:00 Total 8:00:00
")); "));
@ -287,7 +291,7 @@ mod tests {
assert_eq!(PrettyString(&String::from_utf8_lossy(&output)), PrettyString("Timesheet: default assert_eq!(PrettyString(&String::from_utf8_lossy(&output)), PrettyString("Timesheet: default
Day Start End Duration Notes Day Start End Duration Notes
Fri Oct 03, 2008 12:00:00 - 14:00:00 1:59:59 entry 1 Fri Oct 03, 2008 12:00:00 - 14:00:00 1:59:59 entry 1
1:59:59 1:59:59
--------------------------------------------------------- ---------------------------------------------------------
Total 1:59:59 Total 1:59:59
")); "));
@ -310,9 +314,9 @@ mod tests {
assert_eq!(PrettyString(&String::from_utf8_lossy(&output)), PrettyString("Timesheet: default assert_eq!(PrettyString(&String::from_utf8_lossy(&output)), PrettyString("Timesheet: default
Day Start End Duration Notes Day Start End Duration Notes
Wed Oct 01, 2008 12:00:00 - 14:00:00+2d 50:00:00 entry 1 Wed Oct 01, 2008 12:00:00 - 14:00:00+2d 50:00:00 entry 1
50:00:00 50:00:00
Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 2 Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 2
2:00:00 2:00:00
---------------------------------------------------------- ----------------------------------------------------------
Total 52:00:00 Total 52:00:00
")); "));
@ -338,10 +342,10 @@ mod tests {
ID Day Start End Duration Notes ID Day Start End Duration Notes
1 Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1 1 Fri Oct 03, 2008 12:00:00 - 14:00:00 2:00:00 entry 1
2 16:00:00 - 18:00:00 2:00:00 entry 2 2 16:00:00 - 18:00:00 2:00:00 entry 2
4:00:00 4:00:00
3 Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3 3 Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 entry 3
4 18:00:00 - 2:00:00 entry 4 4 18:00:00 - 2:00:00 entry 4
4:00:00 4:00:00
--------------------------------------------------------- ---------------------------------------------------------
Total 8:00:00 Total 8:00:00
")); "));
@ -376,7 +380,7 @@ mod tests {
forking the rubygem and seeing if we can work forking the rubygem and seeing if we can work
in our own changes, however hard that might in our own changes, however hard that might
be. be.
2:00:00 2:00:00
----------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------
Total 2:00:00 Total 2:00:00
")); "));
@ -411,7 +415,7 @@ mod tests {
forking the rubygem and seeing if we can forking the rubygem and seeing if we can
work in our own changes, however hard that work in our own changes, however hard that
might be. might be.
2:00:00 2:00:00
---------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------
Total 2:00:00 Total 2:00:00
")); "));
@ -440,7 +444,7 @@ mod tests {
Day Start End Duration Notes Day Start End Duration Notes
Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 first line Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 first line
and a second line and a second line
2:00:00 2:00:00
------------------------------------------------------------------- -------------------------------------------------------------------
Total 2:00:00 Total 2:00:00
")); "));