nushell/crates/nu-table/src/main.rs
Darren Schroeder 57a26bbd42
Default alignment (#2481)
* WIP - compiling but not working

* semi-working

* making progress

* working except for table lines

* fmt + clippy

* cleaned up some comments

* working line colors

* fmt, clippy, updated sample config.toml

* merges

* fixed bug where no config.toml or not set settings made weird defaults.

* clippy & fmt again

* Header default alignment is left.

Co-authored-by: Andrés N. Robalino <andres@androbtech.com>
2020-09-01 19:08:41 -05:00

31 lines
1.0 KiB
Rust

use nu_table::{draw_table, StyledString, Table, TextStyle, Theme};
use std::collections::HashMap;
fn main() {
let args: Vec<_> = std::env::args().collect();
let width = args[1].parse::<usize>().expect("Need a width in columns");
let msg = args[2..]
.iter()
.map(|x| StyledString::new(x.to_owned(), TextStyle::basic_left()))
.collect();
let t = Table::new(
vec![
StyledString::new("Test me".to_owned(), TextStyle::default_header()),
StyledString::new(
"Long column \n name with carriage returns and a lot of text\n check it out"
.to_owned(),
TextStyle::default_header(),
),
StyledString::new("Another".to_owned(), TextStyle::default_header()),
],
vec![msg; 2],
Theme::compact(),
);
// FIXME: Config isn't available from here so just put these here to compile
let color_hm: HashMap<String, ansi_term::Style> = HashMap::new();
draw_table(&t, width, &color_hm);
}