mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
update mock table for easier table testing (#3065)
This commit is contained in:
parent
039f223b53
commit
11a9144e84
1 changed files with 63 additions and 19 deletions
|
@ -4,27 +4,71 @@ use std::collections::HashMap;
|
|||
fn main() {
|
||||
let args: Vec<_> = std::env::args().collect();
|
||||
|
||||
// Width in terminal characters
|
||||
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(),
|
||||
);
|
||||
// The mocked up table data
|
||||
let (table_headers, row_data) = make_table_data();
|
||||
// The table headers
|
||||
let headers = vec_of_str_to_vec_of_styledstr(&table_headers, true);
|
||||
// The table rows
|
||||
let rows = vec_of_str_to_vec_of_styledstr(&row_data, false);
|
||||
// The table itself
|
||||
let table = Table::new(headers, vec![rows; 3], Theme::rounded());
|
||||
|
||||
// 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);
|
||||
// Draw the table
|
||||
draw_table(&table, width, &color_hm);
|
||||
}
|
||||
|
||||
fn make_table_data() -> (Vec<&'static str>, Vec<&'static str>) {
|
||||
let mut table_headers = vec![];
|
||||
table_headers.push("category");
|
||||
table_headers.push("description");
|
||||
table_headers.push("emoji");
|
||||
table_headers.push("ios_version");
|
||||
table_headers.push("unicode_version");
|
||||
table_headers.push("aliases");
|
||||
table_headers.push("tags");
|
||||
table_headers.push("category2");
|
||||
table_headers.push("description2");
|
||||
table_headers.push("emoji2");
|
||||
table_headers.push("ios_version2");
|
||||
table_headers.push("unicode_version2");
|
||||
table_headers.push("aliases2");
|
||||
table_headers.push("tags2");
|
||||
|
||||
let mut row_data = vec![];
|
||||
row_data.push("Smileys & Emotion");
|
||||
row_data.push("grinning face");
|
||||
row_data.push("😀");
|
||||
row_data.push("6");
|
||||
row_data.push("6.1");
|
||||
row_data.push("grinning");
|
||||
row_data.push("smile");
|
||||
row_data.push("Smileys & Emotion");
|
||||
row_data.push("grinning face");
|
||||
row_data.push("😀");
|
||||
row_data.push("6");
|
||||
row_data.push("6.1");
|
||||
row_data.push("grinning");
|
||||
row_data.push("smile");
|
||||
|
||||
(table_headers, row_data)
|
||||
}
|
||||
|
||||
fn vec_of_str_to_vec_of_styledstr(data: &[&str], is_header: bool) -> Vec<StyledString> {
|
||||
let mut v = vec![];
|
||||
|
||||
for x in data.iter() {
|
||||
if is_header {
|
||||
v.push(StyledString::new(
|
||||
String::from(*x),
|
||||
TextStyle::default_header(),
|
||||
))
|
||||
} else {
|
||||
v.push(StyledString::new(String::from(*x), TextStyle::basic_left()))
|
||||
}
|
||||
}
|
||||
v
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue