From 8b476f222d849dae4704ef8b51ef34b7b1138b8d Mon Sep 17 00:00:00 2001 From: steven-omaha <35634100+steven-omaha@users.noreply.github.com> Date: Tue, 16 May 2023 16:20:31 +0200 Subject: [PATCH] refact(review): user intention query --- crates/pacdef_core/src/review/mod.rs | 37 ++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/crates/pacdef_core/src/review/mod.rs b/crates/pacdef_core/src/review/mod.rs index dc78ada..3b29f5c 100644 --- a/crates/pacdef_core/src/review/mod.rs +++ b/crates/pacdef_core/src/review/mod.rs @@ -106,17 +106,17 @@ fn get_action_for_package( Ok(ContinueWithReview::Yes) } +/// Ask the user for the desired action, and return the associated +/// [`ReviewIntention`]. The query depends on the capabilities of the backend. +/// +/// # Errors +/// +/// This function will return an error if stdin or stdout cannot be accessed. fn ask_user_action_for_package(supports_as_dependency: bool) -> Result { - print!("assign to (g)roup, (d)elete, (s)kip, (i)nfo, "); - - if supports_as_dependency { - print!("(a)s dependency, "); - } - print!("(q)uit? "); - stdout().lock().flush()?; + print_query(supports_as_dependency)?; match read_single_char_from_terminal()?.to_ascii_lowercase() { - 'a' => Ok(ReviewIntention::AsDependency), + 'a' if supports_as_dependency => Ok(ReviewIntention::AsDependency), 'd' => Ok(ReviewIntention::Delete), 'g' => Ok(ReviewIntention::AssignGroup), 'i' => Ok(ReviewIntention::Info), @@ -126,6 +126,27 @@ fn ask_user_action_for_package(supports_as_dependency: bool) -> Result Result<()> { + let mut query = String::from("assign to (g)roup, (d)elete, (s)kip, (i)nfo, "); + + if supports_as_dependency { + query.push_str("(a)s dependency, "); + } + + query.push_str("(q)uit? "); + + print!("{query}"); + stdout().lock().flush()?; + Ok(()) +} + fn print_enumerated_groups(groups: &[Rc]) { let number_digits = get_amount_of_digits_for_number(groups.len());