[−][src]Struct comfy_table::Table
This is the main interface for building a table. Each table consists of Rows, which in turn contain Cells.
There also exists a representation of a Column. Columns are automatically created when adding rows to a table.
Implementations
impl Table
[src]
pub fn new() -> Self
[src]
Create a new table with default ASCII styling.
pub fn trim_fmt(&self) -> String
[src]
This is an alternative fmt
function, which simply removes any trailing whitespaces.
Trailing whitespaces often occur, when using tables without a right border.
pub fn set_header<T: ToRow>(&mut self, row: T) -> &mut Self
[src]
Set the header row of the table. This is usually the title of each column.
There'll be no header unless you explicitly set it with this function.
use comfy_table::{Table, Row}; let mut table = Table::new(); let header = Row::from(vec!["Header One", "Header Two"]); table.set_header(header);
pub fn get_header(&self) -> Option<&Row>
[src]
pub fn add_row<T: ToRow>(&mut self, row: T) -> &mut Self
[src]
Add a new row to the table.
use comfy_table::{Table, Row}; let mut table = Table::new(); let row = Row::from(vec!["One", "Two"]); table.add_row(row);
pub fn set_table_width(&mut self, table_width: u16) -> &mut Self
[src]
Enforce a max width that should be used in combination with dynamic content arrangement.
This is usually not necessary, if you plan to output your table to a tty,
since the terminal width can be automatically determined.
pub fn get_table_width(&self) -> Option<u16>
[src]
Get the expected width of the table.
This will be Some(width)
, if the terminal width can be detected or if the table width is set via set_table_width.
If neither is not possible, None
will be returned.
This implies that both the Dynamic mode and the Percentage constraint won't work.
pub fn set_content_arrangement(
&mut self,
arrangement: ContentArrangement
) -> &mut Self
[src]
&mut self,
arrangement: ContentArrangement
) -> &mut Self
Specify how Comfy Table should arrange the content in your table.
use comfy_table::{Table, ContentArrangement}; let mut table = Table::new(); table.set_content_arrangement(ContentArrangement::Dynamic);
pub fn set_delimiter(&mut self, delimiter: char) -> &mut Self
[src]
Set the delimiter used to split text in all cells.
A custom delimiter on a cell in will overwrite the column's delimiter.
The default is a simple space
.
pub fn force_no_tty(&mut self) -> &mut Self
[src]
In case you are sure you don't want export tables to a tty or you experience problems with tty specific code, you can enforce a non_tty mode.
This disables:
- table_width lookup from the current tty
- Styling and attributes on cells (unless you use Table::enforce_styling)
If you use the dynamic content arrangement, you need to set the width of your desired table manually with set_table_width.
pub fn is_tty(&self) -> bool
[src]
Returns whether the table will be handled as if it's printed to a tty.
This function respects the Table::force_no_tty function.
Otherwise we try to determine, if we are on a tty.
pub fn enforce_styling(&mut self) -> &mut Self
[src]
Enforce terminal styling.
Only useful if you forcefully disabled tty, but still want those fancy terminal styles.
use comfy_table::Table; let mut table = Table::new(); table.force_no_tty() .enforce_styling();
pub fn should_style(&self) -> bool
[src]
Returns whether the content of this table should be styled with the current settings and environment.
pub fn set_constraints<T: IntoIterator<Item = ColumnConstraint>>(
&mut self,
constraints: T
) -> &mut Self
[src]
&mut self,
constraints: T
) -> &mut Self
Convenience method to set a ColumnConstraint for all columns at once.
Simply pass any iterable with ColumnConstraints.
If more constraints are passed than there are columns, the superfluous constraints will be ignored.
use comfy_table::{Table, ColumnConstraint, ContentArrangement}; let mut table = Table::new(); table.add_row(&vec!["one", "two", "three"]) .set_content_arrangement(ContentArrangement::Dynamic) .set_constraints(vec![ ColumnConstraint::MaxWidth(15), ColumnConstraint::MinWidth(20), ]);
pub fn load_preset(&mut self, preset: &str) -> &mut Self
[src]
This function creates a TableStyle from a given preset string.
Preset strings can be found in styling::presets::*
.
You can also write your own preset strings and use them with this function.
There's the convenience method Table::current_style_as_preset, which prints you a preset
string from your current style configuration.
The function expects the to-be-drawn characters to be in the same order as in the TableComponent enum.
If the string isn't long enough, the default ASCII_FULL style will be used for all remaining components.
If the string is too long, remaining charaacters will be simply ignored.
pub fn current_style_as_preset(&mut self) -> String
[src]
Returns the current style as a preset string.
A pure convenience method, so you're not force to fiddle with those preset strings yourself.
use comfy_table::Table; use comfy_table::presets::UTF8_FULL; let mut table = Table::new(); table.load_preset(UTF8_FULL); assert_eq!(UTF8_FULL, table.current_style_as_preset())
pub fn apply_modifier(&mut self, modifier: &str) -> &mut Self
[src]
Modify a preset with a modifier string from modifiers.
For instance, the UTF8_ROUND_CORNERS modifies all corners to be round UTF8 box corners.
use comfy_table::Table; use comfy_table::presets::UTF8_FULL; use comfy_table::modifiers::UTF8_ROUND_CORNERS; let mut table = Table::new(); table.load_preset(UTF8_FULL); table.apply_modifier(UTF8_ROUND_CORNERS);
pub fn set_style(
&mut self,
component: TableComponent,
character: char
) -> &mut Self
[src]
&mut self,
component: TableComponent,
character: char
) -> &mut Self
Define the char that will be used to draw a specific component.
Look at TableComponent to see all stylable components
If None
is supplied, the element won't be displayed.
In case of a e.g. *BorderIntersection a whitespace will be used as placeholder,
unless related borders and and corners are set to None
as well.
For example, if TopBorderIntersections
is None
the first row would look like this:
+------ ------+
| this | test |
If in addition TopLeftCorner
,TopBorder
and TopRightCorner
would be None
as well,
the first line wouldn't be displayed at all.
use comfy_table::Table; use comfy_table::presets::UTF8_FULL; use comfy_table::TableComponent::*; let mut table = Table::new(); // Load the UTF8_FULL preset table.load_preset(UTF8_FULL); // Set all outer corners to round UTF8 corners // This is basically the same as the UTF8_ROUND_CORNERS modifier table.set_style(TopLeftCorner, '╭'); table.set_style(TopRightCorner, '╮'); table.set_style(BottomLeftCorner, '╰'); table.set_style(BottomRightCorner, '╯');
pub fn get_style(&mut self, component: TableComponent) -> Option<char>
[src]
Get a copy of the char that's currently used for drawing this component.
use comfy_table::Table; use comfy_table::TableComponent::*; let mut table = Table::new(); assert_eq!(table.get_style(TopLeftCorner), Some('+'));
pub fn remove_style(&mut self, component: TableComponent) -> &mut Self
[src]
Remove the style for a specific component of the table.
By default, a space will be used as a placeholder instead.
Though, if for instance all components of the left border are removed, the left border won't be displayed.
pub fn get_column(&self, index: usize) -> Option<&Column>
[src]
Get a reference to a specific column.
pub fn get_column_mut(&mut self, index: usize) -> Option<&mut Column>
[src]
Get a mutable reference to a specific column.
pub fn column_iter(&mut self) -> Iter<'_, Column>
[src]
Iterator over all columns
pub fn column_iter_mut(&mut self) -> IterMut<'_, Column>
[src]
Get a mutable iterator over all columns.
use comfy_table::{Table, ColumnConstraint}; let mut table = Table::new(); table.add_row(&vec!["First", "Second", "Third"]); // Add a ColumnConstraint to each column (left->right) // first -> min width of 10 // second -> max width of 8 // third -> fixed width of 10 let constraints = vec![ ColumnConstraint::MinWidth(10), ColumnConstraint::MaxWidth(8), ColumnConstraint::Width(10), ]; // Add the constraints to their respective column for (column_index, column) in table.column_iter_mut().enumerate() { let constraint = constraints.get(column_index).unwrap(); column.set_constraint(*constraint); }
pub fn get_row(&self, index: usize) -> Option<&Row>
[src]
Reference to a specific row
pub fn get_row_mut(&mut self, index: usize) -> Option<&mut Row>
[src]
Mutable reference to a specific row
pub fn row_iter(&mut self) -> Iter<'_, Row>
[src]
Iterator over all rows
pub fn row_iter_mut(&mut self) -> IterMut<'_, Row>
[src]
Get a mutable iterator over all rows.
use comfy_table::Table; let mut table = Table::new(); table.add_row(&vec!["First", "Second", "Third"]); // Add the constraints to their respective row for row in table.row_iter_mut() { row.max_height(5); } assert!(table.row_iter_mut().len() == 1);
pub fn column_max_content_widths(&self) -> Vec<u16>
[src]
Return a vector representing the maximum amount of characters in any line of this column.
This is mostly needed for internal testing and formatting, but can be interesting
if you want to see the widths of the longest lines for each column.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Table
[src]
impl Send for Table
[src]
impl Sync for Table
[src]
impl Unpin for Table
[src]
impl UnwindSafe for Table
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,