oxicode_textarea/render/
line_utils.rs1use ratatui::text::Line;
2use ratatui::text::Span;
3
4pub fn line_to_static(line: &Line<'_>) -> Line<'static> {
6 Line {
7 style: line.style,
8 alignment: line.alignment,
9 spans: line
10 .spans
11 .iter()
12 .map(|s| Span {
13 style: s.style,
14 content: std::borrow::Cow::Owned(s.content.to_string()),
15 })
16 .collect(),
17 }
18}
19
20pub fn push_owned_lines<'a>(src: &[Line<'a>], out: &mut Vec<Line<'static>>) {
22 for l in src {
23 out.push(line_to_static(l));
24 }
25}
26
27pub fn is_blank_line_spaces_only(line: &Line<'_>) -> bool {
30 if line.spans.is_empty() {
31 return true;
32 }
33 line.spans
34 .iter()
35 .all(|s| s.content.is_empty() || s.content.chars().all(|c| c == ' '))
36}
37
38pub fn prefix_lines(
41 lines: Vec<Line<'static>>,
42 initial_prefix: Span<'static>,
43 subsequent_prefix: Span<'static>,
44) -> Vec<Line<'static>> {
45 lines
46 .into_iter()
47 .enumerate()
48 .map(|(i, l)| {
49 let mut spans = Vec::with_capacity(l.spans.len() + 1);
50 spans.push(if i == 0 {
51 initial_prefix.clone()
52 } else {
53 subsequent_prefix.clone()
54 });
55 spans.extend(l.spans);
56 Line::from(spans).style(l.style)
57 })
58 .collect()
59}