Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix README.md #457

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ struct Language {
}

let languages = vec![
Language{ name: "C", designed_by: "Dennis Ritchie", invented_year: 1972 },
Language{ name: "Rust", designed_by: "Graydon Hoare", invented_year: 2010 },
Language{ name: "Go", designed_by: "Rob Pike", invented_year: 2009 },
Language { name: "C", designed_by: "Dennis Ritchie", invented_year: 1972 },
Language { name: "Rust", designed_by: "Graydon Hoare", invented_year: 2010 },
Language { name: "Go", designed_by: "Rob Pike", invented_year: 2009 },
];

let table = Table::new(languages).to_string();
Expand Down Expand Up @@ -210,14 +210,12 @@ If you want to peak style at runtime `Theme` might be better suited for it.
Any `Style` can be customized.
As well as a custom `Style` can be created from scratch.

A style can be used like this.

```rust
use tabled::{Table, Style};

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

#### Styles

Expand Down
22 changes: 22 additions & 0 deletions tabled/src/settings/formatting/charset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::borrow::Cow;

use crate::{
grid::config::Entity,
grid::records::{ExactRecords, PeekableRecords, Records, RecordsMut},
Expand Down Expand Up @@ -72,6 +74,26 @@ impl Charset {
#[derive(Debug, Default, Clone)]
pub struct CleanCharset;

impl CleanCharset {
/// Removes all symbols which may break the layout such as `\t`, `\r` and more.
///
/// Notice that tab is just removed rather then being replaced with spaces.
///
/// # Example
///
/// ```
/// use tabled::settings::formatting::CleanCharset;
///
/// assert_eq!(
/// CleanCharset::clean("Some\ttext\t\twith \\tabs\r\nSome"),
/// "Sometextwith \\tabs\nSome"
/// )
/// ```
pub fn clean(s: &str) -> Cow<'_, str> {
Cow::Owned(clean_charset(s))
}
}

impl<R, D, C> TableOption<R, C, D> for CleanCharset
where
R: Records + ExactRecords + RecordsMut<String> + PeekableRecords,
Expand Down
60 changes: 60 additions & 0 deletions tabled/src/tables/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ impl Table {
///
/// ```
/// use tabled::{Table, Tabled};
/// use testing_table::assert_table;
///
/// #[derive(Tabled)]
/// struct Relationship {
Expand All @@ -112,12 +113,24 @@ impl Table {
/// ];
///
/// let table = Table::new(list);
///
/// assert_table!(
/// table,
/// "+-------+"
/// "| love |"
/// "+-------+"
/// "| true |"
/// "+-------+"
/// "| false |"
/// "+-------+"
/// );
/// ```
///
/// ## Notice that you can pass tuples.
///
/// ```
/// use tabled::{Table, Tabled};
/// use testing_table::assert_table;
///
/// #[derive(Tabled)]
/// struct Relationship {
Expand All @@ -130,19 +143,66 @@ impl Table {
/// ];
///
/// let table = Table::new(list);
///
/// assert_table!(
/// table,
/// "+------+-------+"
/// "| &str | love |"
/// "+------+-------+"
/// "| Kate | true |"
/// "+------+-------+"
/// "| | false |"
/// "+------+-------+"
/// );
/// ```
///
/// ## Notice that you can pass const arrays as well.
///
/// ```
/// use tabled::Table;
/// use testing_table::assert_table;
///
/// let list = vec![
/// ["Kate", "+", "+", "+", "-"],
/// ["", "-", "-", "-", "-"],
/// ];
///
/// let table = Table::new(list);
///
/// assert_table!(
/// table,
/// "+------+---+---+---+---+"
/// "| 0 | 1 | 2 | 3 | 4 |"
/// "+------+---+---+---+---+"
/// "| Kate | + | + | + | - |"
/// "+------+---+---+---+---+"
/// "| | - | - | - | - |"
/// "+------+---+---+---+---+"
/// );
/// ```
///
/// ## As a different way to create a [`Table`], you can use [`Table::from_iter`].
///
/// ```
/// use std::iter::FromIterator;
/// use tabled::Table;
/// use testing_table::assert_table;
///
/// let list = vec![
/// vec!["Kate", "+", "+", "+", "-"],
/// vec!["", "-", "-", "-", "-"],
/// ];
///
/// let table = Table::from_iter(list);
///
/// assert_table!(
/// table,
/// "+------+---+---+---+---+"
/// "| Kate | + | + | + | - |"
/// "+------+---+---+---+---+"
/// "| | - | - | - | - |"
/// "+------+---+---+---+---+"
/// );
/// ```
pub fn new<I, T>(iter: I) -> Self
where
Expand Down
Loading