summaryrefslogtreecommitdiffstats
path: root/examples/formatting.rs
diff options
context:
space:
mode:
Diffstat (limited to 'examples/formatting.rs')
-rw-r--r--examples/formatting.rs173
1 files changed, 86 insertions, 87 deletions
diff --git a/examples/formatting.rs b/examples/formatting.rs
index d994796..a3cbc51 100644
--- a/examples/formatting.rs
+++ b/examples/formatting.rs
@@ -1,87 +1,86 @@
-#[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();
-
- // Customized format with unicode
- // Example to print
- // ┌─────────────┬────────────┐
- // | Title 1 | Title 2 |
- // ├─────────────┼────────────┤
- // | Value 1 | Value 2 |
- // ├─────────────┼────────────┤
- // | Value three | Value four |
- // └─────────────┴────────────┘
- println!("With unicode:");
- table.set_format(
- format::FormatBuilder::new()
- .column_separator('|')
- .borders('|')
- .separators( &[format::LinePosition::Top], format::LineSeparator::new('─', '┬', '┌', '┐'))
- .separators( &[format::LinePosition::Intern], format::LineSeparator::new('─', '┼', '├', '┤'))
- .separators( &[format::LinePosition::Bottom], format::LineSeparator::new('─', '┴', '└', '┘'))
- .padding(1, 1)
- .build()
- );
- table.printstd();
-}
+#[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();
+
+ // Customized format with unicode
+ // Example to print
+ // ┌─────────────┬────────────┐
+ // | Title 1 | Title 2 |
+ // ├─────────────┼────────────┤
+ // | Value 1 | Value 2 |
+ // ├─────────────┼────────────┤
+ // | Value three | Value four |
+ // └─────────────┴────────────┘
+ println!("With unicode:");
+ table.set_format(format::FormatBuilder::new()
+ .column_separator('|')
+ .borders('|')
+ .separators(&[format::LinePosition::Top],
+ format::LineSeparator::new('─', '┬', '┌', '┐'))
+ .separators(&[format::LinePosition::Intern],
+ format::LineSeparator::new('─', '┼', '├', '┤'))
+ .separators(&[format::LinePosition::Bottom],
+ format::LineSeparator::new('─', '┴', '└', '┘'))
+ .padding(1, 1)
+ .build());
+ table.printstd();
+}