Skip to content

Commit

Permalink
tabled/ Rename Disable into Remove
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt committed Nov 21, 2024
1 parent 9b058c1 commit 9fe5c71
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 66 deletions.
18 changes: 7 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ you can find more examples in the **[examples](/tabled/examples/)** folder.
- [Height Increase](#height-increase)
- [Height Limit](#height-limit)
- [Rotate](#rotate)
- [Disable](#disable)
- [Remove](#remove)
- [Extract](#extract)
- [Header and Footer and Panel](#header-and-footer-and-panel)
- [Merge](#merge)
Expand Down Expand Up @@ -1106,19 +1106,15 @@ table.with(Rotate::Left);
└──────────────┴────────────────────────┴───────────────────────────┴──────────────────────────┘
```

### Disable
### Remove

You can remove certain rows or columns from the table by `Disable`.
You can remove certain rows or columns from the table by `Remove`.

```rust
use tabled::settings::{
object::{Columns, Rows},
Disable,
};
use tabled::settings::{object::{Columns, Rows}, Remove};

table
.with(Disable::row(Rows::first()))
.with(Disable::column(Columns::single(2)));
table.with(Remove::row(Rows::first()));
table.with(Remove::column(Columns::single(2)));
```

If the above example be applied for a first example in a file it would look like this.
Expand Down Expand Up @@ -1493,7 +1489,7 @@ struct Person {

You can mark filds as hidden in which case they will be ignored and not be present on a sheet.

A similar effect could be achieved by the means of a `Disable` setting.
A similar effect could be achieved by the means of a [`Remove`](#remove).

```rust
use tabled::Tabled;
Expand Down
10 changes: 5 additions & 5 deletions tabled/examples/disable.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! This example demonstrates using the [`Disable`] [`TableOption`] to remove specific
//! This example demonstrates using the [`Remove`] to remove specific
//! cell data from a [`Table`] display.
//!
//! * ⚠️ Using [`Disable`] in combination with other [`Style`] customizations may yield unexpected results.
//! It is safest to use [`Disable`] last in a chain of alterations.
//! * ⚠️ Using [`Remove`] in combination with other [`Style`] customizations may yield unexpected results.
//! It is safest to use [`Remove`] last in a chain of alterations.
use tabled::{
settings::{location::ByColumnName, Disable},
settings::{location::ByColumnName, Remove},
Table, Tabled,
};

Expand Down Expand Up @@ -36,7 +36,7 @@ fn main() {
];

let mut table = Table::new(data);
table.with(Disable::column(ByColumnName::new("is_active")));
table.with(Remove::column(ByColumnName::new("is_active")));

println!("{table}");
}
24 changes: 12 additions & 12 deletions tabled/examples/show/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use tabled::{
settings::{
object::{Columns, Object, Rows},
style::{Border, BorderColor, LineText, Style},
Alignment, Color, Disable, Format, Highlight, Margin, Panel, Width,
Alignment, Color, Remove, Format, Highlight, Margin, Panel, Width,
},
Table, Tabled,
};
Expand Down Expand Up @@ -131,21 +131,21 @@ fn run(movies: &[Movie], debug: bool) {
fn print_movies(p: &mut impl Printer, movies: &[Movie]) {
#[rustfmt::skip]
let create_titles_actions: Vec<Action> = vec![
detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(1..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(2..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(3..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(4..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(1..))).with(Disable::column(Columns::new(5..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(1..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(2..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(3..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(4..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(1..))).with(Remove::column(Columns::new(5..))).with(Style::modern()); }),
];

#[rustfmt::skip]
let add_movies_actions: Vec<Action> = vec![
detached_action(|t| { t.with(Disable::row(Rows::new(2..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(3..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(4..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(5..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(6..))).with(Style::modern()); }),
detached_action(|t| { t.with(Disable::row(Rows::new(7..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(2..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(3..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(4..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(5..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(6..))).with(Style::modern()); }),
detached_action(|t| { t.with(Remove::row(Rows::new(7..))).with(Style::modern()); }),
];

#[rustfmt::skip]
Expand Down
2 changes: 1 addition & 1 deletion tabled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ pub use crate::{tabled::Tabled, tables::Table};
///
/// You can mark fields as hidden in which case they fill be ignored and not be present on a sheet.
///
/// A similar affect could be achieved by the means of a `Disable` setting.
/// A similar affect could be achieved by the means of a `Remove`.
///
/// ```rust,no_run
/// use tabled::Tabled;
Expand Down
40 changes: 20 additions & 20 deletions tabled/src/settings/disable/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! This module contains a [`Disable`] structure which helps to
//! This module contains a [`Remove`] structure which helps to
//! remove an etheir column or row from a [`Table`].
//!
//! # Example
//!
//! ```rust,no_run
//! # use tabled::{Table, settings::{Disable, object::Rows}};
//! # use tabled::{Table, settings::{Remove, object::Rows}};
//! # let data: Vec<&'static str> = Vec::new();
//! let table = Table::new(&data).with(Disable::row(Rows::first()));
//! let table = Table::new(&data).with(Remove::row(Rows::first()));
//! ```
//!
//! [`Table`]: crate::Table
Expand All @@ -18,22 +18,22 @@ use crate::{
settings::{location::Location, TableOption},
};

/// Disable removes particular rows/columns from a [`Table`].
/// Remove removes particular rows/columns from a [`Table`].
///
/// It tries to keeps track of style changes which may occur.
/// But it's not guaranteed will be the way you would expect it to be.
///
/// Generally you should avoid use of [`Disable`] because it's a slow function and modifies the underlying records.
/// Generally you should avoid use of [`Remove`] because it's a slow function and modifies the underlying records.
/// Providing correct data right away is better.
///
/// # Example
///
/// ```
/// use tabled::{Table, settings::{Disable, object::Rows}};
/// use tabled::{Table, settings::{Remove, object::Rows}};
///
/// let data = vec!["Hello", "World", "!!!"];
///
/// let table = Table::new(data).with(Disable::row(Rows::new(1..2))).to_string();
/// let table = Table::new(data).with(Remove::row(Rows::new(1..2))).to_string();
///
/// assert_eq!(
/// table,
Expand All @@ -49,13 +49,13 @@ use crate::{
/// ```
/// [`Table`]: crate::Table
#[derive(Debug)]
pub struct Disable<L, Target> {
pub struct Remove<L, Target> {
locator: L,
target: PhantomData<Target>,
}

impl<L> Disable<L, TargetColumn> {
/// Disable columns.
impl<L> Remove<L, TargetColumn> {
/// Remove columns.
///
/// Available locators are:
///
Expand All @@ -66,14 +66,14 @@ impl<L> Disable<L, TargetColumn> {
/// - [`ByColumnName`]
///
/// ```rust
/// use tabled::{builder::Builder, settings::{Disable, location::ByColumnName, object::Columns}};
/// use tabled::{builder::Builder, settings::{Remove, location::ByColumnName, object::Columns}};
///
/// let mut builder = Builder::default();
/// builder.push_record(["col1", "col2", "col3"]);
/// builder.push_record(["Hello", "World", "1"]);
///
/// let table = builder.build()
/// .with(Disable::column(ByColumnName::new("col3")))
/// .with(Remove::column(ByColumnName::new("col3")))
/// .to_string();
///
/// assert_eq!(
Expand All @@ -99,8 +99,8 @@ impl<L> Disable<L, TargetColumn> {
}
}

impl<L> Disable<L, TargetRow> {
/// Disable rows.
impl<L> Remove<L, TargetRow> {
/// Remove rows.
///
/// Available locators are:
///
Expand All @@ -110,14 +110,14 @@ impl<L> Disable<L, TargetRow> {
/// - [`LastRow`]
///
/// ```rust
/// use tabled::{settings::{Disable, object::Rows}, builder::Builder};
/// use tabled::{settings::{Remove, object::Rows}, builder::Builder};
///
/// let mut builder = Builder::default();
/// builder.push_record(["col1", "col2", "col3"]);
/// builder.push_record(["Hello", "World", "1"]);
///
/// let table = builder.build()
/// .with(Disable::row(Rows::first()))
/// .with(Remove::row(Rows::first()))
/// .to_string();
///
/// assert_eq!(
Expand All @@ -140,15 +140,15 @@ impl<L> Disable<L, TargetRow> {
}
}

/// A marker struct for [`Disable`].
/// A marker struct for [`Remove`].
#[derive(Debug)]
pub struct TargetRow;

/// A marker struct for [`Disable`].
/// A marker struct for [`Remove`].
#[derive(Debug)]
pub struct TargetColumn;

impl<L, R, D, C> TableOption<R, C, D> for Disable<L, TargetColumn>
impl<L, R, D, C> TableOption<R, C, D> for Remove<L, TargetColumn>
where
L: Location<R, Coordinate = usize>,
R: Records + Resizable,
Expand All @@ -171,7 +171,7 @@ where
}
}

impl<L, R, D, C> TableOption<R, C, D> for Disable<L, TargetRow>
impl<L, R, D, C> TableOption<R, C, D> for Remove<L, TargetRow>
where
L: Location<R, Coordinate = usize>,
R: ExactRecords + Resizable,
Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub use self::{
pub use self::{
color::Color,
concat::Concat,
disable::Disable,
disable::Remove,
duplicate::Dup,
format::Format,
height::Height,
Expand Down
18 changes: 9 additions & 9 deletions tabled/tests/settings/disable_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ use tabled::settings::{
location::ByColumnName,
object::{Columns, Rows, Segment},
style::{HorizontalLine, Style},
Alignment, Disable, Modify,
Alignment, Modify, Remove,
};

use crate::matrix::Matrix;
use testing_table::test_table;

test_table!(
disable_rows,
Matrix::new(3, 3).with(Disable::row(Rows::new(1..=2))),
Matrix::new(3, 3).with(Remove::row(Rows::new(1..=2))),
"+---+----------+----------+----------+"
"| N | column 0 | column 1 | column 2 |"
"+---+----------+----------+----------+"
Expand All @@ -22,7 +22,7 @@ test_table!(

test_table!(
disable_header,
Matrix::new(3, 3).with(Style::psql()).with(Disable::row(Rows::first())),
Matrix::new(3, 3).with(Style::psql()).with(Remove::row(Rows::first())),
" 0 | 0-0 | 0-1 | 0-2 "
"---+-----+-----+-----"
" 1 | 1-0 | 1-1 | 1-2 "
Expand All @@ -33,15 +33,15 @@ test_table!(
disable_all_table_via_rows,
Matrix::new(3, 3)
.with(Style::psql())
.with(Disable::row(Columns::new(..))),
.with(Remove::row(Columns::new(..))),
""
);

test_table!(
disable_header_with_new_styling,
Matrix::new(3, 3)
.with(Modify::new(Segment::all()).with(Alignment::left()))
.with(Disable::row(Rows::new(..1)))
.with(Remove::row(Rows::new(..1)))
.with(Style::modern().remove_horizontal().horizontals([(1, HorizontalLine::inherit(Style::modern()))])),
"┌───┬─────┬─────┬─────┐"
"│ 0 │ 0-0 │ 0-1 │ 0-2 │"
Expand All @@ -53,7 +53,7 @@ test_table!(

test_table!(
disable_columns,
Matrix::new(3, 3).with(Style::psql()).with(Disable::column(Columns::first())),
Matrix::new(3, 3).with(Style::psql()).with(Remove::column(Columns::first())),
" column 0 | column 1 | column 2 "
"----------+----------+----------"
" 0-0 | 0-1 | 0-2 "
Expand All @@ -64,8 +64,8 @@ test_table!(
test_table!(
disable_column_by_name,
Matrix::new(3, 3).with(Style::psql())
.with(Disable::column(ByColumnName::new("column 1")))
.with(Disable::column(ByColumnName::new("column 3"))),
.with(Remove::column(ByColumnName::new("column 1")))
.with(Remove::column(ByColumnName::new("column 3"))),
" N | column 0 | column 2 "
"---+----------+----------"
" 0 | 0-0 | 0-2 "
Expand All @@ -78,6 +78,6 @@ test_table!(
Matrix::new(3, 3)
.with(Style::psql())
.with(Modify::new(Segment::all()).with(Alignment::left()))
.with(Disable::column(Columns::new(..))),
.with(Remove::column(Columns::new(..))),
""
);
14 changes: 7 additions & 7 deletions tabled/tests/settings/extract_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use tabled::{
builder::Builder,
settings::{
object::{Rows, Segment},
Alignment, Disable, Extract, Format, Modify, Padding,
Alignment, Extract, Format, Modify, Padding, Remove,
},
};

Expand Down Expand Up @@ -181,15 +181,15 @@ test_table!(

test_table!(
extract_inside_test,
Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(1..2, 1..2)),
Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(1..2, 1..2)),
"+-----+"
"| 1-0 |"
"+-----+"
);

test_table!(
extract_left_test,
Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(.., ..1)),
Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(.., ..1)),
"+---+"
"| 0 |"
"+---+"
Expand All @@ -201,7 +201,7 @@ test_table!(

test_table!(
extract_right_test,
Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(.., 2..)),
Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(.., 2..)),
"+-----+-----+"
"| 0-1 | 0-2 |"
"+-----+-----+"
Expand All @@ -213,15 +213,15 @@ test_table!(

test_table!(
extract_top_test,
Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(..1, ..)),
Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(..1, ..)),
"+---+-----+-----+-----+"
"| 0 | 0-0 | 0-1 | 0-2 |"
"+---+-----+-----+-----+"
);

test_table!(
extract_bottom_test,
Matrix::new(3, 3).with(Disable::row(Rows::first())).with(Extract::segment(2.., ..)),
Matrix::new(3, 3).with(Remove::row(Rows::first())).with(Extract::segment(2.., ..)),
"+---+-----+-----+-----+"
"| 2 | 2-0 | 2-1 | 2-2 |"
"+---+-----+-----+-----+"
Expand All @@ -230,7 +230,7 @@ test_table!(
test_table!(
extract_all_test,
Matrix::new(3, 3)
.with(Disable::row(Rows::first()))
.with(Remove::row(Rows::first()))
.with(Extract::segment(3.., 3..)),
""
);
Expand Down

0 comments on commit 9fe5c71

Please sign in to comment.