Skip to content

Commit

Permalink
Merge pull request #45 from Holzhaus/quit-in-selection
Browse files Browse the repository at this point in the history
feat(import): Add support for quitting in candidate selection screen
  • Loading branch information
Holzhaus authored Dec 29, 2024
2 parents 3badbdc + 81dccd5 commit 390b1bc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/cli/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ async fn select_release<'a>(
ui::ReleaseCandidateSelectionResult::Skipped => {
return Ok(SelectionResult::Skipped)
}
ui::ReleaseCandidateSelectionResult::Quit => return Ok(SelectionResult::Quit),
};
};
allow_autoselection = false;
Expand Down
10 changes: 10 additions & 0 deletions src/cli/ui/select_candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub enum ReleaseCandidateSelectionResult<'a, T: ReleaseLike> {
/// Save release information to file (for debugging).
#[cfg(feature = "dev")]
DumpReleaseInfo,
/// Quit (i.e., skip this item and all following).
Quit,
}

/// An option presented when selecting a release.
Expand All @@ -49,6 +51,8 @@ enum ReleaseCandidateSelectionOption<'a, T: ReleaseLike> {
DumpReleaseInfo,
/// Skip this item.
SkipItem,
/// Quit (i.e., skip this item and all following).
Quit,
}

// Manual implementation of `Clone` to work around unnecessary trait bound `T: Clone`.
Expand All @@ -61,6 +65,7 @@ impl<T: ReleaseLike> Clone for ReleaseCandidateSelectionOption<'_, T> {
#[cfg(feature = "dev")]
Self::DumpReleaseInfo => Self::DumpReleaseInfo,
Self::SkipItem => Self::SkipItem,
Self::Quit => Self::Quit,
}
}
}
Expand Down Expand Up @@ -141,6 +146,7 @@ impl<T: ReleaseLike> fmt::Display for StyledReleaseCandidateSelectionOption<'_,
ReleaseCandidateSelectionOption::PrintTrackList => "Print Tracklist",
#[cfg(feature = "dev")]
ReleaseCandidateSelectionOption::DumpReleaseInfo => "Dump Releases for Debugging",
ReleaseCandidateSelectionOption::Quit => "Quit",
ReleaseCandidateSelectionOption::Candidate(_) => unreachable!(),
};
write!(
Expand Down Expand Up @@ -192,6 +198,7 @@ pub fn select_candidate<'a, T: ReleaseLike>(
#[cfg(feature = "dev")]
ReleaseCandidateSelectionOption::DumpReleaseInfo,
ReleaseCandidateSelectionOption::SkipItem,
ReleaseCandidateSelectionOption::Quit,
];
let options: Vec<StyledReleaseCandidateSelectionOption<'a, T>> = candidates
.iter()
Expand Down Expand Up @@ -227,6 +234,9 @@ pub fn select_candidate<'a, T: ReleaseLike>(
| Err(InquireError::OperationCanceled) => {
break Ok(ReleaseCandidateSelectionResult::Skipped)
}
Ok(ReleaseCandidateSelectionOption::Quit) => {
break Ok(ReleaseCandidateSelectionResult::Quit)
}
Err(err) => Err(err)?,
}
}
Expand Down

0 comments on commit 390b1bc

Please sign in to comment.