(spans: Vec<Span<'static>>, width: usize)
| 1209 | } |
| 1210 | |
| 1211 | fn 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 | |
| 1245 | fn push_merged_span(line: &mut Vec<Span<'static>>, ch: char, style: Style) { |
| 1246 | if let Some(last) = line.last_mut() { |
no test coverage detected