Skip to content

Commit

Permalink
Merge pull request #18 from phsym/ascription_fix
Browse files Browse the repository at this point in the history
Ascription fix
  • Loading branch information
phsym committed Jan 20, 2016
2 parents b770f25 + 73298cc commit eaff73d
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
language: rust
rust:
- stable
- beta
- nightly
matrix:
allow_failures:
- rust: nightly
- stable
- beta
- nightly
# matrix:
# allow_failures:
# - rust: nightly
env:
global:
- secure: M+X/Y/0FmtXj18pp2WI4KRyHx+C9B8ITxyfoIOY7sXu+zI06hmmWbawQSpKRzQY3KhTxXAXw7DMtsLlyHioz3w4iIoFykhai6DrUQWDocagPwvVA6hWf+mW7j3DiFlfx/0VT9JMi6Y0RyUcvo1e2snFKI9zQP20EOwK8IIyWUcwFks2Fpu1Hu3Bu8bw9lB3D6ZdzxbAuctcy+OuMR7OD6QFyHi8jQ2Q3yUruh3yLqy30bJSD3Nerw+PuwKiDX2tnObNUVRT0W0IQx6Yvk5sA7m+IZf2VM2ayKw6ChLdDC9yOa/s0mNzHBT7rE1HGfkYIsgc9kos2zZP5fMawDELpEDccPq19DYsno2gb7zFj7fyTFJbkqlROoj6cgL4xkBQAY/yRpnMzHhwLV1tu2lOJCdhyujCImb+mAZV14U7fkCAzYUrtxfdNImp88QQgynRC74vOAJc6qHnRI0ut6DoKcNqK+nn07spPY0wrAD4F+o7Nc32JcfJJ/YW7QvJBsWi6IdSduKvJyWTFtFLnLUzjsFT+C0U2P8dykOf1C4gxdUdUnxwSMDPC4+8VZlcqjPowjQ2xqS04TRKx45SEUDuX2xM0E2r8pIZpxNUm/NP1bwgumO0zMJCLEsIYe561BLODyOjmmsW2YVg2WOdpJWGh+Mbzr6aDu3B4FO4PbjZdEoI=
- secure: uEDWqegkGvkCo9qE5h3j/VvD007MKjwfsX9+CiWKK+nd+FrfqUak/LpSJiLYAdXePMqh/+jYynUWKsZFi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ut6DoKcNqK+nn07spPY0wrAD4F+o7Nc32JcfJJ/YW7QvJBsWi6IdSduKvJyWTFtFLnLUzjsFT+C0U2P8dykOf1C4gxdUdUnxwSMDPC4+8VZlcqjPowjQ2xqS04TRKx45SEUDuX2xM0E2r8pIZpxNUm/NP1bwgumO0zMJCLEsIYe561BLODyOjmmsW2YVg2WOdpJWGh+Mbzr6aDu3B4FO4PbjZdEoI=
- secure: uEDWqegkGvkCo9qE5h3j/VvD007MKjwfsX9+CiWKK+nd+FrfqUak/LpSJiLYAdXePMqh/+jYynUWKsZFiLksmSkJK0U2Xkms9C2TynbuojlyTd8P1aUM9RNtOmS6FYtrmpQLxzUPNL8mIMcoTzIiZgABp8XDmW83NXKXSuKbXWpqO2oxHuVFHFNTnHW5fDs1VJJOrv+1oUICijAoy9X1iGZUTt0r+Vqb+uUt2XXlGzBhTBkGYIONDzI/4D9N7P4KJxrpiiKNpH8/EiWSGBmi1YCydW5KRLswdQYGWyvyKwRE9XBbLRd8CnEVPpB2ouL3CB2jGufzC1ZDKw7ehtyTCAZBFdIQMJHucJn0h0/qSFKBXO6Qvn7A5LfyxBpR0t+VG1cvtzE+v3BcIs6MkakZdVfOHoPczrOw6kG1Gbsjqd1TrYeT2evhzbiGIgyLf8UP5ReROlOwkpvyZSxqumuQtxNWIidzPRD9WQi8lD6F0p/C2hwqgmcDTBXV0+b6gmwOdn6rQVItTJj1j9V0omTh4rHsLHuycpXpBwLbABUaYvXxjHL+ZvQiydka1RqDsNDOZ5sOBEduPVtB3q1FN4WRBaAhXLOd4XwGys6K36JZgcxAEx4CVP5ECgU75cFkRC/qJhaOHI04qFdpGrfmv+ctmZQOBQyl+U0kDrV02kFftek=
after_success: |
sudo apt-get install libcurl4-openssl-dev libelf-dev libdw-dev &&
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,27 +144,26 @@ Cell::new("foo2").style_spec("FrByc")
Where **FrBybc** means **F**oreground: **r**ed, **B**ackground: **y**ellow, **b**old, **c**enter

