diff --git a/README.md b/README.md index 05a14c9..7fca26b 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ As an alternative to the editor you can generate `.yaya` grids using [@AaronErha ## Command line arguments -The program takes a single number for a squared grid size, two numbers for a width and height or the filename of a `.yaya` grid file. +The program takes a single number for a squared grid size, two numbers for width and height, or the filename of a `.yaya` grid file to load a custom user-made grid. ```shell yayagram # a random 5x5 grid diff --git a/src/editor.rs b/src/editor.rs index d4a3f56..8104677 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -128,7 +128,7 @@ impl Editor { // but does the file for it still exist? if !Path::new(&self.filename).exists() { match self.new_writer(builder) { - Ok(writer) => (writer), + Ok(writer) => writer, Err(err) => { return Err(err); } @@ -144,7 +144,7 @@ impl Editor { None => { // This is the first time we are saving the grid match self.new_writer(builder) { - Ok(writer) => (writer), + Ok(writer) => writer, Err(err) => { return Err(err); } diff --git a/src/event.rs b/src/event.rs index 6c2e82d..70d2430 100644 --- a/src/event.rs +++ b/src/event.rs @@ -112,8 +112,9 @@ pub fn r#loop(terminal: &mut Terminal, builder: &mut Builder) -> State { State::Solved(_) => break state, State::Exit(instant) => { if let Some(instant) = instant { - if instant.elapsed().as_secs() > 60 { - // If the player played for more than 1 minute, the game is considered to have some kind of value to the player, + if instant.elapsed().as_secs() >= 30 { + // If the player stayed for half a minute, + // the game is considered to have some kind of value to the player, // so we make sure the player really wants to exit. let confirmed = diff --git a/src/event/input/mouse.rs b/src/event/input/mouse.rs index a6d629b..6b8a4c7 100644 --- a/src/event/input/mouse.rs +++ b/src/event/input/mouse.rs @@ -173,8 +173,12 @@ fn resize_grid( // Temporarily set the builder grid size back to the old size to render the confirmation alert properly. let new_grid_size = builder.grid.size; builder.grid.size = original_grid_size; - let confirmed = - window::confirmation_prompt(terminal, builder, alert, "new random grid in this size"); + let confirmed = window::confirmation_prompt( + terminal, + builder, + alert, + "load new random grid in this size", + ); builder.grid.size = new_grid_size; if confirmed { diff --git a/src/event/input/window.rs b/src/event/input/window.rs index daec820..9d51c60 100644 --- a/src/event/input/window.rs +++ b/src/event/input/window.rs @@ -66,10 +66,8 @@ pub fn await_fitting_size( } else { unreachable!() }; - let message = format!( - "Please increase window {} or decrease text size (Ctrl and -)", - length - ); + let message = + format!("Please increase window {length} or decrease text size (Ctrl and -)"); terminal.write(&message); terminal.flush(); @@ -157,7 +155,7 @@ pub fn await_dropped_grid_file_path( Ok(path) } -/// Draws an alert asking the user to confirm the given thing and returns whether the user confirmed the action. +/// Draws an alert asking the user to confirm the given verb and returns whether the user confirmed the action. /// /// Despite the alert saying that Esc cancels, every other key apart from Enter will cancel as well. /// @@ -166,9 +164,9 @@ pub fn confirmation_prompt( terminal: &mut Terminal, builder: &mut Builder, alert: &mut Option, - thing_to_confirm: &str, + verb_to_confirm: &str, ) -> bool { - let message = format!("Press Enter to confirm {}. Esc to cancel", thing_to_confirm).into(); + let message = format!("Press Enter to {}; Esc to cancel", verb_to_confirm).into(); alert::draw(terminal, builder, alert, message); // We could also just ignore `Event::Mouse(_)` in the loop below but disabling mouse capture changes the pointer icon diff --git a/src/grid/builder.rs b/src/grid/builder.rs index 931ab89..84c6588 100644 --- a/src/grid/builder.rs +++ b/src/grid/builder.rs @@ -347,7 +347,7 @@ impl Builder { // In the future it might be helpful to take a look at the market share of Windows 10 or 11 and decide by that. // // In this regard, for good Windows terminal compatibility, - // I generally recommend limiting yourself to characters listed on https://en.wikipedia.org/wiki/Code_page_437 + // I generally recommend sticking to the characters listed on https://en.wikipedia.org/wiki/Code_page_437 #[cfg(windows)] terminal.write(" +"); } diff --git a/src/grid/cell.rs b/src/grid/cell.rs index c3e51cc..caa2a42 100644 --- a/src/grid/cell.rs +++ b/src/grid/cell.rs @@ -5,7 +5,7 @@ use terminal::{ Terminal, }; -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Cell { /// An umarked cell. Empty, @@ -29,7 +29,7 @@ impl Default for Cell { impl From for Cell { fn from(filled: bool) -> Self { - filled.then(|| Cell::Filled).unwrap_or_default() + filled.then_some(Cell::Filled).unwrap_or_default() } } @@ -317,7 +317,7 @@ impl CellPlacement { } else { self.measurement_point = Some(selected_cell_point); - State::Alert("Set second measurement point".into()) + State::Alert("Press X to set second measurement point".into()) } } else { State::Continue diff --git a/src/main.rs b/src/main.rs index 19d6b19..1277d21 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,19 +15,19 @@ use terminal::{ Terminal, }; -// Things that could be implemented but might not be worth it: -// -A main menu -// -An interactive tutorial -// -Currently whole clue rows are grayed out once all cells for those clues have been solved +// Wishlist: +// - A main menu +// - An interactive tutorial +// - Currently whole clue rows are grayed out once all cells for those clues have been solved // Make them gray out individually. (Maybe itertools' `pad_using` is helpful) -// -Ability to save records to a file and determine new records with that -// -Ability to continue after solving the puzzle/ability to play it again +// - Ability to save records to a file and determine new records with that +// - Ability to continue after solving the puzzle/ability to play it again fn main() { let code = match run() { Ok(()) => 0, Err(err) => { - eprintln!("{}", err); + eprintln!("{err}"); 1 } }; @@ -42,7 +42,7 @@ fn run() -> Result<(), Cow<'static, str>> { Ok(Some(args::Arg::Help)) => { println!(concat!( "Play nonograms/picross in your terminal.\n", - "For the arguments please check ." + "For command line arguments please visit ." )); return Ok(()); @@ -50,7 +50,7 @@ fn run() -> Result<(), Cow<'static, str>> { Ok(Some(args::Arg::Version)) => { let version = env!("CARGO_PKG_VERSION"); - println!("{}", version); + println!("{version}"); return Ok(()); }