summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-06-01 00:17:04 +0200
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-06-01 00:17:04 +0200
commite5ffc8a7e74bf508a2a096339a155bd39fdddd26 (patch)
tree4c4f34d043277a5042af507423af48d19d4999b7
parenta757b37d86eba14ef5a8cc3757dee994e3ce5b47 (diff)
Added multiline examples
-rw-r--r--README.md32
-rw-r--r--examples/multiline.rs31
2 files changed, 63 insertions, 0 deletions
diff --git a/README.md b/README.md
index 8beb8b5..17bdb2b 100644
--- a/README.md
+++ b/README.md
@@ -79,4 +79,36 @@ fn main() {
Using the `ptable!` macro would even print it on stdout for you.
+Tables also support multiline cells content. As a consequence, you can print a table into another table (yo dawg ;).
+For example, the following code
+```rust
+let table1 = table!(["ABC", "DEFG", "HIJKLMN"],
+ ["foobar", "bar", "foo"],
+ ["foobar2", "bar2", "foo2"]
+ );
+let table2 = table!(["Title 1", "Title 2"],
+ ["This is\na multiline\ncell", "foo"],
+ ["You dawg ;) You can even\nprint tables\ninto tables", table1]
+ );
+table2.printstd();
+```
+Would print the following text :
+```text
++--------------------------+------------------------------+
+| Title 1 | Title 2 |
++--------------------------+------------------------------+
+| This is | foo |
+| a multiline | |
+| cell | |
++--------------------------+------------------------------+
+| You dawg ;) You can even | +---------+------+---------+ |
+| print tables | | ABC | DEFG | HIJKLMN | |
+| into tables | +---------+------+---------+ |
+| | | foobar | bar | foo | |
+| | +---------+------+---------+ |
+| | | foobar2 | bar2 | foo2 | |
+| | +---------+------+---------+ |
++--------------------------+------------------------------+
+```
+
Additional examples are provided in documentation and in [examples](./examples/) directory
diff --git a/examples/multiline.rs b/examples/multiline.rs
new file mode 100644
index 0000000..93b49fb
--- /dev/null
+++ b/examples/multiline.rs
@@ -0,0 +1,31 @@
+#[macro_use] extern crate tabprint;
+
+/*
+ Following main function will print :
+ +--------------------------+------------------------------+
+ | Title 1 | Title 2 |
+ +--------------------------+------------------------------+
+ | This is | foo |
+ | a multiline | |
+ | cell | |
+ +--------------------------+------------------------------+
+ | You dawg ;) You can even | +---------+------+---------+ |
+ | print tables | | ABC | DEFG | HIJKLMN | |
+ | into tables | +---------+------+---------+ |
+ | | | foobar | bar | foo | |
+ | | +---------+------+---------+ |
+ | | | foobar2 | bar2 | foo2 | |
+ | | +---------+------+---------+ |
+ +--------------------------+------------------------------+
+*/
+fn main() {
+ let table1 = table!(["ABC", "DEFG", "HIJKLMN"],
+ ["foobar", "bar", "foo"],
+ ["foobar2", "bar2", "foo2"]
+ );
+ let table2 = table!(["Title 1", "Title 2"],
+ ["This is\na multiline\ncell", "foo"],
+ ["You dawg ;) You can even\nprint tables\ninto tables", table1]
+ );
+ table2.printstd();
+}