Skip to content

Commit

Permalink
Merge pull request #37 from zhiburt/refactorings2
Browse files Browse the repository at this point in the history
tabled/ change style functions to constants
  • Loading branch information
zhiburt committed Nov 25, 2021
2 parents d5aa14d + f0f2406 commit a36ce95
Show file tree
Hide file tree
Showing 22 changed files with 173 additions and 148 deletions.
12 changes: 6 additions & 6 deletions README.md
Expand Up @@ -123,7 +123,7 @@ A list of ready to use styles.
Styles can be chosen by passing a `Style` argument option.

```rust
let table = Table::new(&data).with(Style::psql());
let table = Table::new(&data).with(Style::PSQL);
```

### Default
Expand Down Expand Up @@ -200,7 +200,7 @@ let table = Table::new(&data).with(Style::psql());
You can modify existing styles to fits your needs.

```rust
let style = tabled::Style::noborder()
let style = tabled::Style::NO_BORDER
.frame_bottom(Some(Line::short('*', ' '')))
.split(Some(Line::short(' ', ' ')))
.inner(' ');
Expand All @@ -226,7 +226,7 @@ The `Format` function provides an interface for a modification of cells.
```rust
Table::new(&data)
.with(Style::psql()),
.with(Style::PSQL),
.with(Modify::new(Column(..)).with(Format(|s| format!("<< {} >>", s))))
.with(Modify::new(Row(..1)).with(Format(|s| format!("Head {}", s))));
```
Expand All @@ -235,7 +235,7 @@ It's also possible to use functions with signature `Fn(&str) -> String` as a for

```rust
Table::new(&data)
.with(Style::psql()),
.with(Style::PSQL),
.with(Modify::new(Column(..)).with(|s: &str| format!("<< {} >>", s)))
.with(Modify::new(Row(..1)).with(str::to_lowercase));
```
Expand Down Expand Up @@ -337,7 +337,7 @@ The library doesn't bind you in usage of any color library but to be able to wor

```rust
Table::new(&data)
.with(Style::psql())
.with(Style::PSQL)
.with(Modify::new(Column(..1)).with(Format(|s| s.red().to_string())))
.with(Modify::new(Column(1..2)).with(Format(|s| s.blue().to_string())))
.with(Modify::new(Column(2..)).with(Format(|s| s.green().to_string())));
Expand Down Expand Up @@ -475,7 +475,7 @@ let data = vec![
(Developer("Maxim Zhiburt"), Domain::Unknown),
];

let table = Table::new(data).with(Style::psql()).to_string();
let table = Table::new(data).with(Style::PSQL).to_string();

assert_eq!(
table,
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Expand Up @@ -44,7 +44,7 @@ fn main() {
];

let table = Table::new(&data)
.with(Style::pseudo())
.with(Style::PSEUDO)
.with(Modify::new(Head).with(Alignment::Horizontal(AlignmentHorizontal::Center)))
.with(Modify::new(Row(1..)).with(Alignment::Horizontal(AlignmentHorizontal::Left)));

Expand Down
2 changes: 1 addition & 1 deletion examples/color.rs
Expand Up @@ -48,7 +48,7 @@ fn main() {
];

let table = Table::new(&data)
.with(Style::psql())
.with(Style::PSQL)
.with(Modify::new(Head).with(Alignment::center_horizontal()))
.with(Modify::new(Row(1..)).with(Alignment::left()))
.with(Modify::new(Column(1..2)).with(Format(|s| s.blue().to_string())))
Expand Down
2 changes: 1 addition & 1 deletion examples/default_array.rs
Expand Up @@ -5,7 +5,7 @@ use tabled::{Style, Table};

fn main() {
let data = matrix::<10>();
let table = Table::new(&data).with(Style::pseudo());
let table = Table::new(&data).with(Style::PSEUDO);

println!("{}", table);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/format.rs
Expand Up @@ -34,7 +34,7 @@ fn main() {
];

let table = Table::new(&data)
.with(Style::github_markdown())
.with(Style::GITHUB_MARKDOWN)
.with(Modify::new(Row(..1)).with(FormatWithIndex(|_, _, column| column.to_string())))
.with(Modify::new(Row(1..2).not(Column(..1))).with(FormatFrom(vec!["qwe", "asd"])))
.with(Modify::new(Column(..1).not(Row(..1))).with(Format(|s| format!("{}...", s))));
Expand Down
2 changes: 1 addition & 1 deletion examples/inline.rs
Expand Up @@ -40,7 +40,7 @@ fn main() {
];

let table = Table::new(&data)
.with(Style::pseudo())
.with(Style::PSEUDO)
.with(Modify::new(Full).with(Indent::new(1, 1, 0, 0)))
.with(Modify::new(Head).with(Alignment::Horizontal(AlignmentHorizontal::Left)))
.with(Modify::new(Row(1..)).with(Alignment::Horizontal(AlignmentHorizontal::Center)));
Expand Down
2 changes: 1 addition & 1 deletion examples/panel.rs
Expand Up @@ -36,7 +36,7 @@ fn main() {
let table = Table::new(&data)
.with(Header("Tabled Releases"))
.with(Footer(format!("N - {}", data.len())))
.with(Style::pseudo())
.with(Style::PSEUDO)
.with(Modify::new(Full).with(Alignment::Horizontal(AlignmentHorizontal::Center)));

println!("{}", table);
Expand Down
2 changes: 1 addition & 1 deletion examples/rotate.rs
Expand Up @@ -28,7 +28,7 @@ fn main() {

let table = Table::new(&data)
.with(Rotate::Left)
.with(Style::noborder())
.with(Style::NO_BORDER)
.with(Modify::new(Full).with(Indent::new(1, 1, 0, 0)));

println!("{}", table);
Expand Down
2 changes: 1 addition & 1 deletion examples/width.rs
Expand Up @@ -10,7 +10,7 @@ fn main() {
["Hello World", "[[[[[[[[[[[[[[[[["],
];

let table = Table::new(&data).with(Style::github_markdown()).with(
let table = Table::new(&data).with(Style::GITHUB_MARKDOWN).with(
Modify::new(Full)
.with(MaxWidth::truncating(10, "..."))
.with(Alignment::left()),
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Expand Up @@ -120,7 +120,7 @@
//! (Developer("Maxim Zhiburt"), Domain::Unknown),
//! ];
//!
//! let table = Table::new(data).with(Style::psql()).to_string();
//! let table = Table::new(data).with(Style::PSQL).to_string();
//!
//! assert_eq!(
//! table,
Expand Down Expand Up @@ -235,7 +235,7 @@ pub trait CellOption {
/// use tabled::{Table, Style, Alignment, Full, Modify};
/// let data = vec!["Hello", "2021"];
/// let table = Table::new(&data)
/// .with(Style::psql())
/// .with(Style::PSQL)
/// .with(Modify::new(Full).with(Alignment::left()));
/// println!("{}", table);
/// ```
Expand All @@ -249,7 +249,7 @@ impl Table {
let grid = build_grid(iter);

let table = Self { grid };
table.with(Style::ascii())
table.with(Style::ASCII)
}

/// With is a generic function which applies options to the [Table].
Expand Down

0 comments on commit a36ce95

Please sign in to comment.