Skip to content

Commit

Permalink
Change CompactConfig back to self
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt committed Feb 3, 2025
1 parent 4843370 commit f3277c9
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 82 deletions.
18 changes: 9 additions & 9 deletions papergrid/examples/common_grid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ const fn generate_table_config() -> CompactConfig {
intersection: Some('+'),
};

let mut cfg = CompactConfig::new();
cfg.set_borders(STYLE);
cfg.set_alignment_horizontal(AlignmentHorizontal::Center);
cfg.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::spaced(0),
Indent::spaced(0),
));
let cfg = CompactConfig::new()
.set_borders(STYLE)
.set_alignment_horizontal(AlignmentHorizontal::Center)
.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::spaced(0),
Indent::spaced(0),
));

cfg
}
18 changes: 9 additions & 9 deletions papergrid/examples/common_grid_no_std.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ const fn generate_table_config() -> CompactConfig {
intersection: Some('+'),
};

let mut cfg = CompactConfig::new();
cfg.set_borders(STYLE);
cfg.set_alignment_horizontal(AlignmentHorizontal::Center);
cfg.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::spaced(3),
Indent::spaced(0),
));
let cfg = CompactConfig::new()
.set_borders(STYLE)
.set_alignment_horizontal(AlignmentHorizontal::Center)
.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::spaced(3),
Indent::spaced(0),
));

cfg
}
Expand Down
21 changes: 14 additions & 7 deletions papergrid/src/config/compact/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ impl CompactConfig {
}

