nu-table/ table --collapse style fix (#8041)
close #8033 So as I said they suppose to be there; I've basically added a change of style if --collapse is used. PS: I guess it's worth to add tests so hold on if you'll plan to merge it. --------- Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
parent
1fd1a3a456
commit
daeb3e5187
|
@ -1,6 +1,6 @@
|
||||||
use nu_test_support::fs::Stub::FileWithContent;
|
use nu_test_support::fs::Stub::FileWithContent;
|
||||||
use nu_test_support::playground::Playground;
|
use nu_test_support::playground::Playground;
|
||||||
use nu_test_support::{nu, pipeline};
|
use nu_test_support::{nu, nu_repl_code, pipeline};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn table_0() {
|
fn table_0() {
|
||||||
|
@ -21,7 +21,213 @@ fn table_collapse_0() {
|
||||||
let actual = nu!(r#"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"#);
|
let actual = nu!(r#"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"#);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
actual.out,
|
actual.out,
|
||||||
"╭───┬───┬───╮│ a │ b │ c │ ─── ─── ─── │ 1 │ 2 │ 3 │ ─── ─── ─── │ 4 │ 5 │ 1 ││ │ ─── │ │ │ 2 ││ │ ─── │ │ │ 3 │╰───┴───┴───╯"
|
"╭───┬───┬───╮\
|
||||||
|
│ a │ b │ c │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 1 │ 2 │ 3 │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 4 │ 5 │ 1 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 2 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 3 │\
|
||||||
|
╰───┴───┴───╯"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_basic() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: basic };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
"+---+---+---+\
|
||||||
|
| a | b | c |\
|
||||||
|
+---+---+---+\
|
||||||
|
| 1 | 2 | 3 |\
|
||||||
|
+---+---+---+\
|
||||||
|
| 4 | 5 | 1 |\
|
||||||
|
| | +---+\
|
||||||
|
| | | 2 |\
|
||||||
|
| | +---+\
|
||||||
|
| | | 3 |\
|
||||||
|
+---+---+---+"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_heavy() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: heavy };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
"┏━━━┳━━━┳━━━┓\
|
||||||
|
┃ a ┃ b ┃ c ┃\
|
||||||
|
┣━━━╋━━━╋━━━┫\
|
||||||
|
┃ 1 ┃ 2 ┃ 3 ┃\
|
||||||
|
┣━━━╋━━━╋━━━┫\
|
||||||
|
┃ 4 ┃ 5 ┃ 1 ┃\
|
||||||
|
┃ ┃ ┣━━━┫\
|
||||||
|
┃ ┃ ┃ 2 ┃\
|
||||||
|
┃ ┃ ┣━━━┫\
|
||||||
|
┃ ┃ ┃ 3 ┃\
|
||||||
|
┗━━━┻━━━┻━━━┛"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_compact() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: compact };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
"┌───┬───┬───┐\
|
||||||
|
│ a │ b │ c │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 1 │ 2 │ 3 │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 4 │ 5 │ 1 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 2 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 3 │\
|
||||||
|
└───┴───┴───┘"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_compact_double() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: compact_double };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
"╔═══╦═══╦═══╗\
|
||||||
|
║ a ║ b ║ c ║\
|
||||||
|
╠═══╬═══╬═══╣\
|
||||||
|
║ 1 ║ 2 ║ 3 ║\
|
||||||
|
╠═══╬═══╬═══╣\
|
||||||
|
║ 4 ║ 5 ║ 1 ║\
|
||||||
|
║ ║ ╠═══╣\
|
||||||
|
║ ║ ║ 2 ║\
|
||||||
|
║ ║ ╠═══╣\
|
||||||
|
║ ║ ║ 3 ║\
|
||||||
|
╚═══╩═══╩═══╝"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_compact_light() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: light };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
"┌───┬───┬───┐\
|
||||||
|
│ a │ b │ c │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 1 │ 2 │ 3 │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 4 │ 5 │ 1 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 2 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 3 │\
|
||||||
|
└───┴───┴───┘"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_none() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: none };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
concat!(
|
||||||
|
" a b c ",
|
||||||
|
" 1 2 3 ",
|
||||||
|
" 4 5 1 ",
|
||||||
|
" 2 ",
|
||||||
|
" 3 ",
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_compact_reinforced() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: reinforced };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
"┏───┬───┬───┓\
|
||||||
|
│ a │ b │ c │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 1 │ 2 │ 3 │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 4 │ 5 │ 1 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 2 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 3 │\
|
||||||
|
┗───┴───┴───┛"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_compact_thin() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: thin };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
"┌───┬───┬───┐\
|
||||||
|
│ a │ b │ c │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 1 │ 2 │ 3 │\
|
||||||
|
├───┼───┼───┤\
|
||||||
|
│ 4 │ 5 │ 1 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 2 │\
|
||||||
|
│ │ ├───┤\
|
||||||
|
│ │ │ 3 │\
|
||||||
|
└───┴───┴───┘"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn table_collapse_hearts() {
|
||||||
|
let actual = nu!(nu_repl_code(&[
|
||||||
|
"let-env config = { table_mode: with_love };",
|
||||||
|
"[[a b, c]; [1 2 3] [4 5 [1 2 3]]] | table --collapse"
|
||||||
|
]));
|
||||||
|
assert_eq!(
|
||||||
|
actual.out,
|
||||||
|
concat!(
|
||||||
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
||||||
|
"❤ a ❤ b ❤ c ❤",
|
||||||
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
||||||
|
"❤ 1 ❤ 2 ❤ 3 ❤",
|
||||||
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
||||||
|
"❤ 4 ❤ 5 ❤ 1 ❤",
|
||||||
|
"❤ ❤ ❤❤❤❤❤",
|
||||||
|
"❤ ❤ ❤ 2 ❤",
|
||||||
|
"❤ ❤ ❤❤❤❤❤",
|
||||||
|
"❤ ❤ ❤ 3 ❤",
|
||||||
|
"❤❤❤❤❤❤❤❤❤❤❤❤❤",
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ fn load_theme<R>(table: &mut tabled::Table<R>, style_computer: &StyleComputer, t
|
||||||
where
|
where
|
||||||
R: Records,
|
R: Records,
|
||||||
{
|
{
|
||||||
let mut theme = theme.theme.clone();
|
let mut theme = theme.into_full().unwrap_or_else(|| theme.theme.clone());
|
||||||
theme.set_horizontals(HashMap::default());
|
theme.set_horizontals(HashMap::default());
|
||||||
|
|
||||||
table.with(theme);
|
table.with(theme);
|
||||||
|
|
|
@ -7,12 +7,14 @@ use tabled::{
|
||||||
pub struct TableTheme {
|
pub struct TableTheme {
|
||||||
pub(crate) theme: RawStyle,
|
pub(crate) theme: RawStyle,
|
||||||
has_inner: bool,
|
has_inner: bool,
|
||||||
|
full_theme: Option<RawStyle>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableTheme {
|
impl TableTheme {
|
||||||
pub fn basic() -> TableTheme {
|
pub fn basic() -> TableTheme {
|
||||||
Self {
|
Self {
|
||||||
theme: Style::ascii().into(),
|
theme: Style::ascii().into(),
|
||||||
|
full_theme: None,
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +22,7 @@ impl TableTheme {
|
||||||
pub fn thin() -> TableTheme {
|
pub fn thin() -> TableTheme {
|
||||||
Self {
|
Self {
|
||||||
theme: Style::modern().into(),
|
theme: Style::modern().into(),
|
||||||
|
full_theme: None,
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +35,7 @@ impl TableTheme {
|
||||||
Line::new(Some('─'), Some('─'), None, None),
|
Line::new(Some('─'), Some('─'), None, None),
|
||||||
)])
|
)])
|
||||||
.into(),
|
.into(),
|
||||||
|
full_theme: Some(Style::modern().into()),
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,6 +50,7 @@ impl TableTheme {
|
||||||
.left(None)
|
.left(None)
|
||||||
.right(None)])
|
.right(None)])
|
||||||
.into(),
|
.into(),
|
||||||
|
full_theme: Some(Style::modern().into()),
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +66,25 @@ impl TableTheme {
|
||||||
Line::new(Some('❤'), Some('❤'), None, None),
|
Line::new(Some('❤'), Some('❤'), None, None),
|
||||||
)])
|
)])
|
||||||
.into(),
|
.into(),
|
||||||
|
full_theme: Some(
|
||||||
|
Style::empty()
|
||||||
|
.top('❤')
|
||||||
|
.bottom('❤')
|
||||||
|
.vertical('❤')
|
||||||
|
.horizontal('❤')
|
||||||
|
.left('❤')
|
||||||
|
.right('❤')
|
||||||
|
.top_intersection('❤')
|
||||||
|
.top_left_corner('❤')
|
||||||
|
.top_right_corner('❤')
|
||||||
|
.bottom_intersection('❤')
|
||||||
|
.bottom_left_corner('❤')
|
||||||
|
.bottom_right_corner('❤')
|
||||||
|
.right_intersection('❤')
|
||||||
|
.left_intersection('❤')
|
||||||
|
.inner_intersection('❤')
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,6 +99,7 @@ impl TableTheme {
|
||||||
.left(None)
|
.left(None)
|
||||||
.right(None)])
|
.right(None)])
|
||||||
.into(),
|
.into(),
|
||||||
|
full_theme: Some(Style::extended().into()),
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,6 +107,14 @@ impl TableTheme {
|
||||||
pub fn rounded() -> TableTheme {
|
pub fn rounded() -> TableTheme {
|
||||||
Self {
|
Self {
|
||||||
theme: Style::rounded().into(),
|
theme: Style::rounded().into(),
|
||||||
|
full_theme: Some(
|
||||||
|
Style::modern()
|
||||||
|
.top_left_corner('╭')
|
||||||
|
.top_right_corner('╮')
|
||||||
|
.bottom_left_corner('╰')
|
||||||
|
.bottom_right_corner('╯')
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -96,6 +128,14 @@ impl TableTheme {
|
||||||
.bottom_right_corner('┛')
|
.bottom_right_corner('┛')
|
||||||
.off_horizontal()
|
.off_horizontal()
|
||||||
.into(),
|
.into(),
|
||||||
|
full_theme: Some(
|
||||||
|
Style::modern()
|
||||||
|
.top_left_corner('┏')
|
||||||
|
.top_right_corner('┓')
|
||||||
|
.bottom_left_corner('┗')
|
||||||
|
.bottom_right_corner('┛')
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,6 +156,25 @@ impl TableTheme {
|
||||||
.bottom_right_corner('┛')
|
.bottom_right_corner('┛')
|
||||||
.horizontals([HorizontalLine::new(1, Line::full('━', '╋', '┣', '┫'))])
|
.horizontals([HorizontalLine::new(1, Line::full('━', '╋', '┣', '┫'))])
|
||||||
.into(),
|
.into(),
|
||||||
|
full_theme: Some(
|
||||||
|
Style::modern()
|
||||||
|
.top('━')
|
||||||
|
.bottom('━')
|
||||||
|
.vertical('┃')
|
||||||
|
.left('┃')
|
||||||
|
.right('┃')
|
||||||
|
.top_intersection('┳')
|
||||||
|
.bottom_intersection('┻')
|
||||||
|
.top_left_corner('┏')
|
||||||
|
.top_right_corner('┓')
|
||||||
|
.bottom_left_corner('┗')
|
||||||
|
.bottom_right_corner('┛')
|
||||||
|
.horizontal('━')
|
||||||
|
.left_intersection('┣')
|
||||||
|
.right_intersection('┫')
|
||||||
|
.inner_intersection('╋')
|
||||||
|
.into(),
|
||||||
|
),
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,6 +182,7 @@ impl TableTheme {
|
||||||
pub fn none() -> TableTheme {
|
pub fn none() -> TableTheme {
|
||||||
Self {
|
Self {
|
||||||
theme: Style::blank().into(),
|
theme: Style::blank().into(),
|
||||||
|
full_theme: None,
|
||||||
has_inner: true,
|
has_inner: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -151,4 +211,8 @@ impl TableTheme {
|
||||||
pub fn has_inner(&self) -> bool {
|
pub fn has_inner(&self) -> bool {
|
||||||
self.has_inner
|
self.has_inner
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_full(&self) -> Option<RawStyle> {
|
||||||
|
self.full_theme.clone()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user