Struct Table

Source
pub struct Table { /* private fields */ }
Expand description

A paintable Table

The type can be thought of as Rows[Cols[Cells[Text]]], where the items inside a Cell will be concatenated together (alowing mixed formatting to exist within a table’s cell).

Warning: do not use \t in your text, as this currently uses tabwriter under the hood.

§Examples

use termstyle::*;

let rows = vec![
    // header
    vec![
        vec![Text::new("header1".into())],
        vec![Text::new("header2".into())],
    ],
    // row1
    vec![
        vec![Text::new("col1".into())],
        vec![Text::new("col2".into())],
    ],
];
let example = Table::new(rows);

let expected = "\
header1 header2
col1    col2
";

let mut result = Vec::new();
example.paint(&mut result);

assert_eq!(expected.as_bytes(), result.as_slice());

Implementations§

Source§

impl Table

Source

pub fn new(table: Vec<Vec<Vec<Text>>>) -> Table

Create a new table from the given rows.

The type can be thought of as Rows[Cols[Cells[Text]]], where the items inside a Cell will be concatenated together (alowing mixed formatting to exist within a table’s cell).

Source

pub fn set_plain(&mut self)

Recursively clears all formatting.

Source

pub fn paint<W: Write>(&self, w: &mut W) -> Result<()>

Paint the table, giving each column the same width.

Trait Implementations§

Source§

impl Debug for Table

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Table

Source§

fn eq(&self, other: &Table) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Table

Source§

impl StructuralPartialEq for Table

Auto Trait Implementations§

§

impl Freeze for Table

§

impl RefUnwindSafe for Table

§

impl Send for Table

§

impl Sync for Table

§

impl Unpin for Table

§

impl UnwindSafe for Table

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.