Apply clippy suggestions
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
// Application properties
|
// Application properties
|
||||||
pub const APP_NAME: &'static str = "pixelpwnr";
|
pub const APP_NAME: &str = "pixelpwnr";
|
||||||
pub const APP_VERSION: &'static str = "0.1";
|
pub const APP_VERSION: &str = "0.1";
|
||||||
pub const APP_AUTHOR: &'static str = "Tim Visee <timvisee@gmail.com>";
|
pub const APP_AUTHOR: &str = "Tim Visee <timvisee@gmail.com>";
|
||||||
pub const APP_ABOUT: &'static str = "A quick pixelflut client, that pwns pixelflut panels.";
|
pub const APP_ABOUT: &str = "A quick pixelflut client, that pwns pixelflut panels.";
|
||||||
|
|
||||||
// The default frames per second rate
|
// The default frames per second rate
|
||||||
pub const DEFAULT_IMAGE_FPS: u32 = 1;
|
pub const DEFAULT_IMAGE_FPS: u32 = 1;
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ impl<'a: 'b, 'b> ArgHandler<'a> {
|
|||||||
self.matches
|
self.matches
|
||||||
.value_of("count")
|
.value_of("count")
|
||||||
.map(|count| count.parse::<usize>().expect("Invalid count specified"))
|
.map(|count| count.parse::<usize>().expect("Invalid count specified"))
|
||||||
.unwrap_or(num_cpus::get())
|
.unwrap_or_else(num_cpus::get)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the image paths.
|
/// Get the image paths.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ impl Color {
|
|||||||
|
|
||||||
/// Get a hexadecimal representation of the color,
|
/// Get a hexadecimal representation of the color,
|
||||||
/// such as `FFFFFF` for white and `FF0000` for red.
|
/// such as `FFFFFF` for white and `FF0000` for red.
|
||||||
pub fn as_hex(&self) -> String {
|
pub fn as_hex(self) -> String {
|
||||||
format!("{:02X}{:02X}{:02X}", self.r, self.g, self.b)
|
format!("{:02X}{:02X}{:02X}", self.r, self.g, self.b)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,13 +26,13 @@ impl ImageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Instantiate the image manager, and load the images from the given paths.
|
/// Instantiate the image manager, and load the images from the given paths.
|
||||||
pub fn load(paths: Vec<&str>, size: &(u32, u32)) -> ImageManager {
|
pub fn load(paths: &[&str], size: (u32, u32)) -> ImageManager {
|
||||||
// Show a status message
|
// Show a status message
|
||||||
println!("Load and process {} image(s)...", paths.len());
|
println!("Load and process {} image(s)...", paths.len());
|
||||||
|
|
||||||
// Load the images from the paths
|
// Load the images from the paths
|
||||||
let image_manager =
|
let image_manager =
|
||||||
ImageManager::from(paths.iter().map(|path| load_image(path, &size)).collect());
|
ImageManager::from(paths.iter().map(|path| load_image(path, size)).collect());
|
||||||
|
|
||||||
// TODO: process the image slices
|
// TODO: process the image slices
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ impl ImageManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Load the image at the given path, and size it correctly
|
/// Load the image at the given path, and size it correctly
|
||||||
fn load_image(path: &str, size: &(u32, u32)) -> DynamicImage {
|
fn load_image(path: &str, size: (u32, u32)) -> DynamicImage {
|
||||||
// Create a path instance
|
// Create a path instance
|
||||||
let path = Path::new(&path);
|
let path = Path::new(&path);
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ fn start<'a>(arg_handler: &ArgHandler<'a>) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Load the image manager
|
// Load the image manager
|
||||||
let mut image_manager = ImageManager::load(arg_handler.image_paths(), &size);
|
let mut image_manager = ImageManager::load(&arg_handler.image_paths(), size);
|
||||||
|
|
||||||
// Start the work in the image manager, to walk through the frames
|
// Start the work in the image manager, to walk through the frames
|
||||||
image_manager.work(&mut canvas, arg_handler.fps());
|
image_manager.work(&mut canvas, arg_handler.fps());
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ impl Painter {
|
|||||||
self.client.write_pixel(
|
self.client.write_pixel(
|
||||||
x + self.area.x + self.offset.0,
|
x + self.area.x + self.offset.0,
|
||||||
y + self.area.y + self.offset.1,
|
y + self.area.y + self.offset.1,
|
||||||
&color,
|
color,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ use color::Color;
|
|||||||
const CMD_READ_BUFFER_SIZE: usize = 32;
|
const CMD_READ_BUFFER_SIZE: usize = 32;
|
||||||
|
|
||||||
// The response format of the screen size from a pixelflut server.
|
// The response format of the screen size from a pixelflut server.
|
||||||
const PIX_SERVER_SIZE_REGEX: &'static str = r"^(?i)\s*SIZE\s+([[:digit:]]+)\s+([[:digit:]]+)\s*$";
|
const PIX_SERVER_SIZE_REGEX: &str = r"^(?i)\s*SIZE\s+([[:digit:]]+)\s+([[:digit:]]+)\s*$";
|
||||||
|
|
||||||
/// A pixelflut client.
|
/// A pixelflut client.
|
||||||
///
|
///
|
||||||
@@ -44,9 +44,9 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write a pixel to the given stream.
|
/// Write a pixel to the given stream.
|
||||||
pub fn write_pixel(&mut self, x: u32, y: u32, color: &Color) -> Result<(), Error> {
|
pub fn write_pixel(&mut self, x: u32, y: u32, color: Color) -> Result<(), Error> {
|
||||||
// Write the command to set a pixel
|
// Write the command to set a pixel
|
||||||
self.write_command(format!("PX {} {} {}", x, y, color.as_hex()))
|
self.write_command(&format!("PX {} {} {}", x, y, color.as_hex()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read the size of the screen.
|
/// Read the size of the screen.
|
||||||
@@ -77,10 +77,10 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write the given command to the given stream.
|
/// Write the given command to the given stream.
|
||||||
fn write_command(&mut self, cmd: String) -> Result<(), Error> {
|
fn write_command(&mut self, cmd: &str) -> Result<(), Error> {
|
||||||
// Write the pixels and a new line
|
// Write the pixels and a new line
|
||||||
self.stream.write(cmd.as_bytes())?;
|
self.stream.write_all(cmd.as_bytes())?;
|
||||||
self.stream.write("\r\n".as_bytes())?;
|
self.stream.write_all(b"\r\n")?;
|
||||||
|
|
||||||
// Flush, make sure to clear the send buffer
|
// Flush, make sure to clear the send buffer
|
||||||
// TODO: only flush each 100 pixels?
|
// TODO: only flush each 100 pixels?
|
||||||
@@ -95,7 +95,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Write the given command to the given stream, and read the output.
|
/// Write the given command to the given stream, and read the output.
|
||||||
fn write_read_command(&mut self, cmd: String) -> Result<String, Error> {
|
fn write_read_command(&mut self, cmd: &str) -> Result<String, Error> {
|
||||||
// Write the command
|
// Write the command
|
||||||
self.write_command(cmd)?;
|
self.write_command(cmd)?;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user