Truncate display text on character boundaries and append `...`.
(s: &str, max_chars: usize)
| 1149 | |
| 1150 | /// Truncate display text on character boundaries and append `...`. |
| 1151 | pub(crate) fn truncate_display(s: &str, max_chars: usize) -> String { |
| 1152 | if s.chars().count() <= max_chars { |
| 1153 | s.to_string() |
| 1154 | } else { |
| 1155 | let kept: String = s.chars().take(max_chars.saturating_sub(3)).collect(); |
| 1156 | format!("{}...", kept) |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | /// Search the knowledge graph. |
| 1161 | #[derive(Parser, Debug)] |