Skip to content

Commit

Permalink
Fixed lint (+clippy) warnings and line endings
Browse files Browse the repository at this point in the history
Added some lint rustc checks and fixed warnings.
Fixed some clippy warnings & errors
Converted remaining CRLF line endings to LF
  • Loading branch information
Pierre-Henri Symoneaux committed Jun 5, 2017
1 parent 14dcf5f commit 4e36ac1
Show file tree
Hide file tree
Showing 11 changed files with 443 additions and 409 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/target/
/Cargo.lock

\.vscode/
34 changes: 17 additions & 17 deletions examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,23 @@ use prettytable::Table;
use prettytable::row::Row;
use prettytable::cell::Cell;

/*
Following main function will print :
+---------+------+---------+
| ABC | DEFG | HIJKLMN |
+---------+------+---------+
| foobar | bar | foo |
+---------+------+---------+
| foobar2 | bar2 | foo2 |
+---------+------+---------+
Modified :
+---------+------+---------+
| ABC | DEFG | HIJKLMN |
+---------+------+---------+
| foobar | bar | foo |
+---------+------+---------+
| foobar2 | bar2 | new_foo |
+---------+------+---------+
/*
Following main function will print :
+---------+------+---------+
| ABC | DEFG | HIJKLMN |
+---------+------+---------+
| foobar | bar | foo |
+---------+------+---------+
| foobar2 | bar2 | foo2 |
+---------+------+---------+
Modified :
+---------+------+---------+
| ABC | DEFG | HIJKLMN |
+---------+------+---------+
| foobar | bar | foo |
+---------+------+---------+
| foobar2 | bar2 | new_foo |
+---------+------+---------+
*/
fn main() {
let mut table = Table::new();
Expand Down
22 changes: 11 additions & 11 deletions examples/slices.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ fn main() {
let slice = slice.slice(2..);
let slice = slice.slice(..3);

/*
Will print
+----+----+----+
| t1 | t2 | t3 |
+====+====+====+
| 2 | 2 | 2 |
+----+----+----+
| 3 | 3 | 3 |
+----+----+----+
| 4 | 4 | 4 |
+----+----+----+
/*
Will print
+----+----+----+
| t1 | t2 | t3 |
+====+====+====+
| 2 | 2 | 2 |
+----+----+----+
| 3 | 3 | 3 |
+----+----+----+
| 4 | 4 | 4 |
+----+----+----+
*/
slice.printstd();

Expand Down
16 changes: 8 additions & 8 deletions examples/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ fn main() {
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.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();
Expand Down
22 changes: 11 additions & 11 deletions examples/tictactoe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ fn main() {
print!("{} plays > ", current);
stdout.flush().unwrap();
stdin.read_line(&mut line).expect("Cannot read input");
let i = match usize::from_str(line.trim()) {
Ok(i) => i,
let i = match usize::from_str(line.trim()) {
Ok(i) => i,
_ => {
println!("Bad input");
continue;
}
}
};
if i < 1 || i > 9 {
println!("Bad input, should be between 1 and 9");
Expand Down Expand Up @@ -57,14 +57,14 @@ fn main() {
}

fn get(table: &Table, x: usize, y: usize) -> String {
match table.get_row(y) {
Some(ref r) => {
match r.get_cell(x) {
Some(ref c) => c.to_string(),
_ => EMPTY.to_string(),
match table.get_row(y) {
Some(r) => {
match r.get_cell(x) {
Some(c) => c.to_string(),
_ => EMPTY.to_string(),
}
}
_ => EMPTY.to_string(),
}
_ => EMPTY.to_string(),
}
}

Expand Down Expand Up @@ -94,5 +94,5 @@ fn check(table: &Table) -> bool {
if full {
println!("Game is over. It's a draw");
}
return full;
full
}
89 changes: 44 additions & 45 deletions src/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl Cell {
/// Create a new `Cell` initialized with content from `string`.
/// Text alignment in cell is configurable with the `align` argument
pub fn new_align(string: &str, align: Alignment) -> Cell {
let content: Vec<String> = string.lines().map(|ref x| x.to_string()).collect();
let content: Vec<String> = string.lines().map(|x| x.to_string()).collect();
let mut width = 0;
for cont in &content {
let l = UnicodeWidthStr::width(&cont[..]);
Expand Down Expand Up @@ -109,29 +109,29 @@ impl Cell {
let mut background = false;
for c in spec.chars() {
if foreground || background {
let color = match c {
'r' => color::RED,
'R' => color::BRIGHT_RED,
'b' => color::BLUE,
'B' => color::BRIGHT_BLUE,
'g' => color::GREEN,
'G' => color::BRIGHT_GREEN,
'y' => color::YELLOW,
'Y' => color::BRIGHT_YELLOW,
'c' => color::CYAN,
'C' => color::BRIGHT_CYAN,
'm' => color::MAGENTA,
'M' => color::BRIGHT_MAGENTA,
'w' => color::WHITE,
'W' => color::BRIGHT_WHITE,
'd' => color::BLACK,
'D' => color::BRIGHT_BLACK,
let color = match c {
'r' => color::RED,
'R' => color::BRIGHT_RED,
'b' => color::BLUE,
'B' => color::BRIGHT_BLUE,
'g' => color::GREEN,
'G' => color::BRIGHT_GREEN,
'y' => color::YELLOW,
'Y' => color::BRIGHT_YELLOW,
'c' => color::CYAN,
'C' => color::BRIGHT_CYAN,
'm' => color::MAGENTA,
'M' => color::BRIGHT_MAGENTA,
'w' => color::WHITE,
'W' => color::BRIGHT_WHITE,
'd' => color::BLACK,
'D' => color::BRIGHT_BLACK,
_ => {
// Silently ignore unknown tags
foreground = false;
background = false;
continue;
}
}
};
if foreground {
self.style(Attr::ForegroundColor(color));
Expand All @@ -141,21 +141,20 @@ impl Cell {
foreground = false;
background = false;
} else {
match c {
'F' => foreground = true,
'B' => background = true,
'b' => self.style(Attr::Bold),
'i' => self.style(Attr::Italic(true)),
'u' => self.style(Attr::Underline(true)),
'c' => self.align(Alignment::CENTER),
'l' => self.align(Alignment::LEFT),
'r' => self.align(Alignment::RIGHT),
'd' => { /* Default : do nothing */ }
_ => { /* Silently ignore unknown tags */ }
match c {
'F' => foreground = true,
'B' => background = true,
'b' => self.style(Attr::Bold),
'i' => self.style(Attr::Italic(true)),
'u' => self.style(Attr::Underline(true)),
'c' => self.align(Alignment::CENTER),
'l' => self.align(Alignment::LEFT),
'r' => self.align(Alignment::RIGHT),
_ => { /* Silently ignore unknown tags */ }
}
}
}
return self;
self
}

/// Return the height of the cell
Expand Down Expand Up @@ -195,27 +194,27 @@ impl Cell {
skip_right_fill: bool)
-> Result<(), Error> {
for a in &self.style {
match out.attr(a.clone()) {
match out.attr(*a) {
Ok(..) |
Err(::term::Error::NotSupported) |
Err(::term::Error::ColorOutOfRange) => (), // Ignore unsupported atrributes
Err(e) => return Err(term_error_to_io_error(e)),
Err(::term::Error::ColorOutOfRange) => (), // Ignore unsupported atrributes
Err(e) => return Err(term_error_to_io_error(e)),
};
}
try!(self.print(out, idx, col_width, skip_right_fill));
match out.reset() {
match out.reset() {
Ok(..) |
Err(::term::Error::NotSupported) |
Err(::term::Error::ColorOutOfRange) => Ok(()),
Err(e) => Err(term_error_to_io_error(e)),
Err(::term::Error::ColorOutOfRange) => Ok(()),
Err(e) => Err(term_error_to_io_error(e)),
}
}
}

fn term_error_to_io_error(te: ::term::Error) -> Error {
match te {
::term::Error::Io(why) => why,
_ => Error::new(::std::io::ErrorKind::Other, te),
match te {
::term::Error::Io(why) => why,
_ => Error::new(::std::io::ErrorKind::Other, te),
}
}

Expand Down Expand Up @@ -257,7 +256,7 @@ impl Default for Cell {
/// ```
/// Value must implement the `std::string::ToString` trait
///
/// For details about style specifier syntax, check doc for [Cell::style_spec](cell/struct.Cell.html#method.style_spec) method
/// For details about style specifier syntax, check doc for [`Cell::style_spec`](cell/struct.Cell.html#method.style_spec) method
/// # Example
/// ```
/// # #[macro_use] extern crate prettytable;
Expand All @@ -271,10 +270,10 @@ impl Default for Cell {
/// # }
/// ```
#[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)));
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)));
}

#[cfg(test)]
Expand Down
Loading

0 comments on commit 4e36ac1

Please sign in to comment.