summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorPierre-Henri Symoneaux <phsym@users.noreply.github.com>2016-01-20 11:38:07 +0100
committerPierre-Henri Symoneaux <phsym@users.noreply.github.com>2016-01-20 11:38:07 +0100
commitbb88b9ebe5fa219768d3a4f5e876136e83eca434 (patch)
tree2ba7b4f4b500fcd92e5879c83c96fff4bc707661 /examples
parent468cf90d8571e459fdab99260b219cf19c93fac8 (diff)
parent9e4485373b9dd6079e8baee9ba0b33c2c5e7db69 (diff)
Merge pull request #19 from phsym/refactor_format
Refactored table formatting API
Diffstat (limited to 'examples')
-rw-r--r--examples/formatting.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/examples/formatting.rs b/examples/formatting.rs
new file mode 100644
index 0000000..946d326
--- /dev/null
+++ b/examples/formatting.rs
@@ -0,0 +1,66 @@
+#[macro_use] extern crate prettytable;
+use prettytable::format;
+
+fn main() {
+ let mut table = table!(["Value 1", "Value 2"], ["Value three", "Value four"]);
+ table.set_titles(row!["Title 1", "Title 2"]);
+
+ // Print
+ // +-------------+------------+
+ // | Title 1 | Title 2 |
+ // +-------------+------------+
+ // | Value 1 | Value 2 |
+ // | Value three | Value four |
+ // +-------------+------------+
+ println!("FORMAT_NO_LINESEP_WITH_TITLE :");
+ table.set_format(*format::consts::FORMAT_NO_LINESEP_WITH_TITLE);
+ table.printstd();
+ println!("");
+
+ // Print
+ // -------------------------
+ // Title 1 Title 2
+ // =========================
+ // Value 1 Value 2
+ // -------------------------
+ // Value three Value four
+ // -------------------------
+ println!("FORMAT_NO_COLSEP :");
+ table.set_format(*format::consts::FORMAT_NO_COLSEP);
+ table.printstd();
+ println!("");
+
+ // Print
+ // +-------------------------+
+ // | Title 1 Title 2 |
+ // +=========================+
+ // | Value 1 Value 2 |
+ // +-------------------------+
+ // | Value three Value four |
+ // +-------------------------+
+ println!("FORMAT_BORDERS_ONLY :");
+ table.set_format(*format::consts::FORMAT_BORDERS_ONLY);
+ table.printstd();
+ println!("");
+
+ // Custom format can be implemented using `prettytable::format::FormatBuilder`
+ // Example to print
+ // +-------------+------------+
+ // | Title 1 | Title 2 |
+ // | Value 1 | Value 2 |
+ // | Value three | Value four |
+ // +-------------+------------+
+ println!("Custom :");
+ table.set_format(
+ format::FormatBuilder::new()
+ .column_separator('|')
+ .borders('|')
+ .separators(
+ &[format::LinePosition::Top, format::LinePosition::Bottom],
+ format::LineSeparator::new('-', '+', '+', '+')
+ )
+ .padding(1, 1)
+ .build()
+ );
+ table.printstd();
+}