Revert "Add an option to move header on borders" (#9908)

Reverts nushell/nushell#9796

This is just draft since we're seeing some issues with the latest fixes
to table drawing that just landed with #9796. We're hoping to get these
fixed, but if we're not able to fix them before the next release, we'll
need to revert (hence this PR, just in case we need it).
This commit is contained in:
JT
2023-08-04 07:52:12 +12:00
committed by GitHub
parent 572698bf3e
commit a98b3124c5
20 changed files with 747 additions and 762 deletions

View File

@ -1,16 +1,16 @@
#![allow(dead_code)]
use nu_table::{string_width, NuTable, NuTableConfig};
use nu_table::{string_width, NuTable, TableConfig};
use tabled::grid::records::vec_records::CellInfo;
pub struct TestCase {
cfg: NuTableConfig,
cfg: TableConfig,
termwidth: usize,
expected: Option<String>,
}
impl TestCase {
pub fn new(cfg: NuTableConfig, termwidth: usize, expected: Option<String>) -> Self {
pub fn new(cfg: TableConfig, termwidth: usize, expected: Option<String>) -> Self {
Self {
cfg,
termwidth,
@ -37,7 +37,7 @@ pub fn test_table<I: IntoIterator<Item = TestCase>>(data: Data, tests: I) {
}
}
pub fn create_table(data: Data, config: NuTableConfig, termwidth: usize) -> Option<String> {
pub fn create_table(data: Data, config: TableConfig, termwidth: usize) -> Option<String> {
let table = NuTable::from(data);
table.draw(config, termwidth)
}

View File

@ -1,7 +1,7 @@
mod common;
use nu_protocol::TrimStrategy;
use nu_table::{NuTable, NuTableConfig, TableTheme as theme};
use nu_table::{NuTable, TableConfig, TableTheme as theme};
use common::{create_row, test_table, TestCase};
use tabled::grid::records::vec_records::CellInfo;
@ -9,13 +9,11 @@ use tabled::grid::records::vec_records::CellInfo;
#[test]
fn data_and_header_has_different_size_doesnt_work() {
let table = NuTable::from(vec![create_row(5), create_row(5), create_row(5)]);
let cfg = NuTableConfig {
theme: theme::heavy(),
with_header: true,
..Default::default()
};
let table = table.draw(cfg.clone(), usize::MAX);
let table = table.draw(
TableConfig::new().theme(theme::heavy()).with_header(true),
usize::MAX,
);
assert_eq!(
table.as_deref(),
@ -31,7 +29,10 @@ fn data_and_header_has_different_size_doesnt_work() {
let table = NuTable::from(vec![create_row(5), create_row(5), create_row(5)]);
let table = table.draw(cfg, usize::MAX);
let table = table.draw(
TableConfig::new().theme(theme::heavy()).with_header(true),
usize::MAX,
);
assert_eq!(
table.as_deref(),
@ -48,7 +49,7 @@ fn data_and_header_has_different_size_doesnt_work() {
#[test]
fn termwidth_too_small() {
let test_loop = |config: NuTableConfig| {
let test_loop = |config: TableConfig| {
for i in 0..10 {
let table = NuTable::from(vec![create_row(5), create_row(5), create_row(5)]);
let table = table.draw(config.clone(), i);
@ -57,22 +58,29 @@ fn termwidth_too_small() {
}
};
let mut cfg = NuTableConfig {
theme: theme::heavy(),
with_header: true,
..Default::default()
};
let base_config = TableConfig::new().theme(theme::heavy()).with_header(true);
for case in [
TrimStrategy::truncate(None),
TrimStrategy::truncate(Some(String::from("**"))),
TrimStrategy::truncate(Some(String::from(""))),
TrimStrategy::wrap(false),
TrimStrategy::wrap(true),
] {
cfg.trim = case;
test_loop(cfg.clone());
}
let config = base_config.clone();
test_loop(config);
let config = base_config.clone().trim(TrimStrategy::truncate(None));
test_loop(config);
let config = base_config
.clone()
.trim(TrimStrategy::truncate(Some(String::from("**"))));
test_loop(config);
let config = base_config
.clone()
.trim(TrimStrategy::truncate(Some(String::from(""))));
test_loop(config);
let config = base_config.clone().trim(TrimStrategy::wrap(false));
test_loop(config);
let config = base_config.trim(TrimStrategy::wrap(true));
test_loop(config);
}
#[test]
@ -196,12 +204,11 @@ fn width_control_test_0() {
}
fn test_width(data: Vec<Vec<CellInfo<String>>>, tests: &[(usize, &str)]) {
let config = NuTableConfig {
theme: theme::heavy(),
trim: TrimStrategy::truncate(Some(String::from("..."))),
with_header: true,
..Default::default()
};
let trim = TrimStrategy::truncate(Some(String::from("...")));
let config = TableConfig::new()
.theme(theme::heavy())
.with_header(true)
.trim(trim);
let tests = tests.iter().map(|&(termwidth, expected)| {
TestCase::new(config.clone(), termwidth, Some(expected.to_owned()))
@ -211,13 +218,10 @@ fn test_width(data: Vec<Vec<CellInfo<String>>>, tests: &[(usize, &str)]) {
}
fn test_trim(tests: &[(usize, Option<&str>)], trim: TrimStrategy) {
let config = NuTableConfig {
theme: theme::heavy(),
with_header: true,
trim,
..Default::default()
};
let config = TableConfig::new()
.theme(theme::heavy())
.with_header(true)
.trim(trim);
let tests = tests.iter().map(|&(termwidth, expected)| {
TestCase::new(config.clone(), termwidth, expected.map(|s| s.to_string()))
});

View File

@ -2,18 +2,16 @@ mod common;
use common::{create_row, create_table};
use nu_table::{NuTableConfig, TableTheme as theme};
use nu_table::{TableConfig, TableTheme as theme};
#[test]
fn test_expand() {
let table = create_table(
vec![create_row(4); 3],
NuTableConfig {
theme: theme::rounded(),
with_header: true,
expand: true,
..Default::default()
},
TableConfig::new()
.theme(theme::rounded())
.with_header(true)
.expand(true),
50,
);

View File

@ -1,7 +1,7 @@
mod common;
use common::create_row as row;
use nu_table::{NuTable, NuTableConfig, TableTheme as theme};
use nu_table::{NuTable, TableConfig, TableTheme as theme};
use tabled::grid::records::vec_records::CellInfo;
#[test]
@ -476,11 +476,10 @@ fn test_with_love() {
}
fn create_table(data: Vec<Vec<CellInfo<String>>>, with_header: bool, theme: theme) -> String {
let config = NuTableConfig {
theme,
with_header,
..Default::default()
};
let mut config = TableConfig::new().theme(theme);
if with_header {
config = config.with_header(true);
}
let out = common::create_table(data, config, usize::MAX);
@ -492,11 +491,10 @@ fn create_table_with_size(
with_header: bool,
theme: theme,
) -> String {
let config = NuTableConfig {
theme,
with_header,
..Default::default()
};
let mut config = TableConfig::new().theme(theme);
if with_header {
config = config.with_header(true);
}
let table = NuTable::from(data);