Format entries for oneline 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)
| 337 | /// |
| 338 | /// Formatted output string. |
| 339 | pub(crate) fn format_oneline(&self, entries: &[HistoryEntry], hash_length: usize) -> String { |
| 340 | let mut output = String::new(); |
| 341 | |
| 342 | // Calculate max author width for alignment |
| 343 | let max_author_width = entries |
| 344 | .iter() |
| 345 | .filter_map(|e| e.authors()) |
| 346 | .filter_map(|authors| authors.first()) |
| 347 | .map(|a| a.name.len()) |
| 348 | .max() |
| 349 | .unwrap_or(10) |
| 350 | .min(20); // Cap at 20 characters |
| 351 | |
| 352 | for entry in entries { |
| 353 | let hash_str = format_hash_with_length(&entry.hash, hash_length); |
| 354 | |
| 355 | let date_str = entry |
| 356 | .timestamp() |
| 357 | .map(|ts| ts.format("%Y-%m-%d").to_string()) |
| 358 | .unwrap_or_else(|| " ".to_string()); |
| 359 | |
| 360 | let author_name = entry |
| 361 | .authors() |
| 362 | .and_then(|authors| authors.first()) |
| 363 | .map(|a| truncate_string(&a.name, max_author_width)) |
| 364 | .unwrap_or_else(|| "(unknown)".to_string()); |
| 365 | |
| 366 | let message = entry.message().unwrap_or("(no message)"); |
| 367 | let first_line = message.lines().next().unwrap_or(message); |
| 368 | |
| 369 | let tagged_marker = if entry.is_tagged { "*" } else { " " }; |
| 370 | |
| 371 | output.push_str(&format!( |
| 372 | "{}{} {} {:width$} {}\n", |
| 373 | style_hash(&hash_str), |
| 374 | hint(tagged_marker), |
| 375 | style_timestamp(&date_str), |
| 376 | style_author(&author_name), |
| 377 | first_line, |
| 378 | width = max_author_width |
| 379 | )); |
| 380 | } |
| 381 | |
| 382 | output |
| 383 | } |
| 384 | |
| 385 | /// Format entries for JSON output. |
| 386 | /// |