MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / wrap_spans

Function wrap_spans

crates/opencode-tui/src/components/session.rs:1211–1243  ·  view source on GitHub ↗
(spans: Vec<Span<'static>>, width: usize)

Source from the content-addressed store, hash-verified

1209}
1210
1211fn wrap_spans(spans: Vec<Span<'static>>, width: usize) -> Vec<Vec<Span<'static>>> {
1212 if width == 0 {
1213 return vec![spans];
1214 }
1215
1216 let mut out: Vec<Vec<Span<'static>>> = vec![Vec::new()];
1217 let mut current_width = 0usize;
1218
1219 for span in spans {
1220 let style = span.style;
1221 for ch in span.content.chars() {
1222 if ch == '\n' {
1223 out.push(Vec::new());
1224 current_width = 0;
1225 continue;
1226 }
1227
1228 let ch_width = UnicodeWidthChar::width(ch).unwrap_or(0);
1229 if current_width + ch_width > width && !out.last().is_some_and(|line| line.is_empty()) {
1230 out.push(Vec::new());
1231 current_width = 0;
1232 }
1233
1234 push_merged_span(out.last_mut().expect("line exists"), ch, style);
1235 current_width += ch_width;
1236 }
1237 }
1238
1239 if out.is_empty() {
1240 out.push(Vec::new());
1241 }
1242 out
1243}
1244
1245fn push_merged_span(line: &mut Vec<Span<'static>>, ch: char, style: Style) {
1246 if let Some(last) = line.last_mut() {

Callers 1

wrap_block_lineFunction · 0.85

Calls 3

newFunction · 0.85
push_merged_spanFunction · 0.85
is_emptyMethod · 0.80

Tested by

no test coverage detected