summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-01-14 21:09:37 +0100
committerpierresy <pierre-henri.symoneaux@alcatel-lucent.com>2016-01-14 21:09:37 +0100
commit7ac4cf44b5b41ba20d31dcb52ea69261ca60851d (patch)
tree6edf6139d568fbfa6836be485318b107764943b7
parent45d77e82ab32622a2b06264ae660bd73edc6731d (diff)
Changed token for row style
to FlatArrow (`=>`) in macro syntax
-rw-r--r--README.md6
-rw-r--r--examples/style.rs12
-rw-r--r--src/lib.rs2
-rw-r--r--src/main.rs4
-rw-r--r--src/row.rs38
5 files changed, 31 insertions, 31 deletions
diff --git a/README.md b/README.md
index 652b5eb..84190c7 100644
--- a/README.md
+++ b/README.md
@@ -152,7 +152,7 @@ row![FrByb:"ABC", FrByb:"DEFG", "HIJKLMN"];
```
Or for the whole row :
```rust
-row![FY -> "styled", "bar", "foo"];
+row![FY => "styled", "bar", "foo"];
```
In tables, for each cells :
```rust
@@ -160,11 +160,11 @@ table!([FrBybl:"A", FrBybc:"B", FrBybr:"C"], [123, 234, 345, 456]);
```
Or for each rows :
```rust
-table!([Frb -> "A", "B", "C"], [Frb -> 1, 2, 3, 4], [1, 2, 3]);
+table!([Frb => "A", "B", "C"], [Frb => 1, 2, 3, 4], [1, 2, 3]);
```
Or a mix :
```rust
-table!([Frb -> "A", "B", "C"], [Frb:1, Fgi:2, 3, 4], [1, 2, 3]);
+table!([Frb => "A", "B", "C"], [Frb:1, Fgi:2, 3, 4], [1, 2, 3]);
```
### List of style specifiers :
diff --git a/examples/style.rs b/examples/style.rs
index ca608c6..b209060 100644
--- a/examples/style.rs
+++ b/examples/style.rs
@@ -13,7 +13,7 @@ fn main() {
// 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![FY => "styled", "bar", "foo"]);
table.add_row(Row::new(vec![
Cell::new("foobar2"),
// Create a cell with a red foreground color
@@ -25,14 +25,14 @@ fn main() {
);
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]);
-
+ 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]);
+ 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.set_titles(row![c => "Title 1", "Title 2"]);
table.printstd();
}
diff --git a/src/lib.rs b/src/lib.rs
index 20b2389..7c67b72 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -418,7 +418,7 @@ impl <'a, T, E> Slice<'a, E> for T where T: AsRef<TableSlice<'a>>, [Row]: Index<
/// # #[macro_use] extern crate prettytable;
/// # fn main() {
/// let tab = table!([FrByl:"Element1", Fgc:"Element2", "Element3"],
-/// [FrBy -> 1, 2, 3],
+/// [FrBy => 1, 2, 3],
/// ["A", "B", "C"]
/// );
/// # drop(tab);
diff --git a/src/main.rs b/src/main.rs
index 3344952..f5cba05 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -18,7 +18,7 @@ fn main() {
table.add_row(row!["foobar", "bar", "foo"]);
table.add_row(row![]);
// Add style to a full row
- table.add_row(row![FY -> "styled", "bar", "foo"]);
+ 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
@@ -43,7 +43,7 @@ fn main() {
ptable!([FrBybl:"A", "B", FrBybr:"C"], [d:123, 234, 345, 456]);
// 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]);
+ let mut table = table!([Frb => "A", "B", "C"], [1, 2, 3, 4], ["A\nBCCZZZ\nDDD", 2, table]);
table.set_titles(row!["Title 1", "Title 2"]);
table.set_format(FORMAT_DEFAULT);
table.printstd();
diff --git a/src/row.rs b/src/row.rs
index 0a4ca7c..6c1d772 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -22,17 +22,17 @@ impl Row {
cells: cells
};
}
-
+
/// Create an row of length `size`, with empty strings stored
pub fn empty() -> Row {
return Self::new(vec![Cell::default(); 0]);
}
-
+
/// Get the number of cells in this row
pub fn len(&self) -> usize {
return self.cells.len();
}
-
+
/// Get the height of this row
pub fn get_height(&self) -> usize {
let mut height = 1; // Minimum height must be 1 to print empty rows
@@ -44,7 +44,7 @@ impl Row {
}
return height;
}
-
+
/// Get the minimum width required by the cell in the column `column`.
/// Return 0 if the cell does not exist in this row
pub fn get_cell_width(&self, column: usize) -> usize {
@@ -53,17 +53,17 @@ impl Row {
None => 0
}
}
-
+
/// Get the cell at index `idx`
pub fn get_cell(&self, idx: usize) -> Option<&Cell> {
return self.cells.get(idx);
}
-
+
/// Get the mutable cell at index `idx`
pub fn get_mut_cell(&mut self, idx: usize) -> Option<&mut Cell> {
return self.cells.get_mut(idx);
}
-
+
/// Set the `cell` in the row at the given `column`
pub fn set_cell(&mut self, cell: Cell, column: usize) -> Result<(), &str> {
if column >= self.len() {
@@ -72,12 +72,12 @@ impl Row {
self.cells[column] = cell;
return Ok(());
}
-
+
/// Append a `cell` at the end of the row
pub fn add_cell(&mut self, cell: Cell) {
self.cells.push(cell);
}
-
+
/// Insert `cell` at position `index`. If `index` is higher than the row lenght,
/// the cell will be appended at the end
pub fn insert_cell(&mut self, index: usize, cell: Cell) {
@@ -87,17 +87,17 @@ impl Row {
self.add_cell(cell);
}
}
-
+
/// Remove the cell at position `index`. Silently skip if this cell does not exist
pub fn remove_cell(&mut self, index: usize) {
if index < self.cells.len() {
self.cells.remove(index);
}
}
-
+
/// Internal only
- fn __print<T:Write+?Sized, F>(&self, out: &mut T, format: &TableFormat, col_width: &[usize], f: F) -> Result<(), Error>
- where F: Fn(&Cell, &mut T, usize, usize) -> Result<(), Error>
+ fn __print<T:Write+?Sized, F>(&self, out: &mut T, format: &TableFormat, col_width: &[usize], f: F) -> Result<(), Error>
+ where F: Fn(&Cell, &mut T, usize, usize) -> Result<(), Error>
{
for i in 0..self.get_height() {
try!(format.print_column_separator(out));
@@ -112,13 +112,13 @@ impl Row {
}
return Ok(());
}
-
+
/// Print the row to `out`, with `separator` as column separator, and `col_width`
/// specifying the width of each columns
pub fn print<T: Write+?Sized>(&self, out: &mut T, format: &TableFormat, col_width: &[usize]) -> Result<(), Error> {
return self.__print(out, format, col_width, Cell::print);
}
-
+
/// Print the row to terminal `out`, with `separator` as column separator, and `col_width`
/// specifying the width of each columns. Apply style when needed
pub fn print_term<T: Terminal+?Sized>(&self, out: &mut T, format: &TableFormat, col_width: &[usize]) -> Result<(), Error> {
@@ -158,7 +158,7 @@ impl <T, A> From<T> for Row where A: ToString, T : IntoIterator<Item=A> {
}
/// This macro simplifies `Row` creation
-///
+///
/// The syntax support style spec
/// # Example
/// ```
@@ -168,7 +168,7 @@ impl <T, A> From<T> for Row where A: ToString, T : IntoIterator<Item=A> {
/// let row1 = row!["Element 1", "Element 2", "Element 3"];
/// // Create a row with all cells formatted with red foreground color, yellow background color
/// // bold, italic, align in the center of the cell
-/// let row2 = row![FrBybic -> "Element 1", "Element 2", "Element 3"];
+/// let row2 = row![FrBybic => "Element 1", "Element 2", "Element 3"];
/// // Create a row with first cell in blue, second one in red, and last one with default style
/// let row3 = row![Fb:"blue", Fr:"red", "normal"];
/// // Do something with rows
@@ -185,8 +185,8 @@ macro_rules! row {
(($($out:tt)*); $value:expr, $($n:tt)*) => (row!(($($out)* cell!($value),); $($n)*));
(($($out:tt)*); $style:ident : $value:expr) => (vec![$($out)* cell!($style : $value)]);
(($($out:tt)*); $style:ident : $value:expr, $($n: tt)*) => (row!(($($out)* cell!($style : $value),); $($n)*));
-
+
($($content:expr), *) => ($crate::row::Row::new(vec![$(cell!($content)), *]));
- ($style:ident -> $($content:expr), *) => ($crate::row::Row::new(vec![$(cell!($style : $content)), *]));
+ ($style:ident => $($content:expr), *) => ($crate::row::Row::new(vec![$(cell!($style : $content)), *]));
($($content:tt)*) => ($crate::row::Row::new(row!((); $($content)*)));
}