Merge branch 'master' of github.com:timvisee/pixelpwnr

This commit is contained in:
Tim Visée
2018-02-12 15:58:46 +01:00
8 changed files with 77 additions and 39 deletions

View File

@@ -4,8 +4,5 @@ pub const APP_VERSION: &'static str = "0.1";
pub const APP_AUTHOR: &'static str = "Tim Visee <timvisee@gmail.com>";
pub const APP_ABOUT: &'static str = "A quick pixelflut client, that pwns pixelflut panels.";
// The default thread count
pub const DEFAULT_THREAD_COUNT: usize = 4;
// The default frames per second rate
pub const DEFAULT_IMAGE_FPS: u32 = 1;

View File

@@ -1,4 +1,5 @@
extern crate clap;
extern crate num_cpus;
use clap::{Arg, ArgMatches, App};
@@ -50,14 +51,12 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
.takes_value(true))
.arg(Arg::with_name("x")
.short("x")
.long("x")
.value_name("PIXELS")
.help("Draw X offset (def: 0)")
.display_order(4)
.takes_value(true))
.arg(Arg::with_name("y")
.short("y")
.long("y")
.value_name("PIXELS")
.help("Draw Y offset (def: 0)")
.display_order(5)
@@ -68,7 +67,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
.alias("thread")
.alias("threads")
.value_name("COUNT")
.help("Number of concurrent threads (def: 4)")
.help("Number of concurrent threads (def: CPUs)")
.display_order(6)
.takes_value(true))
.arg(Arg::with_name("fps")
@@ -95,9 +94,10 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
/// Get the thread count.
pub fn count(&self) -> usize {
self.matches.value_of("count")
.unwrap_or(&format!("{}", DEFAULT_THREAD_COUNT))
.parse::<usize>()
.expect("Invalid count specified")
.map(|count| count.parse::<usize>()
.expect("Invalid count specified")
)
.unwrap_or(num_cpus::get())
}
/// Get the image paths.
@@ -112,17 +112,19 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
pub fn size(&self, def: Option<(u32, u32)>) -> (u32, u32) {
(
self.matches.value_of("width")
.unwrap_or(
&format!("{}", def.expect("No screen width set or known").0)
.map(|width| width.parse::<u32>()
.expect("Invalid image width")
)
.parse::<u32>()
.expect("Invalid image width"),
.unwrap_or(
def.expect("No screen width set or known").0
),
self.matches.value_of("height")
.unwrap_or(
&format!("{}", def.expect("No screen height set or known").1)
.map(|height| height.parse::<u32>()
.expect("Invalid image height")
)
.parse::<u32>()
.expect("Invalid image height"),
.unwrap_or(
def.expect("No screen height set or known").1
),
)
}
@@ -130,21 +132,24 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
pub fn offset(&self) -> (u32, u32) {
(
self.matches.value_of("x")
.unwrap_or("0")
.parse::<u32>()
.expect("Invalid X offset"),
.map(|x| x.parse::<u32>()
.expect("Invalid X offset")
)
.unwrap_or(0),
self.matches.value_of("y")
.unwrap_or("0")
.parse::<u32>()
.expect("Invalid Y offset"),
.map(|y| y.parse::<u32>()
.expect("Invalid Y offset")
)
.unwrap_or(0),
)
}
/// Get the FPS.
pub fn fps(&self) -> u32 {
self.matches.value_of("fps")
.unwrap_or(&format!("{}", DEFAULT_IMAGE_FPS))
.parse::<u32>()
.expect("Invalid frames per second rate")
.map(|fps| fps.parse::<u32>()
.expect("Invalid frames per second rate")
)
.unwrap_or(DEFAULT_IMAGE_FPS)
}
}

View File

@@ -1,3 +1,3 @@
// Re-export modules
// Reexport modules
pub mod painter;
pub mod handle;

View File

@@ -1,3 +1,3 @@
// Re-export modules
// Reexport modules
pub mod canvas;
pub mod client;