1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
#![forbid(unsafe_code, unstable_features)] #![deny(missing_docs)] //! Rust crate for printing tables on command line. //! //! ## Usage //! //! Add `cli-table` in your `Cargo.toms`'s `dependencies` section //! //! ```toml //! [dependencies] //! cli-table = "0.3" //! ``` //! //! Each cell in a [`Table`] can be formatted using [`CellFormat`]. [`CellFormat`] can be easily created like this: //! //! ``` //! # use cli_table::format::{CellFormat, Justify}; //! // Justifies contents of a cell to right //! let justify_right = CellFormat::builder().justify(Justify::Right).build(); //! //! // Makes contents of a cell bold //! let bold = CellFormat::builder().bold(true).build(); //! ``` //! //! [`Table`] can be formatted using [`TableFormat`]. It is very easy to create a custom table format, but for //! simplicity, this crate provides a few predefined [`TableFormat`]s: //! //! - [`BORDER_COLUMN_ROW`]: Format with borders, column separators and row separators (calling `Default::default()` //! on [`TableFormat`] also returns this format) //! - [`BORDER_COLUMN_NO_ROW`]: Format with borders and column separators (without row separators) //! - [`BORDER_COLUMN_TITLE`]: Format with borders, column separators and title separator (without row separators) //! - [`BORDER_NO_COLUMN_ROW`]: Format with borders and row separators (without column separators) //! - [`NO_BORDER_COLUMN_ROW`]: Format with no borders, column separators and row separators //! - [`NO_BORDER_COLUMN_TITLE`]: Format with no borders, column separators and title separator (without row separators) //! //! To create a table, you can use [`Table::new()`] like this: //! //! ``` //! # use cli_table::format::{CellFormat, Justify}; //! # use cli_table::{Table, Row, Cell}; //! # let justify_right = CellFormat::builder().justify(Justify::Right).build(); //! # let bold = CellFormat::builder().bold(true).build(); //! let table = Table::new( //! vec![ //! Row::new(vec![ //! Cell::new(&format!("Name"), bold), //! Cell::new("Age (in years)", bold), //! ]), //! Row::new(vec![ //! Cell::new("Tom", Default::default()), //! Cell::new("10", justify_right), //! ]), //! Row::new(vec![ //! Cell::new("Jerry", Default::default()), //! Cell::new("15", justify_right), //! ]), //! Row::new(vec![ //! Cell::new("Scooby Doo", Default::default()), //! Cell::new("25", justify_right), //! ]), //! ], //! Default::default(), //! ) //! .unwrap(); //! ``` //! //! To print this table on `stdout`, you can call [`table.print_stdout()`]. //! //! Below is the output of the table we created just now: //! //! ```markdown //! +------------+----------------+ //! | Name | Age (in years) | <-- This row will appear in bold //! +------------+----------------+ //! | Tom | 10 | //! +------------+----------------+ //! | Jerry | 15 | //! +------------+----------------+ //! | Scooby Doo | 25 | //! +------------+----------------+ //! ``` //! //! [`Table`]: crate::Table //! [`CellFormat`]: crate::format::CellFormat //! [`TableFormat`]: crate::format::TableFormat //! [`Table::new()`]: crate::Table::new //! [`table.print_stdout()`]: crate::Table::print_stdout //! //! [`BORDER_COLUMN_ROW`]: crate::format::BORDER_COLUMN_ROW //! [`BORDER_COLUMN_NO_ROW`]: crate::format::BORDER_COLUMN_NO_ROW //! [`BORDER_COLUMN_TITLE`]: crate::format::BORDER_COLUMN_TITLE //! [`BORDER_NO_COLUMN_ROW`]: crate::format::BORDER_NO_COLUMN_ROW //! [`NO_BORDER_COLUMN_ROW`]: crate::format::NO_BORDER_COLUMN_ROW //! [`NO_BORDER_COLUMN_TITLE`]: crate::format::NO_BORDER_COLUMN_TITLE mod cell; mod error; mod row; mod table; pub mod format; pub use self::cell::Cell; pub use self::error::Error; pub use self::row::Row; pub use self::table::{ColorChoice, Table};