git-iris 2.0.8

AI-powered Git workflow assistant for smart commits, code reviews, changelogs, and release notes
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
//! Chat rendering and markdown formatting for Iris Studio

use pulldown_cmark::{Event, Options, Parser, Tag, TagEnd};
use ratatui::prelude::Stylize;
use ratatui::style::{Modifier, Style};
use ratatui::text::{Line, Span};

use crate::studio::components::syntax::SyntaxHighlighter;
use crate::studio::state::{ChatRole, ChatState};
use crate::studio::theme;

/// Render chat messages into formatted lines
pub fn render_messages(
    chat_state: &ChatState,
    content_width: usize,
    last_render_ms: u128,
) -> Vec<Line<'_>> {
    let mut lines: Vec<Line> = Vec::new();

    for (msg_idx, msg) in chat_state.messages.iter().enumerate() {
        // Message header with role indicator
        let (prefix, prefix_style, content_style) = match msg.role {
            ChatRole::User => (
                "◆ You",
                Style::default()
                    .fg(theme::accent_secondary())
                    .add_modifier(Modifier::BOLD),
                Style::default().fg(theme::text_primary_color()),
            ),
            ChatRole::Iris => (
                "◇ Iris",
                Style::default()
                    .fg(theme::accent_primary())
                    .add_modifier(Modifier::BOLD),
                Style::default().fg(theme::text_secondary_color()),
            ),
        };

        lines.push(Line::from(Span::styled(prefix, prefix_style)));

        // Parse and render message content with markdown-like formatting
        let formatted_lines = format_markdown(&msg.content, content_width, content_style);
        lines.extend(formatted_lines);

        // Add separator between messages (except last)
        if msg_idx < chat_state.messages.len() - 1 {
            lines.push(Line::from(""));
            lines.push(Line::from(Span::styled(
                "".repeat(content_width.min(40)),
                Style::default().fg(theme::text_dim_color()),
            )));
            lines.push(Line::from(""));
        }
    }

    // Show streaming response or typing indicator if Iris is responding
    if chat_state.is_responding {
        if !chat_state.messages.is_empty() {
            lines.push(Line::from(""));
            lines.push(Line::from(Span::styled(
                "".repeat(content_width.min(40)),
                Style::default().fg(theme::text_dim_color()),
            )));
            lines.push(Line::from(""));
        }

        // Show streaming content if available
        if let Some(ref streaming) = chat_state.streaming_response {
            // Iris header for streaming response
            lines.push(Line::from(Span::styled(
                "◇ Iris",
                Style::default()
                    .fg(theme::accent_primary())
                    .add_modifier(Modifier::BOLD),
            )));

            // Render the streaming content with markdown formatting
            let content_style = Style::default().fg(theme::text_secondary_color());
            let formatted_lines = format_markdown(streaming, content_width, content_style);
            lines.extend(formatted_lines);

            // Show tool activity history
            for tool in &chat_state.tool_history {
                lines.push(Line::from(vec![
                    Span::styled("", Style::default().fg(theme::accent_secondary())),
                    Span::styled(
                        tool.clone(),
                        Style::default()
                            .fg(theme::text_muted_color())
                            .add_modifier(Modifier::ITALIC),
                    ),
                ]));
            }

            // Add streaming cursor
            let spinner =
                theme::SPINNER_BRAILLE[last_render_ms as usize / 80 % theme::SPINNER_BRAILLE.len()];
            lines.push(Line::from(Span::styled(
                format!(" {}", spinner),
                Style::default().fg(theme::accent_primary()),
            )));
        } else {
            // Just show thinking indicator when no streaming content yet
            let spinner =
                theme::SPINNER_BRAILLE[last_render_ms as usize / 80 % theme::SPINNER_BRAILLE.len()];

            // Show tool history when thinking
            for tool in &chat_state.tool_history {
                lines.push(Line::from(vec![
                    Span::styled("", Style::default().fg(theme::accent_secondary())),
                    Span::styled(
                        tool.clone(),
                        Style::default()
                            .fg(theme::text_muted_color())
                            .add_modifier(Modifier::ITALIC),
                    ),
                ]));
            }

            // Show current tool activity prominently
            if let Some(ref tool) = chat_state.current_tool {
                lines.push(Line::from(vec![
                    Span::styled(
                        format!("{}", spinner),
                        Style::default().fg(theme::accent_secondary()),
                    ),
                    Span::styled(
                        tool.clone(),
                        Style::default()
                            .fg(theme::text_secondary_color())
                            .add_modifier(Modifier::ITALIC),
                    ),
                ]));
            } else if chat_state.tool_history.is_empty() {
                lines.push(Line::from(vec![
                    Span::styled(
                        format!("{} ", spinner),
                        Style::default().fg(theme::accent_primary()),
                    ),
                    Span::styled(
                        "Iris is thinking",
                        Style::default()
                            .fg(theme::accent_primary())
                            .add_modifier(Modifier::ITALIC),
                    ),
                    Span::styled("...", Style::default().fg(theme::text_dim_color())),
                ]));
            } else {
                // Show spinner after tool history
                lines.push(Line::from(Span::styled(
                    format!("  {}", spinner),
                    Style::default().fg(theme::accent_primary()),
                )));
            }
        }
    }

    // Show error message if present
    if let Some(ref error) = chat_state.error {
        if !chat_state.messages.is_empty() {
            lines.push(Line::from(""));
            lines.push(Line::from(Span::styled(
                "".repeat(content_width.min(40)),
                Style::default().fg(theme::text_dim_color()),
            )));
        }
        lines.push(Line::from(""));
        lines.push(Line::from(vec![
            Span::styled(
                "  ⚠ Error: ",
                Style::default()
                    .fg(theme::error_color())
                    .add_modifier(Modifier::BOLD),
            ),
            Span::styled(error.clone(), Style::default().fg(theme::error_color())),
        ]));
        lines.push(Line::from(""));
    }

    // Empty state with helpful message
    if chat_state.messages.is_empty() && !chat_state.is_responding && chat_state.error.is_none() {
        lines.push(Line::from(""));
        lines.push(Line::from(Span::styled(
            "✨ Ask Iris anything about your changes",
            Style::default()
                .fg(theme::text_secondary_color())
                .add_modifier(Modifier::ITALIC),
        )));
        lines.push(Line::from(""));
        lines.push(Line::from(vec![
            Span::styled("", Style::default().fg(theme::accent_primary())),
            Span::styled("\"Make the title shorter\"", theme::dimmed()),
        ]));
        lines.push(Line::from(vec![
            Span::styled("", Style::default().fg(theme::accent_primary())),
            Span::styled("\"Add more context to the body\"", theme::dimmed()),
        ]));
        lines.push(Line::from(vec![
            Span::styled("", Style::default().fg(theme::accent_primary())),
            Span::styled("\"Explain what this change does\"", theme::dimmed()),
        ]));
    }

    // Add bottom padding for scrolling - ensures last message can scroll into view
    if !chat_state.messages.is_empty() || chat_state.is_responding {
        lines.push(Line::from(""));
        lines.push(Line::from(""));
        lines.push(Line::from(""));
    }

    lines
}

