pub struct TableView<'a> { /* private fields */ }Expand description
A sequence of records as a table.
Columns are the union of the records’ keys in first-seen order; a record
that is not a map fills a value column. Missing cells stay empty,
nested values show as compact JSON, numbers are right-justified and nulls
dim. A map renders as one record; a scalar as a one-cell table.
use rich::Console;
use rich_ext::data::{from_serialize, TableView};
use serde_json::json;
let rows = from_serialize(&json!([{"name": "a", "port": 80}, {"name": "b"}])).unwrap();
let out = Console::builder().width(30).build().render_export(&TableView::new(&rows));
assert!(out.contains("│ a │ 80 │"), "{out}");Implementations§
Source§impl<'a> TableView<'a>
impl<'a> TableView<'a>
pub fn new(node: impl Into<Cow<'a, Node>>) -> Self
Sourcepub fn options(self, options: TableOptions) -> Self
pub fn options(self, options: TableOptions) -> Self
Replace all options.
Sourcepub fn columns<S: Into<String>>(
self,
columns: impl IntoIterator<Item = S>,
) -> Self
pub fn columns<S: Into<String>>( self, columns: impl IntoIterator<Item = S>, ) -> Self
Sourcepub fn header(
self,
column: impl Into<String>,
header: impl Into<String>,
) -> Self
pub fn header( self, column: impl Into<String>, header: impl Into<String>, ) -> Self
See TableOptions::header.
pub fn title(self, title: impl Into<String>) -> Self
pub fn max_rows(self, max_rows: usize) -> Self
pub fn max_string(self, max_string: usize) -> Self
Trait Implementations§
Source§impl Renderable for TableView<'_>
impl Renderable for TableView<'_>
fn rich_render( &self, console: &Console, options: &ConsoleOptions, ) -> Vec<Segment>
Source§fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
fn measure(&self, _console: &Console, options: &ConsoleOptions) -> Measurement
The
(minimum, maximum) cell width this renderable wants. The default
assumes the renderable fills the available width (e.g. Panel, Table);
Text overrides it with its content width so the top-level print path can
shrink to fit. Port of __rich_measure__ / Measurement.get.Source§fn fit_to_measurement(&self) -> bool
fn fit_to_measurement(&self) -> bool
Whether a top-level
Console::print shrinks this renderable to its
measured width. Upstream renders every top-level renderable at the full
console width, so the default is false; an extension may opt in.Auto Trait Implementations§
impl<'a> Freeze for TableView<'a>
impl<'a> RefUnwindSafe for TableView<'a>
impl<'a> Send for TableView<'a>
impl<'a> Sync for TableView<'a>
impl<'a> Unpin for TableView<'a>
impl<'a> UnsafeUnpin for TableView<'a>
impl<'a> UnwindSafe for TableView<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more