use std::fmt;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum TranscriptNotice {
Apply,
BranchPush,
BranchPushError,
Commit,
CommitAssist,
CommitError,
CommitWarning,
ContinueError,
Error,
ForkError,
FollowUpTaskError,
Merge,
MergeError,
MainCheckoutWarning,
PasteImageError,
Personality,
QueueError,
Rebase,
RebaseAssist,
RebaseError,
ReplyError,
ReviewRequest,
ReviewComments,
ReviewCommentsWarning,
ReviewRequestSyncWarning,
StartError,
TurnMetadataError,
}
impl TranscriptNotice {
pub const fn prefix(self) -> &'static str {
match self {
Self::Apply => "[Apply]",
Self::BranchPush => "[Branch Push]",
Self::BranchPushError => "[Branch Push Error]",
Self::Commit => "[Commit]",
Self::CommitAssist => "[Commit Assist]",
Self::CommitError => "[Commit Error]",
Self::CommitWarning => "[Commit Warning]",
Self::ContinueError => "[Continue Error]",
Self::Error => "[Error]",
Self::ForkError => "[Fork Error]",
Self::FollowUpTaskError => "[Follow-Up Task Error]",
Self::Merge => "[Merge]",
Self::MergeError => "[Merge Error]",
Self::MainCheckoutWarning => "[Main Checkout Warning]",
Self::PasteImageError => "[Paste Image Error]",
Self::Personality => "[Personality]",
Self::QueueError => "[Queue Error]",
Self::Rebase => "[Sync]",
Self::RebaseAssist => "[Sync Assist]",
Self::RebaseError => "[Sync Error]",
Self::ReplyError => "[Reply Error]",
Self::ReviewRequest => "[Review Request]",
Self::ReviewComments => "[Review Comments]",
Self::ReviewCommentsWarning => "[Review Comments Warning]",
Self::ReviewRequestSyncWarning => "[Review Request Sync Warning]",
Self::StartError => "[Start Error]",
Self::TurnMetadataError => "[Turn Metadata Error]",
}
}
pub fn format(self, detail: impl fmt::Display) -> String {
format!("\n{}\n", self.format_line(detail))
}
pub fn format_line(self, detail: impl fmt::Display) -> String {
format!("{} {}", self.prefix(), detail)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_transcript_notice_prefixes_match_canonical_labels() {
let notices = [
(TranscriptNotice::Apply, "[Apply]"),
(TranscriptNotice::BranchPush, "[Branch Push]"),
(TranscriptNotice::BranchPushError, "[Branch Push Error]"),
(TranscriptNotice::Commit, "[Commit]"),
(TranscriptNotice::CommitAssist, "[Commit Assist]"),
(TranscriptNotice::CommitError, "[Commit Error]"),
(TranscriptNotice::CommitWarning, "[Commit Warning]"),
(TranscriptNotice::ContinueError, "[Continue Error]"),
(TranscriptNotice::Error, "[Error]"),
(TranscriptNotice::ForkError, "[Fork Error]"),
(
TranscriptNotice::FollowUpTaskError,
"[Follow-Up Task Error]",
),
(TranscriptNotice::Merge, "[Merge]"),
(TranscriptNotice::MergeError, "[Merge Error]"),
(
TranscriptNotice::MainCheckoutWarning,
"[Main Checkout Warning]",
),
(TranscriptNotice::PasteImageError, "[Paste Image Error]"),
(TranscriptNotice::Personality, "[Personality]"),
(TranscriptNotice::QueueError, "[Queue Error]"),
(TranscriptNotice::Rebase, "[Sync]"),
(TranscriptNotice::RebaseAssist, "[Sync Assist]"),
(TranscriptNotice::RebaseError, "[Sync Error]"),
(TranscriptNotice::ReplyError, "[Reply Error]"),
(TranscriptNotice::ReviewRequest, "[Review Request]"),
(TranscriptNotice::ReviewComments, "[Review Comments]"),
(
TranscriptNotice::ReviewCommentsWarning,
"[Review Comments Warning]",
),
(
TranscriptNotice::ReviewRequestSyncWarning,
"[Review Request Sync Warning]",
),
(TranscriptNotice::StartError, "[Start Error]"),
(TranscriptNotice::TurnMetadataError, "[Turn Metadata Error]"),
];
let prefixes = notices.map(|(notice, _)| notice.prefix());
let expected = notices.map(|(_, expected)| expected);
assert_eq!(prefixes, expected);
}
#[test]
fn test_transcript_notice_format_wraps_detail_as_paragraph() {
let notice = TranscriptNotice::RebaseAssist;
let formatted = notice.format("Attempt 1/3. Resolving conflicts in:\n- src/main.rs");
assert_eq!(
formatted,
"\n[Sync Assist] Attempt 1/3. Resolving conflicts in:\n- src/main.rs\n"
);
}
#[test]
fn test_transcript_notice_format_line_omits_paragraph_spacing() {
let notice = TranscriptNotice::Commit;
let formatted = notice.format_line("No changes to commit.");
assert_eq!(formatted, "[Commit] No changes to commit.");
}
}