/// Format markdown content into styled lines using pulldown-cmark
pub fn format_markdown(content: &str, max_width: usize, base_style: Style) -> Vec<Line<'static>> {
    let mut lines: Vec<Line<'static>> = Vec::new();
    let mut current_spans: Vec<Span<'static>> = Vec::new();

    // Parser state
    let mut style_stack: Vec<Style> = vec![base_style];
    let mut in_code_block = false;
    let mut code_block_lines: Vec<String> = Vec::new();
    let mut code_lang = String::new();
    let mut list_depth: usize = 0;
    let mut ordered_list_num: Option<u64> = None;
    let mut current_link_url: Option<String> = None;
    let mut in_table = false;
    let mut table_row: Vec<String> = Vec::new();

    // Enable all markdown options
    let options = Options::ENABLE_STRIKETHROUGH
        | Options::ENABLE_TABLES
        | Options::ENABLE_FOOTNOTES
        | Options::ENABLE_TASKLISTS;

    let parser = Parser::new_ext(content, options);

    for event in parser {
        match event {
            Event::Start(tag) => match tag {
                Tag::Heading { level, .. } => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                    let color = match level {
                        pulldown_cmark::HeadingLevel::H1 => theme::accent_primary(),
                        pulldown_cmark::HeadingLevel::H2 => theme::accent_secondary(),
                        pulldown_cmark::HeadingLevel::H3 => theme::accent_tertiary(),
                        _ => theme::text_secondary_color(),
                    };
                    style_stack.push(Style::default().fg(color).add_modifier(Modifier::BOLD));
                    current_spans.push(Span::styled("  ", base_style));
                }
                Tag::Paragraph => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                }
                Tag::CodeBlock(kind) => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                    in_code_block = true;
                    code_lang = match kind {
                        pulldown_cmark::CodeBlockKind::Fenced(lang) => lang.to_string(),
                        pulldown_cmark::CodeBlockKind::Indented => String::new(),
                    };
                }
                Tag::List(first_num) => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                    list_depth += 1;
                    ordered_list_num = first_num;
                }
                Tag::Item => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                    let indent = "  ".repeat(list_depth);
                    if let Some(num) = ordered_list_num.as_mut() {
                        current_spans.push(Span::styled(
                            format!("{}{}. ", indent, num),
                            Style::default().fg(theme::accent_primary()),
                        ));
                        *num += 1;
                    } else {
                        current_spans.push(Span::styled(
                            format!("{}", indent),
                            Style::default().fg(theme::accent_primary()),
                        ));
                    }
                }
                Tag::Emphasis => {
                    // Add space before if needed
                    if needs_space_before(&current_spans) {
                        current_spans.push(Span::styled(" ", base_style));
                    }
                    let current = style_stack.last().copied().unwrap_or(base_style);
                    style_stack.push(current.add_modifier(Modifier::ITALIC));
                }
                Tag::Strong => {
                    // Add space before if needed
                    if needs_space_before(&current_spans) {
                        current_spans.push(Span::styled(" ", base_style));
                    }
                    let current = style_stack.last().copied().unwrap_or(base_style);
                    style_stack.push(current.add_modifier(Modifier::BOLD));
                }
                Tag::Strikethrough => {
                    // Add space before if needed
                    if needs_space_before(&current_spans) {
                        current_spans.push(Span::styled(" ", base_style));
                    }
                    let current = style_stack.last().copied().unwrap_or(base_style);
                    style_stack.push(current.add_modifier(Modifier::CROSSED_OUT));
                }
                Tag::BlockQuote(_) => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                    current_spans.push(Span::styled(
                        "",
                        Style::default().fg(theme::text_dim_color()),
                    ));
                }
                Tag::Link { dest_url, .. } => {
                    // Add space before link if needed
                    if needs_space_before(&current_spans) {
                        current_spans.push(Span::styled(" ", base_style));
                    }
                    // Capture URL to display after link text
                    current_link_url = Some(dest_url.to_string());
                    style_stack.push(
                        Style::default()
                            .fg(theme::accent_secondary())
                            .add_modifier(Modifier::UNDERLINED),
                    );
                }
                Tag::Image { .. } => {
                    // Add space before image if needed
                    if needs_space_before(&current_spans) {
                        current_spans.push(Span::styled(" ", base_style));
                    }
                    style_stack.push(
                        Style::default()
                            .fg(theme::accent_secondary())
                            .add_modifier(Modifier::UNDERLINED),
                    );
                }
                Tag::Table(_) | Tag::TableHead | Tag::TableRow => {
                    in_table = true;
                }
                Tag::TableCell => {
                    // Cell content handled in text
                }
                _ => {}
            },
            Event::End(tag) => match tag {
                TagEnd::Heading(_) => {
                    style_stack.pop();
                    flush_line(&mut lines, &mut current_spans, list_depth);
                }
                TagEnd::Paragraph => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                    lines.push(Line::from("")); // Add spacing after paragraphs
                }
                TagEnd::CodeBlock => {
                    render_code_block(&mut lines, &code_block_lines, &code_lang, max_width);
                    code_block_lines.clear();
                    code_lang.clear();
                    in_code_block = false;
                    lines.push(Line::from("")); // Add spacing after code blocks
                }
                TagEnd::List(_) => {
                    list_depth = list_depth.saturating_sub(1);
                    if list_depth == 0 {
                        ordered_list_num = None;
                        lines.push(Line::from("")); // Add spacing after top-level lists
                    }
                }
                TagEnd::Item => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                }
                TagEnd::Emphasis | TagEnd::Strong | TagEnd::Strikethrough => {
                    style_stack.pop();
                    // Add space after if next text might need it
                    // (will be trimmed if next char is punctuation)
                }
                TagEnd::BlockQuote(_) => {
                    flush_line(&mut lines, &mut current_spans, list_depth);
                }
                TagEnd::Link => {
                    style_stack.pop();
                    // Show the URL after the link text (dimmed, in parentheses)
                    if let Some(url) = current_link_url.take() {
                        // Only show URL if it's different from the link text and not too long
                        if !url.is_empty() {
                            current_spans.push(Span::styled(
                                format!(" ({})", url),
                                Style::default().fg(theme::text_dim_color()),
                            ));
                        }
                    }
                    current_spans.push(Span::styled(" ", base_style));
                }
                TagEnd::Image => {
                    style_stack.pop();
                    current_spans.push(Span::styled(" ", base_style));
                }
                TagEnd::Table => {
                    in_table = false;
                    flush_line(&mut lines, &mut current_spans, list_depth);
                    lines.push(Line::from("")); // Space after table
                }
                TagEnd::TableHead | TagEnd::TableRow => {
                    // Render the row
                    if !table_row.is_empty() {
                        let row_text = table_row.join("");
                        flush_line(&mut lines, &mut current_spans, list_depth);
                        current_spans.push(Span::styled(
                            format!("{}", row_text),
                            Style::default().fg(theme::text_secondary_color()),
                        ));
                        flush_line(&mut lines, &mut current_spans, list_depth);
                        table_row.clear();
                    }
                }
                TagEnd::TableCell => {
                    // Cell completed - handled in text
                }
                _ => {}
            },
            Event::Text(text) => {
                if in_code_block {
                    code_block_lines.extend(text.lines().map(String::from));
                } else if in_table {
                    table_row.push(text.to_string());
                } else {
                    let style = style_stack.last().copied().unwrap_or(base_style);
                    process_text(&text, style, &mut current_spans, list_depth, max_width);
                }
            }
            Event::Code(code) => {
                // Add space before inline code if needed (prevents "text`code`" from merging)
                if let Some(last_span) = current_spans.last() {
                    let last_content = last_span.content.as_ref();
                    if !last_content.is_empty()
                        && !last_content.ends_with(' ')
                        && !last_content.ends_with('\n')
                        && !last_content.ends_with('(')
                        && !last_content.ends_with('[')
                    {
                        let style = style_stack.last().copied().unwrap_or(base_style);
                        current_spans.push(Span::styled(" ", style));
                    }
                }
                // Render without backticks - just styled text
                current_spans.push(Span::styled(code.to_string(), theme::inline_code()));
                // Add trailing space after inline code
                let style = style_stack.last().copied().unwrap_or(base_style);
                current_spans.push(Span::styled(" ", style));
            }
            Event::SoftBreak => {
                // Treat as space
                let style = style_stack.last().copied().unwrap_or(base_style);
                current_spans.push(Span::styled(" ", style));
            }
            Event::HardBreak => {
                flush_line(&mut lines, &mut current_spans, list_depth);
            }
            Event::Rule => {
                flush_line(&mut lines, &mut current_spans, list_depth);
                lines.push(Line::from(Span::styled(
                    "".repeat(max_width.min(60)),
                    Style::default().fg(theme::text_dim_color()),
                )));
            }
            Event::TaskListMarker(checked) => {
                let marker = if checked { "" } else { "" };
                current_spans.push(Span::styled(
                    marker.to_string(),
                    Style::default().fg(theme::accent_primary()),
                ));
            }
            _ => {}
        }
    }

    // Flush any remaining content
    flush_line(&mut lines, &mut current_spans, list_depth);

    // Remove trailing empty lines
    while lines.last().is_some_and(|l| l.spans.is_empty()) {
        lines.pop();
    }

    lines
}

