add a vertical record view

This commit is contained in:
JT
2021-10-01 19:01:22 +13:00
parent 99666829e0
commit d6e24cceb4
4 changed files with 65 additions and 1 deletions

View File

@ -28,7 +28,7 @@ impl Command for FromJson {
input: Value,
) -> Result<nu_protocol::Value, ShellError> {
let span = input.span();
let mut string_input = input.into_string();
let mut string_input = input.collect_string();
string_input.push('\n');
// TODO: turn this into a structured underline of the nu_json error

View File

@ -56,6 +56,35 @@ impl Command for Table {
Ok(Value::Nothing { span: call.head })
}
}
Value::Record { cols, vals, .. } => {
let mut output = vec![];
for (c, v) in cols.into_iter().zip(vals.into_iter()) {
output.push(vec![
StyledString {
contents: c,
style: nu_table::TextStyle::default_header(),
},
StyledString {
contents: v.into_string(),
style: nu_table::TextStyle::default(),
},
])
}
let table = nu_table::Table {
headers: vec![],
data: output,
theme: nu_table::Theme::rounded(),
};
let result = nu_table::draw_table(&table, 80, &HashMap::new());
Ok(Value::String {
val: result,
span: call.head,
})
}
x => Ok(x),
}
}