1use std::fmt;
2
3#[derive(Clone, Copy, Debug, Eq, PartialEq)]
10pub enum TranscriptNotice {
11 Apply,
13 BranchPush,
15 BranchPushError,
17 Commit,
19 CommitAssist,
21 CommitError,
23 CommitWarning,
25 ContinueError,
27 Error,
29 ForkError,
31 FollowUpTaskError,
33 Merge,
35 MergeError,
37 MainCheckoutWarning,
39 PasteImageError,
41 Personality,
43 QueueError,
45 Rebase,
47 RebaseAssist,
49 RebaseError,
51 ReplyError,
53 ReviewRequest,
55 ReviewComments,
57 ReviewCommentsWarning,
59 ReviewRequestSyncWarning,
61 StartError,
63 TurnMetadataError,
65}
66
67impl TranscriptNotice {
68 pub const fn prefix(self) -> &'static str {
70 match self {
71 Self::Apply => "[Apply]",
72 Self::BranchPush => "[Branch Push]",
73 Self::BranchPushError => "[Branch Push Error]",
74 Self::Commit => "[Commit]",
75 Self::CommitAssist => "[Commit Assist]",
76 Self::CommitError => "[Commit Error]",
77 Self::CommitWarning => "[Commit Warning]",
78 Self::ContinueError => "[Continue Error]",
79 Self::Error => "[Error]",
80 Self::ForkError => "[Fork Error]",
81 Self::FollowUpTaskError => "[Follow-Up Task Error]",
82 Self::Merge => "[Merge]",
83 Self::MergeError => "[Merge Error]",
84 Self::MainCheckoutWarning => "[Main Checkout Warning]",
85 Self::PasteImageError => "[Paste Image Error]",
86 Self::Personality => "[Personality]",
87 Self::QueueError => "[Queue Error]",
88 Self::Rebase => "[Sync]",
89 Self::RebaseAssist => "[Sync Assist]",
90 Self::RebaseError => "[Sync Error]",
91 Self::ReplyError => "[Reply Error]",
92 Self::ReviewRequest => "[Review Request]",
93 Self::ReviewComments => "[Review Comments]",
94 Self::ReviewCommentsWarning => "[Review Comments Warning]",
95 Self::ReviewRequestSyncWarning => "[Review Request Sync Warning]",
96 Self::StartError => "[Start Error]",
97 Self::TurnMetadataError => "[Turn Metadata Error]",
98 }
99 }
100
101 pub fn format(self, detail: impl fmt::Display) -> String {
103 format!("\n{}\n", self.format_line(detail))
104 }
105
106 pub fn format_line(self, detail: impl fmt::Display) -> String {
109 format!("{} {}", self.prefix(), detail)
110 }
111}
112
113#[cfg(test)]
114mod tests {
115 use super::*;
116
117 #[test]
118 fn test_transcript_notice_prefixes_match_canonical_labels() {
119 let notices = [
121 (TranscriptNotice::Apply, "[Apply]"),
122 (TranscriptNotice::BranchPush, "[Branch Push]"),
123 (TranscriptNotice::BranchPushError, "[Branch Push Error]"),
124 (TranscriptNotice::Commit, "[Commit]"),
125 (TranscriptNotice::CommitAssist, "[Commit Assist]"),
126 (TranscriptNotice::CommitError, "[Commit Error]"),
127 (TranscriptNotice::CommitWarning, "[Commit Warning]"),
128 (TranscriptNotice::ContinueError, "[Continue Error]"),
129 (TranscriptNotice::Error, "[Error]"),
130 (TranscriptNotice::ForkError, "[Fork Error]"),
131 (
132 TranscriptNotice::FollowUpTaskError,
133 "[Follow-Up Task Error]",
134 ),
135 (TranscriptNotice::Merge, "[Merge]"),
136 (TranscriptNotice::MergeError, "[Merge Error]"),
137 (
138 TranscriptNotice::MainCheckoutWarning,
139 "[Main Checkout Warning]",
140 ),
141 (TranscriptNotice::PasteImageError, "[Paste Image Error]"),
142 (TranscriptNotice::Personality, "[Personality]"),
143 (TranscriptNotice::QueueError, "[Queue Error]"),
144 (TranscriptNotice::Rebase, "[Sync]"),
145 (TranscriptNotice::RebaseAssist, "[Sync Assist]"),
146 (TranscriptNotice::RebaseError, "[Sync Error]"),
147 (TranscriptNotice::ReplyError, "[Reply Error]"),
148 (TranscriptNotice::ReviewRequest, "[Review Request]"),
149 (TranscriptNotice::ReviewComments, "[Review Comments]"),
150 (
151 TranscriptNotice::ReviewCommentsWarning,
152 "[Review Comments Warning]",
153 ),
154 (
155 TranscriptNotice::ReviewRequestSyncWarning,
156 "[Review Request Sync Warning]",
157 ),
158 (TranscriptNotice::StartError, "[Start Error]"),
159 (TranscriptNotice::TurnMetadataError, "[Turn Metadata Error]"),
160 ];
161
162 let prefixes = notices.map(|(notice, _)| notice.prefix());
164 let expected = notices.map(|(_, expected)| expected);
165
166 assert_eq!(prefixes, expected);
168 }
169
170 #[test]
171 fn test_transcript_notice_format_wraps_detail_as_paragraph() {
172 let notice = TranscriptNotice::RebaseAssist;
174
175 let formatted = notice.format("Attempt 1/3. Resolving conflicts in:\n- src/main.rs");
177
178 assert_eq!(
180 formatted,
181 "\n[Sync Assist] Attempt 1/3. Resolving conflicts in:\n- src/main.rs\n"
182 );
183 }
184
185 #[test]
186 fn test_transcript_notice_format_line_omits_paragraph_spacing() {
187 let notice = TranscriptNotice::Commit;
189
190 let formatted = notice.format_line("No changes to commit.");
192
193 assert_eq!(formatted, "[Commit] No changes to commit.");
195 }
196}