MCPcopy Create free account
hub / github.com/evilsocket/cake / wrap_text

Function wrap_text

cake-cli/src/chat.rs:247–273  ·  view source on GitHub ↗
(
    lines: &mut Vec<Line<'static>>,
    text: &str,
    prefix: &str,
    style: Style,
    wrap_width: usize,
)

Source from the content-addressed store, hash-verified

245}
246
247fn wrap_text(
248 lines: &mut Vec<Line<'static>>,
249 text: &str,
250 prefix: &str,
251 style: Style,
252 wrap_width: usize,
253) {
254 for text_line in text.split('\n') {
255 let full = format!("{}{}", prefix, text_line);
256 if wrap_width == 0 {
257 lines.push(Line::from(Span::styled(full, style)));
258 continue;
259 }
260 let chars: Vec<char> = full.chars().collect();
261 if chars.is_empty() {
262 lines.push(Line::from(Span::styled(String::new(), style)));
263 } else {
264 let mut pos = 0;
265 while pos < chars.len() {
266 let end = (pos + wrap_width).min(chars.len());
267 let chunk: String = chars[pos..end].iter().collect();
268 lines.push(Line::from(Span::styled(chunk, style)));
269 pos = end;
270 }
271 }
272 }
273}
274
275/// Extract the text inside an open (unclosed) `<think>` block, if any.
276/// Returns empty string if there's no open think block.

Callers 1

build_message_linesFunction · 0.85

Calls 1

pushMethod · 0.45

Tested by

no test coverage detected