Skip to content

Commit

Permalink
Merge 7a72c8c into 6b8faa4
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiburt authored Jul 16, 2021
2 parents 6b8faa4 + 7a72c8c commit b3e93ef
Show file tree
Hide file tree
Showing 12 changed files with 256 additions and 171 deletions.
2 changes: 1 addition & 1 deletion examples/default_array.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The example can be run by this command
//! `cargo run --example basic`
//! `cargo run --example default_array`

use tabled::{Style, Table};

Expand Down
2 changes: 1 addition & 1 deletion examples/inline.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! The example can be run by this command
//! `cargo run --example inline_structure`
//! `cargo run --example inline`

use tabled::{
papergrid::AlignmentHorizontal, Alignment, Full, Head, Indent, Modify, Row, Style, Table,
Expand Down
18 changes: 18 additions & 0 deletions examples/width.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//! The example can be run by this command
//! `cargo run --example width`

use tabled::{Full, MaxWidth, Modify, Style, Table};

fn main() {
let data = [
["Hello World", "123123123231"],
["Hello World", "zxczczxcxczxczxc"],
["Hello World", "[[[[[[[[[[[[[[[[["],
];

let table = Table::new(&data)
.with(Style::github_markdown())
.with(Modify::new(Full).with(MaxWidth(10, "...")));

println!("{}", table);
}
2 changes: 1 addition & 1 deletion src/alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::CellOption;
use crate::Table;
use papergrid::{AlignmentHorizontal, AlignmentVertical, Entity, Grid, Settings};

/// Alignment represent a horizontal and vertical alignemt setting for a [Table].
/// Alignment represent a horizontal and vertical alignemt setting for any cell on a [Table].
///
/// ```rust,no_run
/// # use tabled::{Style, Alignment, Modify, Row, Table};
Expand Down
11 changes: 6 additions & 5 deletions src/disable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ use crate::{bounds_to_usize, TableOption};
use papergrid::Grid;
use std::ops::RangeBounds;

/// Disable represent a disable setting for a [Table].
/// Disable removes particular rows/columns from a [Table].
///
/// ```rust,no_run
/// # use tabled::{Disable, Table};
/// # let data: Vec<&'static str> = Vec::new();
/// let table = Table::new(&data).with(Disable::Row(..1));
/// ```
///
#[derive(Debug)]
pub enum Disable<R: RangeBounds<usize>> {
/// Columns of the grid. Range is used to locate columns.
/// Columns of the grid.
/// Range is used to locate columns.
Column(R),
/// Rows of the grid. Range is used to locate rows.
/// Rows of the grid.
/// Range is used to locate rows.
Row(R),
}

Expand All @@ -34,7 +35,7 @@ impl<R: RangeBounds<usize>> TableOption for Disable<R> {
let (x, y) =
bounds_to_usize(range.start_bound(), range.end_bound(), grid.count_rows());

// It's kindof a bad design that we must controll shift.
// It's kind of a bad design that we must controll shift.
// It basically unveils an implementation...
for (shifted, i) in (x..y).enumerate() {
grid.remove_row(i - shifted);
Expand Down
25 changes: 13 additions & 12 deletions src/formating.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
use crate::CellOption;
use papergrid::{Entity, Grid, Settings};

/// Format a structure which modifies a [Grid]
/// Formatting of particular cells on a [Grid].
///
/// # Example
///
/// ```
/// use tabled::{Table, Format, Row, Modify};
///
/// let data = vec![
/// (0, "Grodno", true),
/// (1, "Minsk", true),
/// (2, "Hamburg", false),
/// (3, "Brest", true),
/// (0, "Grodno", true),
/// (1, "Minsk", true),
/// (2, "Hamburg", false),
/// (3, "Brest", true),
/// ];
///
/// let table = Table::new(&data)
/// .with(Modify::new(Row(1..)).with(Format(|s| { format!(": {} :", s) })))
/// .with(Modify::new(Row(1..)).with(Format(|s| format!(": {} :", s))))
/// .to_string();
///
/// assert_eq!(table, "+-------+-------------+-----------+\n\
Expand Down Expand Up @@ -53,14 +53,15 @@ where
}
}

/// Multiline a helper function for changing multiline content of cell by rows not as a whole.
/// Multiline a helper function for changing multiline content of cell.
/// Using this formatting applied for all rows not to a string as a whole.
///
/// ```rust,no_run
/// use tabled::{Table, Format, multiline, Full, Modify};
/// let data: Vec<&'static str> = Vec::new();
/// let table = Table::new(&data)
/// .with(Modify::new(Full).with(Format(multiline(|s| format!("{}", s)))))
/// .to_string();
/// use tabled::{Table, Format, multiline, Full, Modify};
/// let data: Vec<&'static str> = Vec::new();
/// let table = Table::new(&data)
/// .with(Modify::new(Full).with(Format(multiline(|s| format!("{}", s)))))
/// .to_string();
/// ```
pub fn multiline<F: 'static + Fn(&str) -> String>(f: F) -> Box<dyn Fn(&str) -> String> {
Box::new(move |s: &str| s.lines().map(|s| f(s)).collect::<Vec<_>>().join("\n"))
Expand Down
3 changes: 2 additions & 1 deletion src/indent.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::CellOption;
use papergrid::{Entity, Grid, Settings};

/// Indent is responsible for a left/right/top/bottom indent.
/// Indent is responsible for a left/right/top/bottom indent of particular cells.
///
/// ```rust,no_run
/// # use tabled::{Style, Indent, Row, Table, Modify};
Expand All @@ -12,6 +12,7 @@ use papergrid::{Entity, Grid, Settings};
pub struct Indent(usize, usize, usize, usize);

impl Indent {
/// Construct's an Indent object.
pub fn new(left: usize, right: usize, top: usize, bottom: usize) -> Self {
Self(left, right, top, bottom)
}
Expand Down
Loading

0 comments on commit b3e93ef

Please sign in to comment.