Merge pull request #631 from jonathandturner/light_tables

Add lighter-weight table output
This commit is contained in:
Jonathan Turner 2019-09-10 05:59:11 +12:00 committed by GitHub
commit 7e2d701725
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 10 deletions

View file

@ -1,8 +1,8 @@
use crate::prelude::*;
use crate::commands::WholeStreamCommand;
use crate::errors::ShellError;
use crate::data::{config, Value};
use crate::errors::ShellError;
use crate::parser::hir::SyntaxType;
use crate::parser::registry::{self};
use std::iter::FromIterator;

View file

@ -16,6 +16,11 @@ pub struct TableView {
entries: Vec<Vec<(String, &'static str)>>,
}
enum TableMode {
Light,
Normal,
}
impl TableView {
fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
let mut ret = vec![];
@ -198,15 +203,36 @@ impl RenderView for TableView {
}
let mut table = Table::new();
table.set_format(
FormatBuilder::new()
.column_separator('│')
.separator(LinePosition::Top, LineSeparator::new('━', '┯', ' ', ' '))
.separator(LinePosition::Title, LineSeparator::new('─', '┼', ' ', ' '))
.separator(LinePosition::Bottom, LineSeparator::new('━', '┷', ' ', ' '))
.padding(1, 1)
.build(),
);
let table_mode = crate::data::config::config(Span::unknown())?
.get("table_mode")
.map(|s| match s.as_string().unwrap().as_ref() {
"light" => TableMode::Light,
_ => TableMode::Normal,
})
.unwrap_or(TableMode::Normal);
match table_mode {
TableMode::Light => {
table.set_format(
FormatBuilder::new()
.separator(LinePosition::Title, LineSeparator::new('─', '─', ' ', ' '))
.padding(1, 1)
.build(),
);
}
_ => {
table.set_format(
FormatBuilder::new()
.column_separator('│')
.separator(LinePosition::Top, LineSeparator::new('━', '┯', ' ', ' '))
.separator(LinePosition::Title, LineSeparator::new('─', '┼', ' ', ' '))
.separator(LinePosition::Bottom, LineSeparator::new('━', '┷', ' ', ' '))
.padding(1, 1)
.build(),
);
}
}
let header: Vec<Cell> = self
.headers