Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One-letter page selection and page number roll over on Rust version #372

Merged
merged 1 commit into from
Dec 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions crates/hyfetch/src/bin/hyfetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> = <Preset as VariantNames>::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(
Expand All @@ -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");
Expand Down