refact(review): user intention query
This commit is contained in:
@@ -106,17 +106,17 @@ fn get_action_for_package(
|
|||||||
Ok(ContinueWithReview::Yes)
|
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<ReviewIntention> {
|
fn ask_user_action_for_package(supports_as_dependency: bool) -> Result<ReviewIntention> {
|
||||||
print!("assign to (g)roup, (d)elete, (s)kip, (i)nfo, ");
|
print_query(supports_as_dependency)?;
|
||||||
|
|
||||||
if supports_as_dependency {
|
|
||||||
print!("(a)s dependency, ");
|
|
||||||
}
|
|
||||||
print!("(q)uit? ");
|
|
||||||
stdout().lock().flush()?;
|
|
||||||
|
|
||||||
match read_single_char_from_terminal()?.to_ascii_lowercase() {
|
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),
|
'd' => Ok(ReviewIntention::Delete),
|
||||||
'g' => Ok(ReviewIntention::AssignGroup),
|
'g' => Ok(ReviewIntention::AssignGroup),
|
||||||
'i' => Ok(ReviewIntention::Info),
|
'i' => Ok(ReviewIntention::Info),
|
||||||
@@ -126,6 +126,27 @@ fn ask_user_action_for_package(supports_as_dependency: bool) -> Result<ReviewInt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Print a space-terminated string that asks the user for the desired action.
|
||||||
|
/// The items of the string depend on whether the backend supports dependent
|
||||||
|
/// packages.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This function will return an error if stdout cannot be flushed.
|
||||||
|
fn print_query(supports_as_dependency: bool) -> 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<Group>]) {
|
fn print_enumerated_groups(groups: &[Rc<Group>]) {
|
||||||
let number_digits = get_amount_of_digits_for_number(groups.len());
|
let number_digits = get_amount_of_digits_for_number(groups.len());
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user