/// Set grid margin.
pub const fn set_margin(&mut self, margin: Sides<Indent>) {
pub const fn set_margin(mut self, margin: Sides<Indent>) -> Self {
self.margin = margin;
self
}

/// Returns a grid margin.
Expand All @@ -55,8 +56,9 @@ impl CompactConfig {
}

/// Set the [`Borders`] value as correct one.
pub const fn set_borders(&mut self, borders: Borders<char>) {
pub const fn set_borders(mut self, borders: Borders<char>) -> Self {
self.borders = borders;
self
}

/// Returns a current [`Borders`] structure.
Expand All @@ -70,8 +72,9 @@ impl CompactConfig {
}

/// Set a padding to a given cells.
pub const fn set_padding(&mut self, padding: Sides<Indent>) {
pub const fn set_padding(mut self, padding: Sides<Indent>) -> Self {
self.padding = padding;
self
}

/// Get a padding for a given.
Expand All @@ -80,8 +83,9 @@ impl CompactConfig {
}

/// Set a horizontal alignment.
pub const fn set_alignment_horizontal(&mut self, alignment: AlignmentHorizontal) {
pub const fn set_alignment_horizontal(mut self, alignment: AlignmentHorizontal) -> Self {
self.halignment = alignment;
self
}

/// Get a alignment horizontal.
Expand All @@ -90,13 +94,15 @@ impl CompactConfig {
}

/// Sets colors of border carcass on the grid.
pub const fn set_borders_color(&mut self, borders: Borders<ANSIStr<'static>>) {
pub const fn set_borders_color(mut self, borders: Borders<ANSIStr<'static>>) -> Self {
self.border_colors = borders;
self
}

/// Set colors for a margin.
pub const fn set_margin_color(&mut self, color: Sides<ANSIStr<'static>>) {
pub const fn set_margin_color(mut self, color: Sides<ANSIStr<'static>>) -> Self {
self.margin_color = color;
self
}

/// Returns a margin color.
Expand All @@ -105,8 +111,9 @@ impl CompactConfig {
}

/// Set a padding to a given cells.
pub const fn set_padding_color(&mut self, color: Sides<ANSIStr<'static>>) {
pub const fn set_padding_color(mut self, color: Sides<ANSIStr<'static>>) -> Self {
self.padding_color = color;
self
}

/// Set a padding to a given cells.
Expand Down
2 changes: 1 addition & 1 deletion tabled/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ assert_table!(
"| Hare | Drew DeVault | 2022 |"
"'------------------------------'"
);
```
```
14 changes: 7 additions & 7 deletions tabled/src/grid/config/compact_multiline_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl CompactMultilineConfig {

/// Set grid margin.
pub fn set_margin(&mut self, margin: Sides<Indent>) {
self.config.set_margin(margin);
self.config = self.config.set_margin(margin);
}

/// Returns a grid margin.
Expand All @@ -54,7 +54,7 @@ impl CompactMultilineConfig {

/// Set the [`Borders`] value as correct one.
pub fn set_borders(&mut self, borders: Borders<char>) {
self.config.set_borders(borders)
self.config = self.config.set_borders(borders);
}

/// Returns a current [`Borders`] structure.
Expand All @@ -69,7 +69,7 @@ impl CompactMultilineConfig {

/// Set a padding to a given cells.
pub fn set_padding(&mut self, padding: Sides<Indent>) {
self.config.set_padding(padding)
self.config = self.config.set_padding(padding)
}

/// Get a padding for a given.
Expand All @@ -79,7 +79,7 @@ impl CompactMultilineConfig {

/// Set a horizontal alignment.
pub fn set_alignment_horizontal(&mut self, alignment: AlignmentHorizontal) {
self.config.set_alignment_horizontal(alignment)
self.config = self.config.set_alignment_horizontal(alignment)
}

/// Get a alignment horizontal.
Expand All @@ -89,12 +89,12 @@ impl CompactMultilineConfig {

/// Sets colors of border carcass on the grid.
pub fn set_borders_color(&mut self, borders: Borders<ANSIStr<'static>>) {
self.config.set_borders_color(borders)
self.config = self.config.set_borders_color(borders)
}

/// Set colors for a margin.
pub fn set_margin_color(&mut self, color: Sides<ANSIStr<'static>>) {
self.config.set_margin_color(color)
self.config = self.config.set_margin_color(color)
}

/// Returns a margin color.
Expand All @@ -104,7 +104,7 @@ impl CompactMultilineConfig {

/// Set a padding color to all cells.
pub fn set_padding_color(&mut self, color: Sides<ANSIStr<'static>>) {
self.config.set_padding_color(color)
self.config = self.config.set_padding_color(color)
}

/// get a padding color.
Expand Down
31 changes: 10 additions & 21 deletions tabled/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,33 +167,22 @@
#![cfg_attr(not(all(feature = "derive", feature = "std")), doc = "```ignore")]
//! use tabled::{Tabled, Table};
//! use testing_table::assert_table;
//! use std::iter::once;
//!
//! #[derive(Tabled)]
//! struct Data(
//! #[tabled(rename = "word")]
//! String,
//! #[tabled(rename = "id")]
//! usize,
//! );
//!
//! let data = once(Data(String::from("Hello"), 0))
//! .chain(once(Data(String::from("World"), 1)))
//! .chain(once(Data(String::from("!!!"), 2)));
//! let data = (0..3).map(|i| [i, i * 2, i * 3]);
//!
//! let mut table = Table::new(data);
//!
//! assert_table!(
//! table,
//! "+-------+----+"
//! "| word | id |"
//! "+-------+----+"
//! "| Hello | 0 |"
//! "+-------+----+"
//! "| World | 1 |"
//! "+-------+----+"
//! "| !!! | 2 |"
//! "+-------+----+"
//! "+---+---+---+"
//! "| 0 | 1 | 2 |"
//! "+---+---+---+"
//! "| 0 | 0 | 0 |"
//! "+---+---+---+"
//! "| 1 | 2 | 3 |"
//! "+---+---+---+"
//! "| 2 | 4 | 6 |"
//! "+---+---+---+"
//! );
//! ```
//!
Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/alignment/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<R, D> TableOption<R, ColoredConfig, D> for Alignment {
impl<R, D> TableOption<R, CompactConfig, D> for Alignment {
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
if let Horizontal(a) = self.inner {
cfg.set_alignment_horizontal(a)
*cfg = cfg.set_alignment_horizontal(a);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/margin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ impl<R, D> TableOption<R, ColoredConfig, D> for Margin {

impl<R, D> TableOption<R, CompactConfig, D> for Margin {
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
cfg.set_margin(self.indent);
*cfg = cfg.set_margin(self.indent);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/margin_color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
{
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
let colors = self.colors.convert_into();
cfg.set_margin_color(colors);
*cfg = cfg.set_margin_color(colors);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/padding/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<R, D> TableOption<R, ColoredConfig, D> for Padding {

impl<R, D> TableOption<R, CompactConfig, D> for Padding {
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
cfg.set_padding(self.indent);
*cfg = cfg.set_padding(self.indent);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/padding_color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ where
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
let c = self.colors.clone();
let colors = Sides::new(c.left.into(), c.right.into(), c.top.into(), c.bottom.into());
cfg.set_padding_color(colors);
*cfg = cfg.set_padding_color(colors);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/style/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1453,7 +1453,7 @@ impl<T, B, L, R, H, V, Data, Dims, const HSIZE: usize, const VSIZE: usize>
TableOption<Data, CompactConfig, Dims> for Style<T, B, L, R, H, V, HSIZE, VSIZE>
{
fn change(self, _: &mut Data, cfg: &mut CompactConfig, _: &mut Dims) {
cfg.set_borders(self.borders);
*cfg = cfg.set_borders(self.borders);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/style/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl<R, D> TableOption<R, ColoredConfig, D> for Borders<char> {

impl<R, D> TableOption<R, CompactConfig, D> for Borders<char> {
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
cfg.set_borders(self);
*cfg = cfg.set_borders(self);
}
}

Expand Down
2 changes: 1 addition & 1 deletion tabled/src/settings/themes/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ impl<R, D> TableOption<R, ColoredConfig, D> for Theme {

impl<R, D> TableOption<R, CompactConfig, D> for Theme {
fn change(self, _: &mut R, cfg: &mut CompactConfig, _: &mut D) {
cfg.set_borders(self.chars);
*cfg = cfg.set_borders(self.chars);
}
}

Expand Down
19 changes: 9 additions & 10 deletions tabled/src/tables/compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,15 @@ where
}

const fn create_config() -> CompactConfig {
let mut cfg = CompactConfig::new();
cfg.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::zero(),
Indent::zero(),
));
cfg.set_alignment_horizontal(AlignmentHorizontal::Left);
cfg.set_borders(Style::ascii().get_borders());
cfg
CompactConfig::new()
.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::zero(),
Indent::zero(),
))
.set_alignment_horizontal(AlignmentHorizontal::Left)
.set_borders(Style::ascii().get_borders())
}

impl<R, D> TableOption<R, CompactConfig, D> for CompactConfig {
Expand Down
19 changes: 9 additions & 10 deletions tabled/src/tables/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,16 +352,15 @@ fn get_count_columns<T>(opts: &Settings, buf: &[Vec<T>]) -> usize {
}

const fn create_config() -> CompactConfig {
let mut cfg = CompactConfig::new();
cfg.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::zero(),
Indent::zero(),
));
cfg.set_alignment_horizontal(AlignmentHorizontal::Left);
cfg.set_borders(Style::ascii().get_borders());
cfg
CompactConfig::new()
.set_padding(Sides::new(
Indent::spaced(1),
Indent::spaced(1),
Indent::zero(),
Indent::zero(),
))
.set_alignment_horizontal(AlignmentHorizontal::Left)
.set_borders(Style::ascii().get_borders())
}

fn build_records<I>(
Expand Down

0 comments on commit f3277c9

Please sign in to comment.