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

A really powerful table formatter for text user interfaces.

Example:

use alinio::table::Table;
let data = vec![
    vec!["First name", "Surname", "Telephone"],
    vec!["John",       "Smith",   "04529834125"],
];
let mut table = Table::new(data, 40);
println!("{}\n---", table.render().unwrap().join("\n"))

This will print a table

Implementations

Create new table with data and space.

data is organized into rows, and then within those rows, there are columns.

If you are creating a blank table, you may need to specify the type that you wish to give to the table in future. This is usually a String. Example:

use alinio::table::Table;
let table = Table::new::<String>(vec![], 10);

Set the priorities for the columns. This allows you to control which columns to remove when space is limited. The higher the number of the column, the more important it is. For example:

use alinio::table::Table;
let data = vec![
    vec!["First name", "Surname", "Telephone"],
    vec!["John",       "Smith",   "04529834125"],
];
let mut table = Table::new(data, 24);
// First name is the most important, surname is least important, telephone is second most
// important.
// The higher the number, the more important the column
table.set_priorities(&[2, 0, 1]);
// We can't fit the whole table in 24 spaces, so it looks to see what it can remove.
// In this case, we can remove the surname column in order to make it fit, as the surname column
// has the lowest priority in the table.
println!("{}\n---", table.render().unwrap().join("\n"))

Set the alignment of each cell.

When surround is true, padding will be applied to the sides of the table. When surround is false, the table will take the full width.

Set the space between each cell. Use this if your terminal size updates.

Render this table to rows of strings.

This will return None if there is not enough space to fit the table.

Only renders rows after offset row. This is particularly useful if you have a table that you wish to fit into a terminal with a height shorter than the table.

This will return None if there is not enough space to fit the table, or if the offset is out of bounds

Trait Implementations

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.