summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-01-20 12:01:42 +0100
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-01-20 12:01:42 +0100
commit73298cc53cbd88b0eed87be132787e33d965c883 (patch)
treeed4874ba234477f3f82f26653d1ad4286f49f9d2 /examples
parent6c925d457249b369b7a1968df38875e545c0915b (diff)
parentb770f25eb61404c79e260ac951708369692b271c (diff)
Merge branch 'master' into ascription_fix
Conflicts: .travis.yml src/row.rs
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();
+}