MCPcopy Create free account
hub / github.com/ccusage/ccusage / wrap_cell_line

Function wrap_cell_line

rust/crates/ccusage-terminal/src/table.rs:246–279  ·  view source on GitHub ↗
(line: &str, width: usize)

Source from the content-addressed store, hash-verified

244}
245
246fn wrap_cell_line(line: &str, width: usize) -> Vec<String> {
247 if line.split_whitespace().count() <= 1 {
248 return vec![truncate_visible(line, width)];
249 }
250
251 let mut lines = Vec::new();
252 let mut current = String::new();
253 for word in line.split_whitespace() {
254 let candidate_width = if current.is_empty() {
255 visible_width(word)
256 } else {
257 visible_width(&current) + 1 + visible_width(word)
258 };
259 if candidate_width <= width {
260 if !current.is_empty() {
261 current.push(' ');
262 }
263 current.push_str(word);
264 } else {
265 if !current.is_empty() {
266 lines.push(current);
267 }
268 current = if visible_width(word) > width {
269 truncate_visible(word, width)
270 } else {
271 word.to_string()
272 };
273 }
274 }
275 if !current.is_empty() {
276 lines.push(current);
277 }
278 lines
279}
280
281fn truncate_visible(value: &str, width: usize) -> String {
282 if visible_width(value) <= width {

Callers 1

wrap_cell_linesFunction · 0.85

Calls 3

visible_widthFunction · 0.85
truncate_visibleFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected