diff options
author | Pierre-Henri Symoneaux <phsym@users.noreply.github.com> | 2017-06-06 21:10:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-06 21:10:42 +0200 |
commit | cf2a344d8f735f9fe7b2150f0cd6964b980cccdf (patch) | |
tree | e453b8caa85936114e875cc2b0184c5bacc8c24f | |
parent | 38aaa2d7dd1d8e641d5ddefcfc2283d95ed68306 (diff) | |
parent | 5c69ec246fa3d6f4276a0d2f33ec684520e2256f (diff) |
Merge pull request #61 from hcpl/examples
Add and fix examples and tests
-rw-r--r-- | examples/formatting.rs | 24 | ||||
-rw-r--r-- | src/lib.rs | 12 |
2 files changed, 25 insertions, 11 deletions
diff --git a/examples/formatting.rs b/examples/formatting.rs index a3cbc51..7822866 100644 --- a/examples/formatting.rs +++ b/examples/formatting.rs @@ -64,16 +64,16 @@ fn main() { // Customized format with unicode // Example to print // ┌─────────────┬────────────┐ - // | Title 1 | Title 2 | + // │ Title 1 │ Title 2 │ // ├─────────────┼────────────┤ - // | Value 1 | Value 2 | + // │ Value 1 │ Value 2 │ // ├─────────────┼────────────┤ - // | Value three | Value four | + // │ Value three │ Value four │ // └─────────────┴────────────┘ println!("With unicode:"); table.set_format(format::FormatBuilder::new() - .column_separator('|') - .borders('|') + .column_separator('│') + .borders('│') .separators(&[format::LinePosition::Top], format::LineSeparator::new('─', '┬', '┌', '┐')) .separators(&[format::LinePosition::Intern], @@ -83,4 +83,18 @@ fn main() { .padding(1, 1) .build()); table.printstd(); + + // Customized format with unicode and different padding + // Example to print + // ┌───────────────┬──────────────┐ + // │ Title 1 │ Title 2 │ + // ├───────────────┼──────────────┤ + // │ Value 1 │ Value 2 │ + // ├───────────────┼──────────────┤ + // │ Value three │ Value four │ + // └───────────────┴──────────────┘ + // Change individual format settings + println!("With unicode and padding:"); + table.get_format().padding(2, 2); + table.printstd(); } @@ -773,7 +773,7 @@ mod tests { table.add_row(Row::new(vec![Cell::new("def"), Cell::new("bc"), Cell::new("a")])); table.set_titles(Row::new(vec![Cell::new("t1"), Cell::new("t2"), Cell::new("t3")])); table.get_format().indent(8); - let out = r" +-----+----+-----+ + let out = " +-----+----+-----+ | t1 | t2 | t3 | +=====+====+=====+ | a | bc | def | @@ -816,8 +816,8 @@ mod tests { fn test_unicode_separators() { let mut table = Table::new(); table.set_format(format::FormatBuilder::new() - .column_separator('|') - .borders('|') + .column_separator('│') + .borders('│') .separators(&[format::LinePosition::Top], format::LineSeparator::new('─', '┬', @@ -840,11 +840,11 @@ mod tests { table.set_titles(Row::new(vec![Cell::new("t1"), Cell::new("t2"), Cell::new("t3")])); let out = "\ ┌────┬────┬────┐ -| t1 | t2 | t3 | +│ t1 │ t2 │ t3 │ ├────┼────┼────┤ -| 1 | 1 | 1 | +│ 1 │ 1 │ 1 │ ├────┼────┼────┤ -| 2 | 2 | 2 | +│ 2 │ 2 │ 2 │ └────┴────┴────┘ "; println!("{}", out); |