mirror of
https://github.com/nushell/nushell
synced 2024-12-28 22:13:10 +00:00
commit
628da27122
4 changed files with 32 additions and 22 deletions
|
@ -1,4 +1,3 @@
|
||||||
crate mod consts;
|
|
||||||
crate mod entries;
|
crate mod entries;
|
||||||
crate mod generic;
|
crate mod generic;
|
||||||
crate mod list;
|
crate mod list;
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
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();
|
|
||||||
}
|
|
|
@ -1,9 +1,10 @@
|
||||||
use crate::format::{RenderView, consts};
|
use crate::format::RenderView;
|
||||||
use crate::object::Value;
|
use crate::object::Value;
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
use derive_new::new;
|
use derive_new::new;
|
||||||
use textwrap::fill;
|
use textwrap::fill;
|
||||||
|
|
||||||
|
use prettytable::format::{FormatBuilder, LinePosition, LineSeparator};
|
||||||
use prettytable::{color, Attr, Cell, Row, Table};
|
use prettytable::{color, Attr, Cell, Row, Table};
|
||||||
|
|
||||||
#[derive(Debug, new)]
|
#[derive(Debug, new)]
|
||||||
|
@ -49,9 +50,12 @@ impl TableView {
|
||||||
} => headers
|
} => headers
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, d)| {
|
.map(|(i, d)| {
|
||||||
let data = value.get_data(d);
|
let data = value.get_data(d);
|
||||||
return (data.borrow().format_leaf(Some(&headers[i])), data.borrow().style_leaf());
|
return (
|
||||||
|
data.borrow().format_leaf(Some(&headers[i])),
|
||||||
|
data.borrow().style_leaf(),
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
x => vec![(x.format_leaf(None), x.style_leaf())],
|
x => vec![(x.format_leaf(None), x.style_leaf())],
|
||||||
|
@ -191,7 +195,15 @@ impl RenderView for TableView {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
table.set_format(*consts::TABLE_FORMAT);
|
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
|
||||||
|
@ -206,7 +218,11 @@ impl RenderView for TableView {
|
||||||
table.set_titles(Row::new(header));
|
table.set_titles(Row::new(header));
|
||||||
|
|
||||||
for row in &self.entries {
|
for row in &self.entries {
|
||||||
table.add_row(Row::new(row.iter().map(|(v, s)| Cell::new(v).style_spec(s)).collect()));
|
table.add_row(Row::new(
|
||||||
|
row.iter()
|
||||||
|
.map(|(v, s)| Cell::new(v).style_spec(s))
|
||||||
|
.collect(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
table.print_term(&mut *host.out_terminal()).unwrap();
|
table.print_term(&mut *host.out_terminal()).unwrap();
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use crate::format::{RenderView, consts};
|
use crate::format::RenderView;
|
||||||
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};
|
||||||
|
|
||||||
#[derive(new)]
|
#[derive(new)]
|
||||||
|
@ -46,7 +47,15 @@ impl RenderView for VTableView {
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut table = Table::new();
|
let mut table = Table::new();
|
||||||
table.set_format(*consts::TABLE_FORMAT);
|
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(),
|
||||||
|
);
|
||||||
|
|
||||||
for row in &self.entries {
|
for row in &self.entries {
|
||||||
table.add_row(Row::new(
|
table.add_row(Row::new(
|
||||||
|
|
Loading…
Reference in a new issue