summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-11-09 19:12:23 +0100
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2015-11-09 19:12:23 +0100
commit6016d66bc09e32c4174297e8ebb106841f8c89ba (patch)
tree1e1a2cad830318eec0772e258e8668fb0b274bd5
parent558bccf0dd5a07e2ec0ebab9e46ed14837167a8a (diff)
#2 : Added an example file (style.rs) and updated some additional doc
-rw-r--r--examples/style.rs38
-rw-r--r--src/lib.rs15
-rw-r--r--src/row.rs2
3 files changed, 55 insertions, 0 deletions
diff --git a/examples/style.rs b/examples/style.rs
new file mode 100644
index 0000000..ca608c6
--- /dev/null
+++ b/examples/style.rs
@@ -0,0 +1,38 @@
+#[macro_use] extern crate prettytable;
+extern crate term;
+use prettytable::Table;
+use prettytable::row::Row;
+use prettytable::cell::Cell;
+
+use term::{Attr, color};
+
+#[allow(dead_code)]
+fn main() {
+ let _ = table!();
+ let mut table = Table::new();
+ // Add style to a cell
+ table.add_row(row![FrByb:"ABC", "DEFG", "HIJKLMN"]);
+ // Add style to a full row
+ table.add_row(row![FY -> "styled", "bar", "foo"]);
+ table.add_row(Row::new(vec![
+ Cell::new("foobar2"),
+ // Create a cell with a red foreground color
+ Cell::new("bar2").with_style(Attr::ForegroundColor(color::RED)),
+ // Create a cell with red foreground color, yellow background color, with bold characters
+ Cell::new("foo2").style_spec("FrByb"),
+ // Using the cell! macro
+ cell!(Fr:"red")])
+ );
+
+ table.printstd();
+
+ // Print a table with some styles on it :
+ // FrBybl means : Foregound red, Background yellow, bold, left align
+ ptable!([FrBybl:"A", "B", FrBybr:"C"], [123, 234, 345, 456], [Fg -> 1, 2, 3]);
+
+ // You can also apply style to full rows :
+ let mut table = table!([Frb -> "A", "B", "C"], [1, 2, 3, 4], ["A\nBCCZZZ\nDDD", 2, table]);
+ // Set a title line, with all text centered in the cell
+ table.set_titles(row![c -> "Title 1", "Title 2"]);
+ table.printstd();
+}
diff --git a/src/lib.rs b/src/lib.rs
index 501c445..f4f1361 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -265,6 +265,21 @@ impl <'a> std::iter::Iterator for ColumnIterMut<'a> {
/// # drop(tab);
/// # }
/// ```
+///
+/// Some style can also be given in table creation
+///
+/// ```
+/// # #[macro_use] extern crate prettytable;
+/// # fn main() {
+/// let tab = table!([FrByl:"Element1", Fgc:"Element2", "Element3"],
+/// [FrBy -> 1, 2, 3],
+/// ["A", "B", "C"]
+/// );
+/// # drop(tab);
+/// # }
+/// ```
+///
+/// For details about style specifier syntax, check doc for [Cell::style_spec](cell/struct.Cell.html#method.style_spec) method
#[macro_export]
macro_rules! table {
($([$($content:tt)*]), *) => (
diff --git a/src/row.rs b/src/row.rs
index 72588cb..e3de678 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -163,6 +163,8 @@ impl <T, A> From<T> for Row where A: ToString, T : IntoIterator<Item=A> {
/// # drop(row3);
/// # }
/// ```
+///
+/// For details about style specifier syntax, check doc for [Cell::style_spec](cell/struct.Cell.html#method.style_spec) method
#[macro_export]
macro_rules! row {
(($($out:tt)*); $value:expr) => (vec![$($out)* cell!($value),]);