mirror of
https://github.com/nushell/nushell
synced 2025-01-13 21:55:07 +00:00
Merge pull request #631 from jonathandturner/light_tables
Add lighter-weight table output
This commit is contained in:
commit
7e2d701725
2 changed files with 36 additions and 10 deletions
|
@ -1,8 +1,8 @@
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
use crate::commands::WholeStreamCommand;
|
use crate::commands::WholeStreamCommand;
|
||||||
use crate::errors::ShellError;
|
|
||||||
use crate::data::{config, Value};
|
use crate::data::{config, Value};
|
||||||
|
use crate::errors::ShellError;
|
||||||
use crate::parser::hir::SyntaxType;
|
use crate::parser::hir::SyntaxType;
|
||||||
use crate::parser::registry::{self};
|
use crate::parser::registry::{self};
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
|
|
@ -16,6 +16,11 @@ pub struct TableView {
|
||||||
entries: Vec<Vec<(String, &'static str)>>,
|
entries: Vec<Vec<(String, &'static str)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum TableMode {
|
||||||
|
Light,
|
||||||
|
Normal,
|
||||||
|
}
|
||||||
|
|
||||||
impl TableView {
|
impl TableView {
|
||||||
fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
|
fn merge_descriptors(values: &[Tagged<Value>]) -> Vec<String> {
|
||||||
let mut ret = vec![];
|
let mut ret = vec![];
|
||||||
|
@ -198,15 +203,36 @@ impl RenderView for TableView {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
table.set_format(
|
|
||||||
FormatBuilder::new()
|
let table_mode = crate::data::config::config(Span::unknown())?
|
||||||
.column_separator('│')
|
.get("table_mode")
|
||||||
.separator(LinePosition::Top, LineSeparator::new('━', '┯', ' ', ' '))
|
.map(|s| match s.as_string().unwrap().as_ref() {
|
||||||
.separator(LinePosition::Title, LineSeparator::new('─', '┼', ' ', ' '))
|
"light" => TableMode::Light,
|
||||||
.separator(LinePosition::Bottom, LineSeparator::new('━', '┷', ' ', ' '))
|
_ => TableMode::Normal,
|
||||||
.padding(1, 1)
|
})
|
||||||
.build(),
|
.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
|
let header: Vec<Cell> = self
|
||||||
.headers
|
.headers
|
||||||
|
|
Loading…
Reference in a new issue