dont actually print spaces if requested

This commit is contained in:
Abraham Toriz 2021-07-16 09:33:45 -05:00
parent 1b57a0b297
commit da124869ca
No known key found for this signature in database
GPG Key ID: D5B4A746DB5DD42A
1 changed files with 34 additions and 1 deletions

View File

@ -32,6 +32,14 @@ pub struct Col {
}
impl Col {
pub fn new() -> Col {
Col {
min_width: 0,
align: Align::Left,
max_width: None,
}
}
pub fn min_width(size: usize) -> Col {
Col {
min_width: size,
@ -125,7 +133,11 @@ impl Tabulate {
self.data.into_iter().map(|row| match row {
DataOrSep::Sep(c) => {
c.to_string().repeat(widths.iter().sum::<usize>() + widths.len() -1) + "\n"
if c == ' ' {
"\n".into()
} else {
c.to_string().repeat(widths.iter().sum::<usize>() + widths.len() -1) + "\n"
}
},
DataOrSep::Data(d) => {
d.into_iter().zip(widths.iter()).zip(cols.iter()).map(|((d, &w), &c)| {
@ -339,6 +351,27 @@ Sun Oct 05, 2008 16:00:00 - 18:00:00 2:00:00 quiúbole
2:00:00
----------------------------------------------------------
Total 2:00:00
"));
}
#[test]
fn tabulate_a_blank_row() {
let mut tabs = Tabulate::with_columns(vec![
Col::new()
]);
tabs.feed(vec!["Hola".into()]);
tabs.separator(' ');
tabs.feed(vec!["adiós".into()]);
tabs.separator('-');
tabs.feed(vec!["ta güeno".into()]);
assert_eq!(PrettyString(&tabs.print()), PrettyString("\
Hola
adiós
--------
ta güeno
"));
}
}