Open fbonin opened 5 months ago
Hi @fbonin
That's actually by design.
Try to use tabled::settings::style::BorderSpanCorrection
afterwards.
Let me know if it helped.
Yes I've just noticed it's not stated in README.md
.
If you want to you can open a PR
Take care
Thank you !
Just a heads up, BorderSpanCorrection
doesn't work on all styles:
use tabled::{
settings::{
style::{BorderSpanCorrection, Style},
Modify, Span,
},
Table,
};
fn main() {
let data = vec![("09", "June", "2022"), ("10", "July", "2022")];
let mut table = Table::new(&data);
table
.with(Modify::new((0, 0)).with("date").with(Span::column(3)))
.with(BorderSpanCorrection);
println!("{}", table.to_string());
table.with(Style::modern());
println!("{}", table.to_string());
}
$ cargo run
+------------------+
| date |
+----+------+------+
| 09 | June | 2022 |
+----+------+------+
| 10 | July | 2022 |
+----+------+------+
┌────┬──────┬──────┐
│ date │
├────┼──────┼──────┤
│ 09 │ June │ 2022 │
├────┼──────┼──────┤
│ 10 │ July │ 2022 │
└────┴──────┴──────┘
Hi @mkatychev
Good observation,
The thing is that you change style after BorderSpanCorrection
make its changes.
So essentially you could call it one more time to fix it. Or if you would make them after applying the style, you'd get a different result.
Yesssssssssss, Surely this must be noted in documentation (ref #402)
You can help to update the doc yourself if you want to.
Let me know if that helps, and Take care.
use tabled::{
settings::{
style::{BorderSpanCorrection, Style},
Modify, Span,
},
Table,
};
fn main() {
let data = vec![("09", "June", "2022"), ("10", "July", "2022")];
let mut table = Table::new(data);
table
.with(Modify::new((0, 0)).with("date").with(Span::column(3)))
.with(Style::modern());
println!("{table}");
table.with(BorderSpanCorrection);
println!("{table}");
}
┌────┬──────┬──────┐
│ date │
├────┼──────┼──────┤
│ 09 │ June │ 2022 │
├────┼──────┼──────┤
│ 10 │ July │ 2022 │
└────┴──────┴──────┘
┌──────────────────┐
│ date │
├────┬──────┬──────┤
│ 09 │ June │ 2022 │
├────┼──────┼──────┤
│ 10 │ July │ 2022 │
└────┴──────┴──────┘
PS: Once again a good observation.
Note
Could be done with Panel
and Disable
.
use tabled::{
settings::{
object::Rows,
style::{BorderSpanCorrection, Style},
Disable, Panel,
},
Table,
};
fn main() {
let data = vec![("09", "June", "2022"), ("10", "July", "2022")];
let mut table = Table::new(data);
table
.with(Disable::row(Rows::first()))
.with(Panel::header("date"))
.with(Style::modern());
println!("{table}");
table.with(BorderSpanCorrection);
println!("{table}");
}
Or like this without Disable
and using Table::from_iter
.
use std::iter::FromIterator;
use tabled::{
settings::{
style::{BorderSpanCorrection, Style},
Panel,
},
Table,
};
fn main() {
let data = vec![["09", "June", "2022"], ["10", "July", "2022"]];
let mut table = Table::from_iter(data);
table.with(Panel::header("date")).with(Style::modern());
println!("{table}");
table.with(BorderSpanCorrection);
println!("{table}");
}
I can confirm the first approach worked flawlessly with 3 or more columns, thanks @zhiburt. Panel::corrected_header
would be valuable as a convenience method although it seems that one needs a &mut Table
to do these inside of Table::with
.
Using Span::column() with the Style::modern() causes virtual artifact on the intersection in the table
To reproduce :
Artifacts on the header at the intersection :
Expected :