MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / truncate

Method truncate

atomic-cli/src/output/table.rs:422–452  ·  view source on GitHub ↗

Truncate text to fit within a maximum width.

(text: &str, max_width: usize)

Source from the content-addressed store, hash-verified

420
421 /// Truncate text to fit within a maximum width.
422 fn truncate(text: &str, max_width: usize) -> String {
423 if max_width == 0 {
424 return text.to_string();
425 }
426
427 let text_width = console::measure_text_width(text);
428 if text_width <= max_width {
429 return text.to_string();
430 }
431
432 if max_width <= 3 {
433 return "...".chars().take(max_width).collect();
434 }
435
436 // Find a safe truncation point
437 let mut result = String::new();
438 let mut current_width = 0;
439 let target_width = max_width - 3; // Leave room for "..."
440
441 for ch in text.chars() {
442 let char_width = console::measure_text_width(&ch.to_string());
443 if current_width + char_width > target_width {
444 break;
445 }
446 result.push(ch);
447 current_width += char_width;
448 }
449
450 result.push_str("...");
451 result
452 }
453
454 /// Render the table to a string.
455 fn render(&self) -> String {

Callers 12

runMethod · 0.80
try_turn_end_lockMethod · 0.80
with_accumulatorMethod · 0.80
save_accumulatorMethod · 0.80
write_fileMethod · 0.80
kg_fts_searchMethod · 0.80
search_embeddingsMethod · 0.80
search_embeddingsMethod · 0.80
kg_fts_searchMethod · 0.80
search_contentFunction · 0.80
vault_kg_searchMethod · 0.80
build_context_stringFunction · 0.80

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected