Clippy + fmt.

This commit is contained in:
2017-02-01 10:42:36 +01:00
parent 9ed7e22d84
commit 0e1e59476b

View File

@@ -2,6 +2,7 @@ extern crate getopts;
extern crate rand;
extern crate ansi_term;
use std::io;
use std::io::prelude::*;
use std::f32::consts::PI;
@@ -11,6 +12,7 @@ use getopts::Options;
use rand::{thread_rng, Rng};
use ansi_term::Colour::RGB;
fn print_usage(program: &str, opts: Options) {
let brief = format!("Usage: {} [OPTION]... [FILE]...", program);
@@ -28,10 +30,10 @@ fn main() {
opts.optopt("S", "seed", "Rainbow seed, 0 = random", "<i>");
opts.optflag("h", "help", "Show this message");
// @todo do not panic!
// TODO Do not panic!
let matches = match opts.parse(&args[1..]) {
Ok(m) => { m }
Err(f) => { panic!(f.to_string()) }
Ok(m) => m,
Err(f) => panic!(f.to_string()),
};
// print usage?
@@ -42,47 +44,44 @@ fn main() {
}
// get spread.
// @todo this is nasty... fix this.
// TODO this is nasty... fix this.
let spread: f32 = match matches.opt_default("spread", "3.0") {
Some(s) => {
match s.parse() {
Ok(0.0) => 3.0,
Ok(n) => n,
_ => 3.0
Ok(n) if n != 0.0 => n,
_ => 3.0,
}
},
None => 3.0
}
None => 3.0,
};
// get freq.
// @todo this is nasty... fix this.
// TODO this is nasty... fix this.
let freq: f32 = match matches.opt_default("freq", "0.1") {
Some(s) => {
match s.parse() {
Ok(0.0) => 0.1,
Ok(n) => n,
_ => 0.1
Ok(n) if n != 0.0 => n,
_ => 0.1,
}
},
None => 0.1
}
None => 0.1,
};
// get seed.
// @todo this is nasty... fix this.
// TODO this is nasty... fix this.
let mut seed: i32 = match matches.opt_default("seed", "0") {
Some(s) => {
match s.parse() {
Ok(0) => thread_rng().gen_range(0, 256),
Ok(n) => n,
_ => thread_rng().gen_range(0, 256)
Ok(n) if n != 0 => n,
_ => thread_rng().gen_range(0, 256),
}
},
None => thread_rng().gen_range(0, 256)
}
None => thread_rng().gen_range(0, 256),
};
let stdin = io::stdin();
// @todo I want to use chars() instead, but it's unstable right now :(
// TODO I want to use chars() instead, but it's unstable right now :(
for line in stdin.lock().lines() {
seed += 1;
@@ -96,7 +95,7 @@ fn main() {
print!("{}", RGB(red, green, blue).paint(c.to_string()));
}
print!("\n");
println!();
}
}