mirror of
https://github.com/nushell/nushell.git
synced 2025-08-16 16:41:41 +02:00
[WIP] table: Change Record view in expand-mode (#6885)
* table: Change Record view in expand-mode Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Fix width issue Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Remove debug println! Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Update logic Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Improve the logic via a wrapping Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * `table -e` spread table to the whole width Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * fix CI Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Fixing tests Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Fix coloring issues Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Don't expand when can Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Fix tests Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Change the logic Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> * Fix cargo fmt Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com> Signed-off-by: Maxim Zhiburt <zhiburt@gmail.com>
This commit is contained in:
@ -188,7 +188,7 @@ fn truncate_with_suffix_test() {
|
||||
fn draw_table(table: Table, limit: usize, cfg: &Config) -> Option<String> {
|
||||
let styles = HashMap::default();
|
||||
let alignments = Alignments::default();
|
||||
table.draw_table(cfg, &styles, alignments, &theme::heavy(), limit)
|
||||
table.draw_table(cfg, &styles, alignments, &theme::heavy(), limit, false)
|
||||
}
|
||||
|
||||
fn row(count_columns: usize) -> Vec<TCell<CellInfo<'static>, TextStyle>> {
|
||||
|
46
crates/nu-table/tests/expand.rs
Normal file
46
crates/nu-table/tests/expand.rs
Normal file
@ -0,0 +1,46 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use nu_protocol::Config;
|
||||
use nu_table::{Alignments, Table, TableTheme as theme, TextStyle};
|
||||
use tabled::papergrid::records::{cell_info::CellInfo, tcell::TCell};
|
||||
|
||||
#[test]
|
||||
fn test_expand() {
|
||||
assert_eq!(
|
||||
draw_table(vec![row(4); 3], 4, true, theme::rounded(), 50),
|
||||
"╭────────────┬───────────┬───────────┬───────────╮\n\
|
||||
│ 0 │ 1 │ 2 │ 3 │\n\
|
||||
├────────────┼───────────┼───────────┼───────────┤\n\
|
||||
│ 0 │ 1 │ 2 │ 3 │\n\
|
||||
│ 0 │ 1 │ 2 │ 3 │\n\
|
||||
╰────────────┴───────────┴───────────┴───────────╯"
|
||||
);
|
||||
}
|
||||
|
||||
fn draw_table(
|
||||
data: Vec<Vec<TCell<CellInfo<'static>, TextStyle>>>,
|
||||
count_columns: usize,
|
||||
with_header: bool,
|
||||
theme: theme,
|
||||
width: usize,
|
||||
) -> String {
|
||||
let size = (data.len(), count_columns);
|
||||
let table = Table::new(data, size, width, with_header, false);
|
||||
|
||||
let cfg = Config::default();
|
||||
let styles = HashMap::default();
|
||||
let alignments = Alignments::default();
|
||||
table
|
||||
.draw_table(&cfg, &styles, alignments, &theme, width, true)
|
||||
.expect("Unexpectdly got no table")
|
||||
}
|
||||
|
||||
fn row(count_columns: usize) -> Vec<TCell<CellInfo<'static>, TextStyle>> {
|
||||
let mut row = Vec::with_capacity(count_columns);
|
||||
|
||||
for i in 0..count_columns {
|
||||
row.push(Table::create_cell(i.to_string(), TextStyle::default()));
|
||||
}
|
||||
|
||||
row
|
||||
}
|
@ -464,7 +464,7 @@ fn draw_table(
|
||||
let styles = HashMap::default();
|
||||
let alignments = Alignments::default();
|
||||
table
|
||||
.draw_table(&cfg, &styles, alignments, &theme, std::usize::MAX)
|
||||
.draw_table(&cfg, &styles, alignments, &theme, std::usize::MAX, false)
|
||||
.expect("Unexpectdly got no table")
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user