From 79fc190013cae43de4408dd6fa6000fd9a2f5e87 Mon Sep 17 00:00:00 2001 From: ctcl-bregis Date: Mon, 16 Dec 2024 19:51:46 -0500 Subject: [PATCH] shorthand next and prev and page number roll over --- crates/hyfetch/src/bin/hyfetch.rs | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/crates/hyfetch/src/bin/hyfetch.rs b/crates/hyfetch/src/bin/hyfetch.rs index 7991f0e7..466fea03 100644 --- a/crates/hyfetch/src/bin/hyfetch.rs +++ b/crates/hyfetch/src/bin/hyfetch.rs @@ -572,15 +572,14 @@ fn create_config( print_flag_page(&pages[usize::from(page)], page).context("failed to print flag page")?; let mut opts: Vec<&str> = ::VARIANTS.into(); - if page < num_pages.checked_sub(1).unwrap() { - opts.push("next"); - } - if page > 0 { - opts.push("prev"); - } + opts.push("next"); + opts.push("n"); + opts.push("prev"); + opts.push("p"); + writeln!( io::stdout(), - "Enter 'next' to go to the next page and 'prev' to go to the previous page." + "Enter '[n]ext' to go to the next page and '[p]rev' to go to the previous page." ) .context("failed to write message to stdout")?; let selection = literal_input( @@ -595,10 +594,18 @@ fn create_config( ) .context("failed to ask for choice input") .context("failed to select preset")?; - if selection == "next" { - page = page.checked_add(1).unwrap(); - } else if selection == "prev" { - page = page.checked_sub(1).unwrap(); + if selection == "next" || selection == "n" { + if page == num_pages.checked_sub(1).unwrap() { + page = 0 + } else { + page = page.checked_add(1).unwrap(); + } + } else if selection == "prev" || selection == "p" { + if page == 0 { + page = num_pages.checked_sub(1).unwrap(); + } else { + page = page.checked_sub(1).unwrap(); + } } else { preset = selection.parse().expect("selected preset should be valid"); debug!(?preset, "selected preset");