From 9e4485373b9dd6079e8baee9ba0b33c2c5e7db69 Mon Sep 17 00:00:00 2001 From: pierresy Date: Tue, 19 Jan 2016 10:14:51 +0100 Subject: Added a section in README about formatting --- README.md | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'README.md') diff --git a/README.md b/README.md index 652b5eb..9145ef0 100644 --- a/README.md +++ b/README.md @@ -216,4 +216,62 @@ table.slice(2..); // Returns a table with rows starting at index 2 table.slice(..3); // Returns a table with rows until the one at index 3 ``` +## Customize your table look and feel + +You can customize the look and feel of a table by providing it a `prettytable::format::TableFormat`. +For example you can change the characters used for borders, junctions, column separations or line separations. +To proceed, you can create a new `TableFormat` object and call the setter methods to configure it, +or you can use the more convenient `prettytable::format::FormatBuilder` structure. + +For example : +```rust +let mut table = /* Initialize table */; +let format = format::FormatBuilder::new() + .column_separator('|') + .borders('|') + .separators( + &[format::LinePosition::Top, format::LinePosition::Bottom], + format::LineSeparator::new('-', '+', '+', '+') + ) + .padding(1, 1) + .build(); +table.set_format(format); +``` +Would give a table like the following +``` ++-------------+------------+ +| Title 1 | Title 2 | +| Value 1 | Value 2 | +| Value three | Value four | ++-------------+------------+ +``` + +For convenience, some predefined formats are provided in the module `prettytable::format::consts`. +For example : +```rust +table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); +``` +Would give a table like the following +``` ++-------------+------------+ +| Title 1 | Title 2 | ++-------------+------------+ +| Value 1 | Value 2 | +| Value three | Value four | ++-------------+------------+ +``` +or +```rust +table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR); +``` +Would give +``` +Title 1 | Title 2 +------------+------------ +Value 1 | Value 2 +Value three | Value four +``` + +Check API documentation for the full list of available predefined formats + Additional examples are provided in documentation and in [examples](./examples/) directory -- cgit v1.2.3 From b770f25eb61404c79e260ac951708369692b271c Mon Sep 17 00:00:00 2001 From: pierresy Date: Wed, 20 Jan 2016 11:24:29 +0100 Subject: Updated version to v0.6.0 in cargo.toml and readme Removed .project file from eclipse IDE --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 9145ef0..a8f7420 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ More often, you will include the library as a dependency to your project. In ord ```toml [dependencies] -prettytable-rs = "^0.5" +prettytable-rs = "^0.6" ``` ## Basic usage -- cgit v1.2.3