1mod command;
8mod command_history;
9
10pub use command::{
11 ColorPolicy, CommandPreview, CommandPreviewWarning, ConfigOverlay, ExecutionMode,
12 GlobalOptions, ImmutabilityPolicy, JjCommandSpec, OperationIntegrationPolicy,
13 OperationLoadPolicy, OutputPolicy, PagerPolicy, RefreshPlan, SafetyClass, WorkingCopyPolicy,
14};
15pub use command_history::{
16 CommandExecutionContext, CommandFamily, CommandHistory, CommandIdentity, CommandRecord,
17 CommandRecordFinish, CommandRecordId, CommandRecordStart, CommandResultSummary, CommandSource,
18 CommandTiming, ExitStatusSummary, GlobalOptionsSnapshot, OutputRetention, PendingCommandRecord,
19 SourceAction, SourceView, StreamSummary,
20};
21
22#[derive(Clone, Debug, Default, Eq, PartialEq)]
27pub struct LogSnapshot {
28 title: String,
29 rendered: String,
30 entries: Vec<LogEntry>,
31}
32
33impl LogSnapshot {
34 #[must_use]
39 pub fn new(rendered: impl Into<String>, entries: Vec<LogEntry>) -> Self {
40 Self {
41 title: String::new(),
42 rendered: rendered.into(),
43 entries,
44 }
45 }
46
47 #[must_use]
49 pub fn with_title(mut self, title: impl Into<String>) -> Self {
50 self.title = title.into();
51 self
52 }
53
54 #[must_use]
56 pub fn title(&self) -> &str {
57 &self.title
58 }
59
60 #[must_use]
62 pub fn rendered(&self) -> &str {
63 &self.rendered
64 }
65
66 #[must_use]
68 pub fn entries(&self) -> &[LogEntry] {
69 &self.entries
70 }
71
72 #[must_use]
74 pub fn into_parts(self) -> (String, String, Vec<LogEntry>) {
75 (self.title, self.rendered, self.entries)
76 }
77}
78
79#[derive(Clone, Debug, Default, Eq, PartialEq)]
81pub struct DiffSnapshot {
82 title: String,
83 change_id: String,
84 rendered: String,
85 file_stats: Vec<DiffFileStat>,
86}
87
88impl DiffSnapshot {
89 #[must_use]
91 pub fn new(change_id: impl Into<String>, rendered: impl Into<String>) -> Self {
92 Self {
93 title: String::new(),
94 change_id: change_id.into(),
95 rendered: rendered.into(),
96 file_stats: Vec::new(),
97 }
98 }
99
100 #[must_use]
102 pub fn with_title(mut self, title: impl Into<String>) -> Self {
103 self.title = title.into();
104 self
105 }
106
107 #[must_use]
109 pub fn with_file_stats(mut self, file_stats: Vec<DiffFileStat>) -> Self {
110 self.file_stats = file_stats;
111 self
112 }
113
114 #[must_use]
116 pub fn title(&self) -> &str {
117 &self.title
118 }
119
120 #[must_use]
122 pub fn change_id(&self) -> &str {
123 &self.change_id
124 }
125
126 #[must_use]
128 pub fn rendered(&self) -> &str {
129 &self.rendered
130 }
131
132 #[must_use]
134 pub fn file_stats(&self) -> &[DiffFileStat] {
135 &self.file_stats
136 }
137
138 #[must_use]
140 pub fn into_parts(self) -> (String, String, String, Vec<DiffFileStat>) {
141 (self.title, self.change_id, self.rendered, self.file_stats)
142 }
143}
144
145#[derive(Clone, Debug, Default, Eq, PartialEq)]
147pub struct InspectionSnapshot {
148 title: String,
149 target: String,
150 rendered: String,
151}
152
153impl InspectionSnapshot {
154 #[must_use]
156 pub fn new(target: impl Into<String>, rendered: impl Into<String>) -> Self {
157 Self {
158 title: String::new(),
159 target: target.into(),
160 rendered: rendered.into(),
161 }
162 }
163
164 #[must_use]
166 pub fn with_title(mut self, title: impl Into<String>) -> Self {
167 self.title = title.into();
168 self
169 }
170
171 #[must_use]
173 pub fn title(&self) -> &str {
174 &self.title
175 }
176
177 #[must_use]
179 pub fn target(&self) -> &str {
180 &self.target
181 }
182
183 #[must_use]
185 pub fn rendered(&self) -> &str {
186 &self.rendered
187 }
188
189 #[must_use]
191 pub fn into_parts(self) -> (String, String, String) {
192 (self.title, self.target, self.rendered)
193 }
194}
195
196#[derive(Clone, Debug, Default, Eq, PartialEq)]
198pub struct DiffFileStat {
199 path: String,
200 added: usize,
201 removed: usize,
202 rendered: String,
203}
204
205impl DiffFileStat {
206 #[must_use]
208 pub fn new(path: impl Into<String>, added: usize, removed: usize) -> Self {
209 Self {
210 path: path.into(),
211 added,
212 removed,
213 rendered: String::new(),
214 }
215 }
216
217 #[must_use]
219 pub fn with_rendered(mut self, rendered: impl Into<String>) -> Self {
220 self.rendered = rendered.into();
221 self
222 }
223
224 #[must_use]
226 pub fn path(&self) -> &str {
227 &self.path
228 }
229
230 #[must_use]
232 pub const fn added(&self) -> usize {
233 self.added
234 }
235
236 #[must_use]
238 pub const fn removed(&self) -> usize {
239 self.removed
240 }
241
242 #[must_use]
244 pub fn rendered(&self) -> &str {
245 &self.rendered
246 }
247}
248
249#[derive(Clone, Debug, Eq, PartialEq)]
251pub struct LogEntry {
252 change_id: String,
253 commit_id: String,
254 description: String,
255 details: String,
256 rendered_line: usize,
257}
258
259impl LogEntry {
260 #[must_use]
265 pub fn new(
266 change_id: impl Into<String>,
267 commit_id: impl Into<String>,
268 description: impl Into<String>,
269 ) -> Self {
270 Self {
271 change_id: change_id.into(),
272 commit_id: commit_id.into(),
273 description: description.into(),
274 details: String::new(),
275 rendered_line: 0,
276 }
277 }
278
279 #[must_use]
281 pub fn with_details(mut self, details: impl Into<String>) -> Self {
282 self.details = details.into();
283 self
284 }
285
286 #[must_use]
288 pub const fn with_rendered_line(mut self, rendered_line: usize) -> Self {
289 self.rendered_line = rendered_line;
290 self
291 }
292
293 #[must_use]
295 pub fn change_id(&self) -> &str {
296 &self.change_id
297 }
298
299 #[must_use]
301 pub fn commit_id(&self) -> &str {
302 &self.commit_id
303 }
304
305 #[must_use]
307 pub fn description(&self) -> &str {
308 &self.description
309 }
310
311 #[must_use]
313 pub fn details(&self) -> &str {
314 &self.details
315 }
316
317 #[must_use]
319 pub const fn rendered_line(&self) -> usize {
320 self.rendered_line
321 }
322
323 #[must_use]
325 pub fn summary(&self) -> &str {
326 let first_line = self.description.lines().next().unwrap_or_default();
327 if first_line.is_empty() {
328 "(no description set)"
329 } else {
330 first_line
331 }
332 }
333}