Refactor: improve readability in CLI modules

- project_files.rs: Fix UTF-8 safety in truncate_for_display (use char
  boundaries instead of byte slicing), add test for multi-byte chars
- task_execution.rs: Extract recoverable_error_name() helper, use shared
  calculate_retry_delay() from error_handling.rs to eliminate duplication
- ui_writer_impl.rs: Extract duration_color() helper for timing display,
  add clear_tool_state() to consolidate repeated mutex clearing patterns

Agent: carmack
This commit is contained in:
Dhanji R. Prasanna
2026-01-13 05:58:54 +05:30
parent f30f145c85
commit 5c9404e292
3 changed files with 77 additions and 78 deletions

View File

@@ -166,10 +166,12 @@ fn find_fallback_title(content: &str) -> Option<String> {
/// Truncate a string for display, adding ellipsis if needed.
fn truncate_for_display(s: &str, max_len: usize) -> String {
if s.len() > max_len {
format!("{}...", &s[..max_len - 3])
} else {
if s.chars().count() <= max_len {
s.to_string()
} else {
// Truncate at character boundary, not byte boundary
let truncated: String = s.chars().take(max_len.saturating_sub(3)).collect();
format!("{}...", truncated)
}
}
@@ -204,6 +206,15 @@ mod tests {
assert_eq!(truncated.len(), 100);
}
#[test]
fn test_truncate_for_display_utf8() {
// Multi-byte characters should not cause panics
let emoji_text = "Hello 👋 World 🌍 Test ✨ More text here and more";
let truncated = truncate_for_display(emoji_text, 15);
assert!(truncated.ends_with("..."));
assert!(truncated.chars().count() <= 15);
}
#[test]
fn test_combine_project_content_all_some() {
let workspace = std::path::PathBuf::from("/test/workspace");