MCPcopy Create free account
hub / github.com/GCWing/BitFun / wrap_hard_display_width

Method wrap_hard_display_width

src/apps/cli/src/ui/chat/render.rs:409–448  ·  view source on GitHub ↗
(s: &str, max_width: usize)

Source from the content-addressed store, hash-verified

407 }
408
409 fn wrap_hard_display_width(s: &str, max_width: usize) -> Vec<String> {
410 if max_width == 0 {
411 return vec![String::new()];
412 }
413 if UnicodeWidthStr::width(s) <= max_width {
414 return vec![s.to_string()];
415 }
416
417 let mut lines: Vec<String> = Vec::new();
418 let mut current = String::new();
419 let mut current_width = 0usize;
420
421 for ch in s.chars() {
422 let ch_width = UnicodeWidthChar::width(ch).unwrap_or(0);
423
424 if !current.is_empty() && current_width + ch_width > max_width {
425 lines.push(std::mem::take(&mut current));
426 current_width = 0;
427 }
428
429 // Even if a single char is wider than max_width, still render it.
430 current.push(ch);
431 current_width += ch_width;
432
433 if current_width >= max_width && !current.is_empty() {
434 lines.push(std::mem::take(&mut current));
435 current_width = 0;
436 }
437 }
438
439 if !current.is_empty() {
440 lines.push(current);
441 }
442
443 if lines.is_empty() {
444 lines.push(String::new());
445 }
446
447 lines
448 }
449
450 // Top margin between messages (previously provided partly by role/timestamp line).
451 items.push(blank_line());

Callers

nothing calls this directly

Calls 3

takeFunction · 0.85
is_emptyMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected