Merge pull request #349 from Porges/box-drawing

Use Unicode box-drawing characters for tables
This commit is contained in:
Jonathan Turner 2019-08-26 17:57:48 +12:00 committed by GitHub
commit 8ff418dc00
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 22 deletions

View file

@ -1,3 +1,4 @@
crate mod consts;
crate mod entries;
crate mod generic;
crate mod list;

14
src/format/consts.rs Normal file
View file

@ -0,0 +1,14 @@
use lazy_static::lazy_static;
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator, TableFormat};
lazy_static! {
pub(crate) static ref TABLE_FORMAT: TableFormat =
FormatBuilder::new()
.column_separator('│')
.separator(LinePosition::Top, LineSeparator::new('━', '┯', ' ', ' '))
.separator(LinePosition::Title, LineSeparator::new('─', '┼', ' ', ' '))
.separator(LinePosition::Bottom, LineSeparator::new('━', '┷', ' ', ' '))
.padding(1, 1)
.build();
}

View file

@ -1,9 +1,8 @@
use crate::format::RenderView;
use crate::format::{RenderView, consts};
use crate::object::Value;
use crate::prelude::*;
use ansi_term::Color;
use derive_new::new;
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator};
use textwrap::fill;
use prettytable::{color, Attr, Cell, Row, Table};
@ -191,16 +190,7 @@ impl RenderView for TableView {
}
let mut table = Table::new();
let fb = FormatBuilder::new()
.separator(LinePosition::Top, LineSeparator::new('-', '+', ' ', ' '))
.separator(LinePosition::Bottom, LineSeparator::new('-', '+', ' ', ' '))
.separator(LinePosition::Title, LineSeparator::new('-', '+', '|', '|'))
.column_separator('|')
.padding(1, 1);
//table.set_format(*prettytable::format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
table.set_format(fb.build());
table.set_format(*consts::TABLE_FORMAT);
let header: Vec<Cell> = self
.headers

View file

@ -1,8 +1,7 @@
use crate::format::RenderView;
use crate::format::{RenderView, consts};
use crate::object::Value;
use crate::prelude::*;
use derive_new::new;
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator};
use prettytable::{color, Attr, Cell, Row, Table};
@ -47,14 +46,7 @@ impl RenderView for VTableView {
}
let mut table = Table::new();
let fb = FormatBuilder::new()
.separator(LinePosition::Top, LineSeparator::new('-', '+', ' ', ' '))
.separator(LinePosition::Bottom, LineSeparator::new('-', '+', ' ', ' '))
.column_separator('|')
.padding(1, 1);
table.set_format(fb.build());
table.set_format(*consts::TABLE_FORMAT);
for row in &self.entries {
table.add_row(Row::new(