forked from extern/nushell
02ad491dea
* 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>
47 lines
1.8 KiB
Rust
47 lines
1.8 KiB
Rust
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
|
|
}
|