With macros it's even simpler :
> **Currently style in macros don't work on nightly rust because of _Type Ascription_. See issue [#11](https://github.com/phsym/prettytable-rs/issues/11) for details**

In rows, for each cells :
```rust
row![FrByb:"ABC", FrByb:"DEFG", "HIJKLMN"];
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
table!([FrBybl:"A", FrBybc:"B", FrBybr:"C"], [123, 234, 345, 456]);
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 :
Expand Down
12 changes: 6 additions & 6 deletions examples/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,28 @@ fn main() {
let _ = table!();
let mut table = Table::new();
// Add style to a cell
table.add_row(row![FrByb:"ABC", "DEFG", "HIJKLMN"]);
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
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")])
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]);
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();
}
4 changes: 2 additions & 2 deletions src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ impl Default for Cell {
/// // Do something with the cell
/// # drop(cell);
/// // Create a cell with style (Red foreground, Bold, aligned to left);
/// let styled = cell!(Frbl:"value");
/// let styled = cell!(Frbl->"value");
/// # drop(styled);
/// # }
/// ```
#[macro_export]
macro_rules! cell {
() => ($crate::cell::Cell::default());
($value:expr) => ($crate::cell::Cell::new(&$value.to_string()));
($style:ident : $value:expr) => (cell!($value).style_spec(stringify!($style)));
($style:ident -> $value:expr) => (cell!($value).style_spec(stringify!($style)));
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ 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],
/// let tab = table!([FrByl->"Element1", Fgc->"Element2", "Element3"],
/// [FrBy => 1, 2, 3],
/// ["A", "B", "C"]
/// );
/// # drop(tab);
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ use term::{Attr, color};
fn main() {
let _ = table!();
let mut table = Table::new();
table.add_row(row![FrByb:"ABC", "DEFG", "HIJKLMN"]);
table.add_row(row![FrByb->"ABC", "DEFG", "HIJKLMN"]);
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
Expand All @@ -40,10 +40,10 @@ fn main() {
// Print a table with some styles on it :
// FrBybl means : Foregound red, Background yellow, bold, left align
// d means : Default, do nothing
ptable!([FrBybl:"A", "B", FrBybr:"C"], [d:123, 234, 345, 456]);
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(*consts::FORMAT_DEFAULT);
table.printstd();
Expand Down
10 changes: 5 additions & 5 deletions src/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ 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"];
/// let row3 = row![Fb->"blue", Fr->"red", "normal"];
/// // Do something with rows
/// # drop(row1);
/// # drop(row2);
Expand All @@ -189,10 +189,10 @@ impl <T, A> From<T> for Row where A: ToString, T : IntoIterator<Item=A> {
macro_rules! row {
(($($out:tt)*); $value:expr) => (vec![$($out)* cell!($value)]);
(($($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)*));
(($($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)*)));
}

0 comments on commit eaff73d

Please sign in to comment.