summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-01-19 00:07:17 +0100
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-01-19 00:07:17 +0100
commitfd6646c58e98b837814be4cc3d428ffa209bd45d (patch)
treeb9d6938f94c74954521a6f255701ab614bdf5c93 /examples
parent65aedffc22c05b4b00d6e14c6711bd905a435e40 (diff)
Added an formatting example file
Changed line separator constants visibility to private
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();
+}