From d1167151fc8a0a566189b31735cc9b85142e8273 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Tue, 10 Sep 2019 05:10:52 +1200 Subject: [PATCH] Add support for light tables --- src/commands/config.rs | 2 +- src/format/table.rs | 44 +++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/commands/config.rs b/src/commands/config.rs index c1f000d04d..440432c275 100644 --- a/src/commands/config.rs +++ b/src/commands/config.rs @@ -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; diff --git a/src/format/table.rs b/src/format/table.rs index 8deaf30aaf..717e3c4a27 100644 --- a/src/format/table.rs +++ b/src/format/table.rs @@ -16,6 +16,11 @@ pub struct TableView { entries: Vec>, } +enum TableMode { + Light, + Normal, +} + impl TableView { fn merge_descriptors(values: &[Tagged]) -> Vec { 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 = self .headers