From 9de0b27867e359b837d1d7126cf84f2a872ee7fb Mon Sep 17 00:00:00 2001 From: George Pollard Date: Sat, 24 Aug 2019 14:12:35 +1200 Subject: [PATCH] Use Unicode box-drawing characters for tables --- src/format.rs | 1 + src/format/consts.rs | 14 ++++++++++++++ src/format/table.rs | 14 ++------------ src/format/vtable.rs | 12 ++---------- 4 files changed, 19 insertions(+), 22 deletions(-) create mode 100644 src/format/consts.rs diff --git a/src/format.rs b/src/format.rs index ae43c6f8a..b23b67534 100644 --- a/src/format.rs +++ b/src/format.rs @@ -1,3 +1,4 @@ +crate mod consts; crate mod entries; crate mod generic; crate mod list; diff --git a/src/format/consts.rs b/src/format/consts.rs new file mode 100644 index 000000000..c36870da8 --- /dev/null +++ b/src/format/consts.rs @@ -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(); +} diff --git a/src/format/table.rs b/src/format/table.rs index ec641bff0..c01d24ca4 100644 --- a/src/format/table.rs +++ b/src/format/table.rs @@ -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 = self .headers diff --git a/src/format/vtable.rs b/src/format/vtable.rs index 30539321a..533baea8b 100644 --- a/src/format/vtable.rs +++ b/src/format/vtable.rs @@ -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(