Use Unicode box-drawing characters for tables

This commit is contained in:
George Pollard 2019-08-24 14:12:35 +12:00
parent cd1e16d574
commit 9de0b27867
No known key found for this signature in database
GPG Key ID: 6694D898AEB73984
4 changed files with 19 additions and 22 deletions

View File

@ -1,3 +1,4 @@
crate mod consts;
crate mod entries; crate mod entries;
crate mod generic; crate mod generic;
crate mod list; 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::object::Value;
use crate::prelude::*; use crate::prelude::*;
use ansi_term::Color; use ansi_term::Color;
use derive_new::new; use derive_new::new;
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator};
use textwrap::fill; use textwrap::fill;
use prettytable::{color, Attr, Cell, Row, Table}; use prettytable::{color, Attr, Cell, Row, Table};
@ -191,16 +190,7 @@ impl RenderView for TableView {
} }
let mut table = Table::new(); let mut table = Table::new();
table.set_format(*consts::TABLE_FORMAT);
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());
let header: Vec<Cell> = self let header: Vec<Cell> = self
.headers .headers

View File

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