From 5320d55be62d55a2a2be5458e46b9352cd70edf0 Mon Sep 17 00:00:00 2001 From: Paul Fenwick Date: Sun, 12 Aug 2018 21:43:54 +1000 Subject: README: Document set_titles, use prettyformat::table, plus extra tests! README: - Mention `set_titles()` - Explicitly `use prettytable::format` - Expand sample code to call `set_titles()` and `add_row()`s. lib.rs: - Added test from README code using the longhand FormatBuilder - Added test from README using FORMAT_NO_LINESEP_WITH_TITLE --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index f1bfbb2..5fd42fc 100644 --- a/README.md +++ b/README.md @@ -269,13 +269,14 @@ Configurable settings include: - Junctions - Column separators - Line separators +- Titles (using `table.set_titles()`) To do this, either: - create a new `TableFormat` object, then call setters until you get the desired configuration; - or use the convenient `FormatBuilder` and Builder pattern, shown below ```rust -let mut table = /* Initialize table */; +let mut table = Table::new(); let format = format::FormatBuilder::new() .column_separator('|') .borders('|') @@ -285,6 +286,10 @@ let format = format::FormatBuilder::new() .padding(1, 1) .build(); table.set_format(format); + +table.set_titles(row!["Title 1", "Title 2"]); +table.add_row(row!["Value 1", "Value 2"]); +table.add_row(row!["Value three", "Value four"]); ``` The code above will make the table look like @@ -300,6 +305,8 @@ For convenience, several formats are predefined in `prettytable::format::consts` Some formats and their respective outputs: - ```rust + use prettytable::format; + table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE); ``` ``` @@ -311,6 +318,8 @@ Some formats and their respective outputs: +-------------+------------+ ``` - ```rust + use prettytable::format; + table.set_format(*format::consts::FORMAT_NO_BORDER_LINE_SEPARATOR); ``` ``` -- cgit v1.2.3