From 4e700115b9cdef611a96384f83c55ac5d601fef0 Mon Sep 17 00:00:00 2001 From: Arne Beer Date: Wed, 29 Jan 2020 20:12:26 +0100 Subject: [PATCH] Add Column::remove_constraint() --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- src/column.rs | 27 +++++++++++++++++++++++++++ src/style/column.rs | 2 +- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..a90eb85 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,5 @@ +#v0.0.5 + +- Add `Column::remove_constraint()` +- Preset `UTF8_NO_BORDERS` +- Preset `UTF8_HORIZONTAL_BORDERS_ONLY` diff --git a/Cargo.toml b/Cargo.toml index 62b601d..feed3a3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "comfy-table" description = "A easy to use, dynamically wrapping and highly configurable commandline table builder library." -version = "0.0.4" +version = "0.0.5" authors = ["Arne Beer "] homepage = "https://github.com/nukesor/comfy-table" repository = "https://github.com/nukesor/comfy-table" diff --git a/src/column.rs b/src/column.rs index 86bdcae..85988b8 100644 --- a/src/column.rs +++ b/src/column.rs @@ -76,9 +76,36 @@ impl Column { self.constraint.as_ref() } + /// Remove any constraint on this column + pub fn remove_constraint(&mut self) -> &mut Self{ + self.constraint = None; + + self + } + /// Set the alignment for content inside of cells for this column. \ /// **Note:** Alignment on a cell will always overwrite the column's setting. pub fn set_cell_alignment(&mut self, alignment: CellAlignment) { self.cell_alignment = Some(alignment); } } + + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_column() { + let mut column = Column::new(0); + column.set_padding((0, 0)); + assert_eq!(column.get_max_content_width(), 0); + + column.set_constraint(ColumnConstraint::ContentWidth); + assert_eq!(column.get_constraint(), Some(&ColumnConstraint::ContentWidth)); + + column.remove_constraint(); + assert_eq!(column.get_constraint(), None); + } +} diff --git a/src/style/column.rs b/src/style/column.rs index 135d5ef..ef2501b 100644 --- a/src/style/column.rs +++ b/src/style/column.rs @@ -1,6 +1,6 @@ /// Constraints can be added to (columns)[crate::Column].\ /// They allow some control over the dynamic content arrangement process. \ -#[derive(Copy, Clone, Debug)] +#[derive(Copy, Clone, Debug, PartialEq)] pub enum ColumnConstraint { /// Force the column to be as long as it's content. /// Use with caution! This can easily break your table, if the column's content is overly long.