Format entries for default output. # Arguments `entries` - History entries to format `hash_length` - Number of hash characters to display # Returns Formatted output string.
(&self, entries: &[HistoryEntry], hash_length: usize)
| 237 | /// |
| 238 | /// Formatted output string. |
| 239 | pub(crate) fn format_default(&self, entries: &[HistoryEntry], hash_length: usize) -> String { |
| 240 | let mut output = String::new(); |
| 241 | |
| 242 | for (i, entry) in entries.iter().enumerate() { |
| 243 | // Add separator between entries |
| 244 | if i > 0 { |
| 245 | output.push('\n'); |
| 246 | } |
| 247 | |
| 248 | // Change header line with hash between === markers for easy copy-paste |
| 249 | let hash_str = format_hash_with_length(&entry.hash, hash_length); |
| 250 | let tagged_marker = if entry.is_tagged { " (tag)" } else { "" }; |
| 251 | let seq_str = format!("#{}", entry.sequence); |
| 252 | output.push_str(&format!( |
| 253 | "{} === {} ==={}\n", |
| 254 | hint(&seq_str), |
| 255 | style_hash(&hash_str), |
| 256 | hint(tagged_marker) |
| 257 | )); |
| 258 | |
| 259 | // Authors |
| 260 | if let Some(authors) = entry.authors() { |
| 261 | for author in authors { |
| 262 | let author_line = if let Some(ref email) = author.email { |
| 263 | format!("{} <{}>", author.name, email) |
| 264 | } else { |
| 265 | author.name.clone() |
| 266 | }; |
| 267 | output.push_str(&format!("Author: {}\n", style_author(&author_line))); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | // Timestamp |
| 272 | if let Some(ts) = entry.timestamp() { |
| 273 | let formatted_time = format_timestamp(&ts); |
| 274 | output.push_str(&format!("Date: {}\n", style_timestamp(&formatted_time))); |
| 275 | } |
| 276 | |
| 277 | // Message |
| 278 | output.push('\n'); |
| 279 | if let Some(message) = entry.message() { |
| 280 | // Indent message lines |
| 281 | for line in message.lines() { |
| 282 | output.push_str(&format!(" {}\n", line)); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | // Description |
| 287 | if let Some(description) = entry.description() { |
| 288 | output.push('\n'); |
| 289 | for line in description.lines() { |
| 290 | output.push_str(&format!(" {}\n", line)); |
| 291 | } |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | output |
| 296 | } |