Bump tabled dependency to 0.11 (#8922)

close? #8060

Quite a bit of refactoring took place.
I believe a few improvements to collapse/expand were made.

I've tried to track any performance regressions and seems like it is
fine.

I've noticed something different now with default configuration path or
something in this regard?
So I might missed something while testing because of this.

Requires some oversight.

---------

Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
Maxim Zhiburt
2023-04-26 21:56:10 +03:00
committed by GitHub
parent 07c9f681c7
commit 8d8b011702
26 changed files with 3041 additions and 3230 deletions

View File

@@ -1,13 +1,13 @@
use nu_ansi_term::{Color, Style};
use nu_color_config::TextStyle;
use nu_table::{Table, TableConfig, TableTheme};
use tabled::papergrid::records::{cell_info::CellInfo, tcell::TCell};
use nu_table::{NuTable, TableConfig, TableTheme};
use tabled::grid::records::vec_records::CellInfo;
fn main() {
let args: Vec<_> = std::env::args().collect();
let mut width = 0;
if args.len() > 1 {
// Width in terminal characters
width = args[1].parse::<usize>().expect("Need a width in columns");
}
@@ -16,31 +16,26 @@ fn main() {
width = 80;
}
// The mocked up table data
let (table_headers, row_data) = make_table_data();
// The table headers
let headers = vec_of_str_to_vec_of_styledstr(&table_headers, true);
let headers = to_cell_info_vec(&table_headers);
let rows = to_cell_info_vec(&row_data);
// The table rows
let rows = vec_of_str_to_vec_of_styledstr(&row_data, false);
// The table itself
let count_cols = std::cmp::max(rows.len(), headers.len());
let mut rows = vec![rows; 3];
rows.insert(0, headers);
let mut table = NuTable::from(rows);
table.set_data_style(TextStyle::basic_left());
table.set_header_style(TextStyle::basic_center().style(Style::new().on(Color::Blue)));
let theme = TableTheme::rounded();
let table_cfg = TableConfig::new(theme, true, false, false);
let table_cfg = TableConfig::new().theme(theme).with_header(true);
let table = Table::new(rows, (3, count_cols));
// Capture the table as a string
let output_table = table
.draw(table_cfg, width)
.unwrap_or_else(|| format!("Couldn't fit table into {width} columns!"));
// Draw the table
println!("{output_table}")
}
@@ -82,24 +77,11 @@ fn make_table_data() -> (Vec<&'static str>, Vec<&'static str>) {
(table_headers, row_data)
}
fn vec_of_str_to_vec_of_styledstr(
data: &[&str],
is_header: bool,
) -> Vec<TCell<CellInfo<'static>, TextStyle>> {
fn to_cell_info_vec(data: &[&str]) -> Vec<CellInfo<String>> {
let mut v = vec![];
for x in data {
if is_header {
v.push(Table::create_cell(
String::from(*x),
TextStyle::default_header(),
))
} else {
v.push(Table::create_cell(
String::from(*x),
TextStyle::basic_left(),
))
}
v.push(CellInfo::new(String::from(*x)));
}
v
}