/// Flush current spans into a line
fn flush_line(lines: &mut Vec<Line<'static>>, spans: &mut Vec<Span<'static>>, _list_depth: usize) {
    if !spans.is_empty() {
        lines.push(Line::from(std::mem::take(spans)));
    }
}

/// Check if we need to add a space before a new styled element
fn needs_space_before(spans: &[Span<'static>]) -> bool {
    if let Some(last_span) = spans.last() {
        let last_content = last_span.content.as_ref();
        !last_content.is_empty()
            && !last_content.ends_with(' ')
            && !last_content.ends_with('\n')
            && !last_content.ends_with('(')
            && !last_content.ends_with('[')
            && !last_content.ends_with('"')
            && !last_content.ends_with('\'')
    } else {
        false
    }
}

/// Process text content with proper spacing and word wrapping
fn process_text(
    text: &str,
    style: Style,
    current_spans: &mut Vec<Span<'static>>,
    list_depth: usize,
    max_width: usize,
) {
    // Add space after inline code if text doesn't start with punctuation/space
    if let Some(last_span) = current_spans.last() {
        let last_content = last_span.content.as_ref();
        if last_content.ends_with('`') {
            let first_char = text.chars().next().unwrap_or(' ');
            if !first_char.is_whitespace()
                && !matches!(
                    first_char,
                    '.' | ',' | ':' | ';' | ')' | ']' | '-' | '!' | '?'
                )
            {
                current_spans.push(Span::styled(" ", style));
            }
        }
    }

    // Word wrap the text
    let effective_width = max_width.saturating_sub(4 + list_depth * 2);
    for chunk in wrap_text(text, effective_width) {
        if !current_spans.is_empty() && !chunk.is_empty() {
            current_spans.push(Span::styled(chunk, style));
        } else if !chunk.is_empty() {
            // Base indent + list depth indent (aligns with bullet text)
            let indent = if list_depth > 0 {
                "  ".repeat(list_depth) + "  "
            } else {
                "  ".to_string()
            };
            current_spans.push(Span::styled(format!("{}{}", indent, chunk), style));
        }
    }
}

fn render_code_block(
    lines: &mut Vec<Line<'static>>,
    code_lines: &[String],
    lang: &str,
    max_width: usize,
) {
    let lang_label = if lang.is_empty() { "code" } else { lang };
    lines.push(Line::from(Span::styled(
        format!("  ┌─ {} ", lang_label),
        Style::default().fg(theme::text_dim_color()),
    )));

    // Create syntax highlighter for the language
    let highlighter = SyntaxHighlighter::for_extension(lang);

    for code_line in code_lines {
        let truncated = if code_line.len() > max_width.saturating_sub(4) {
            format!("{}", &code_line[..max_width.saturating_sub(5)])
        } else {
            code_line.clone()
        };

        // Build spans for this line
        let mut line_spans = vec![Span::styled(
            "",
            Style::default().fg(theme::text_dim_color()),
        )];

        if highlighter.is_available() {
            // Syntax highlighted
            for (style, text) in highlighter.highlight_line(&truncated) {
                line_spans.push(Span::styled(text, style));
            }
        } else {
            // Fallback to plain green
            line_spans.push(Span::styled(
                truncated,
                Style::default().fg(theme::success_color()),
            ));
        }

        lines.push(Line::from(line_spans));
    }

    lines.push(Line::from(Span::styled(
        "  └─",
        Style::default().fg(theme::text_dim_color()),
    )));
}

/// Wrap text to fit within `max_width`
fn wrap_text(text: &str, max_width: usize) -> Vec<String> {
    if max_width == 0 {
        return vec![text.to_string()];
    }

    // Preserve leading/trailing whitespace
    let has_leading_space = text.starts_with(char::is_whitespace);
    let has_trailing_space = text.ends_with(char::is_whitespace);

    let mut lines = Vec::new();
    let mut current_line = String::new();
    let mut first_word = true;

    for word in text.split_whitespace() {
        // Add leading space to first word if original had it
        let word_to_add = if first_word && has_leading_space {
            first_word = false;
            format!(" {}", word)
        } else {
            first_word = false;
            word.to_string()
        };
        // Handle words longer than max_width by breaking them
        if word_to_add.len() > max_width {
            // Push current line if not empty
            if !current_line.is_empty() {
                lines.push(current_line);
                current_line = String::new();
            }
            // Break the long word into chunks
            let mut remaining = word_to_add.as_str();
            while remaining.len() > max_width {
                let (chunk, rest) = remaining.split_at(max_width);
                lines.push(chunk.to_string());
                remaining = rest;
            }
            if !remaining.is_empty() {
                current_line = remaining.to_string();
            }
        } else if current_line.is_empty() {
            current_line = word_to_add;
        } else if current_line.len() + 1 + word_to_add.len() <= max_width {
            current_line.push(' ');
            current_line.push_str(&word_to_add);
        } else {
            lines.push(current_line);
            current_line = word_to_add;
        }
    }

    // Add trailing space if original had it
    if has_trailing_space && !current_line.is_empty() {
        current_line.push(' ');
    }

    if !current_line.is_empty() {
        lines.push(current_line);
    }

    if lines.is_empty() {
        lines.push(String::new());
    }

    lines
}

/// Render the input line with cursor
pub fn render_input_line(input: &str, cursor_visible: bool) -> Line<'static> {
    let cursor_char = if cursor_visible { "" } else { " " };

    Line::from(vec![
        Span::styled("", Style::default().fg(theme::accent_primary())),
        Span::styled(
            input.to_string(),
            Style::default().fg(theme::text_primary_color()),
        ),
        Span::styled(
            cursor_char.to_string(),
            Style::default().fg(theme::accent_secondary()),
        ),
    ])
}

/// Render the help footer
pub fn help_footer() -> Line<'static> {
    Line::from(" [Enter] send · [Esc] close · [↑↓] scroll ").fg(theme::text_dim_color())
}