mirror of
https://github.com/nushell/nushell.git
synced 2025-08-18 06:40:16 +02:00
feat(table): add 'double' table mode (#16013)
# Description Add 'double' table mode, that is similar to `compact_double` but with left and right border lines. This is similar to how there exist both `single` and `compact`, but there is no `double` to compliment `compact_double`. Printing `[ { a: 1, b: 11 }, { a: 2, b:12 } ]` looks like this: ``` ╔═══╦═══╦════╗ ║ # ║ a ║ b ║ ╠═══╬═══╬════╣ ║ 0 ║ 1 ║ 11 ║ ║ 1 ║ 2 ║ 12 ║ ╚═══╩═══╩════╝ ``` The implementation is mostly a one-to-one of #15672 and #15681. # User-Facing Changes New value `double` to set as `$env.config.table.mode`. # Tests + Formatting Tests are added following the example of adding 'single' mode. # After Submitting
This commit is contained in:
committed by
GitHub
parent
4f7e9aac62
commit
c3079a14d9
@@ -187,6 +187,7 @@ pub fn load_theme(mode: TableMode) -> TableTheme {
|
||||
TableMode::AsciiRounded => TableTheme::ascii_rounded(),
|
||||
TableMode::BasicCompact => TableTheme::basic_compact(),
|
||||
TableMode::Single => TableTheme::single(),
|
||||
TableMode::Double => TableTheme::double(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -166,6 +166,15 @@ impl TableTheme {
|
||||
Self::new(Style::sharp(), full)
|
||||
}
|
||||
|
||||
pub fn double() -> TableTheme {
|
||||
let hline = HorizontalLine::inherit(Style::extended());
|
||||
let theme = Style::extended()
|
||||
.remove_horizontal()
|
||||
.horizontals([(1, hline)]);
|
||||
|
||||
Self::new(theme, Style::extended())
|
||||
}
|
||||
|
||||
pub fn none() -> TableTheme {
|
||||
Self::new(Style::blank(), Style::blank())
|
||||
}
|
||||
|
@@ -497,6 +497,52 @@ fn test_single() {
|
||||
assert_eq!(create_table_with_size(vec![], true, theme::single()), "");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_double() {
|
||||
assert_eq!(
|
||||
create_table(vec![row(4); 3], true, theme::double()),
|
||||
"╔═══╦═══╦═══╦═══╗\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
╠═══╬═══╬═══╬═══╣\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
╚═══╩═══╩═══╩═══╝"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
create_table(vec![row(4); 2], true, theme::double()),
|
||||
"╔═══╦═══╦═══╦═══╗\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
╠═══╬═══╬═══╬═══╣\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
╚═══╩═══╩═══╩═══╝"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
create_table(vec![row(4); 1], true, theme::double()),
|
||||
"╔═══╦═══╦═══╦═══╗\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
╚═══╩═══╩═══╩═══╝"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
create_table(vec![row(4); 1], false, theme::double()),
|
||||
"╔═══╦═══╦═══╦═══╗\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
╚═══╩═══╩═══╩═══╝"
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
create_table(vec![row(4); 2], false, theme::double()),
|
||||
"╔═══╦═══╦═══╦═══╗\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
║ 0 ║ 1 ║ 2 ║ 3 ║\n\
|
||||
╚═══╩═══╩═══╩═══╝"
|
||||
);
|
||||
|
||||
assert_eq!(create_table_with_size(vec![], true, theme::double()), "");
|
||||
}
|
||||
|
||||
fn create_table(data: Vec<Vec<Text<String>>>, with_header: bool, theme: theme) -> String {
|
||||
let mut case = TestCase::new(usize::MAX).theme(theme);
|
||||
if with_header {
|
||||
|
Reference in New Issue
Block a user