summaryrefslogtreecommitdiff
path: root/makima/src/daemon/tui/ui.rs
blob: 2a5a6ce1c804102c3386f3b7b740b5c98f40076d (plain) (blame)
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
691
692
693
694
695
//! TUI rendering.

use ratatui::{
    layout::{Alignment, Constraint, Direction, Layout, Rect},
    style::{Color, Modifier, Style},
    text::{Line, Span, Text},
    widgets::{Block, Borders, Clear, List, ListItem, Paragraph, Wrap},
    Frame,
};

use super::app::{App, CreateFormField, InputMode, ViewType, OutputMessageType, WsConnectionState};
use super::event::{get_help_text, get_output_help_text};

/// Main render function
pub fn render(frame: &mut Frame, app: &App) {
    // Create main layout
    let chunks = Layout::default()
        .direction(Direction::Vertical)
        .constraints([
            Constraint::Length(3),  // Header
            Constraint::Min(10),    // Main content
            Constraint::Length(3),  // Status/Help
        ])
        .split(frame.area());

    render_header(frame, app, chunks[0]);
    render_main_content(frame, app, chunks[1]);
    render_footer(frame, app, chunks[2]);

    // Render confirmation dialog if in confirm mode
    if app.input_mode == InputMode::Confirm {
        render_confirm_dialog(frame, app);
    }

    // Render edit dialog if in edit mode
    if matches!(app.input_mode, InputMode::EditName | InputMode::EditDescription) {
        render_edit_dialog(frame, app);
    }

    // Render create contract dialog if in create mode
    if matches!(app.input_mode, InputMode::CreateName | InputMode::CreateDescription) {
        render_create_dialog(frame, app);
    }
}

/// Render header with breadcrumb and search bar
fn render_header(frame: &mut Frame, app: &App, area: Rect) {
    let breadcrumb = app.get_breadcrumb();

    let header_text = if app.input_mode == InputMode::Search || !app.search_query.is_empty() {
        format!("{} [Search: {}]", breadcrumb, app.search_query)
    } else {
        format!("{} ({} items)", breadcrumb, app.filtered_items.len())
    };

    let header = Paragraph::new(header_text)
        .style(Style::default().fg(Color::Cyan).add_modifier(Modifier::BOLD))
        .block(Block::default()
            .borders(Borders::ALL)
            .border_style(Style::default().fg(if app.input_mode == InputMode::Search {
                Color::Yellow
            } else {
                Color::White
            })));

    frame.render_widget(header, area);
}

/// Render main content (list + optional preview)
fn render_main_content(frame: &mut Frame, app: &App, area: Rect) {
    // TaskOutput view has its own rendering
    if app.view_type == ViewType::TaskOutput {
        render_output_view(frame, app, area);
        return;
    }

    if app.preview_visible && !app.preview_content.is_empty() {
        // Split horizontally: list on left, preview on right
        let chunks = Layout::default()
            .direction(Direction::Horizontal)
            .constraints([
                Constraint::Percentage(50),
                Constraint::Percentage(50),
            ])
            .split(area);

        render_list(frame, app, chunks[0]);
        render_preview(frame, app, chunks[1]);
    } else {
        render_list(frame, app, area);
    }
}

/// Render the item list
fn render_list(frame: &mut Frame, app: &App, area: Rect) {
    let items: Vec<ListItem> = app.filtered_items
        .iter()
        .enumerate()
        .map(|(i, item)| {
            let is_selected = i == app.selected_index;

            // Build the display line
            let status_str = item.status
                .as_ref()
                .map(|s| format!(" [{}]", s))
                .unwrap_or_default();

            let content = format!("{}{}", item.name, status_str);

            let style = if is_selected {
                Style::default()
                    .fg(Color::Black)
                    .bg(Color::Cyan)
                    .add_modifier(Modifier::BOLD)
            } else {
                let status_color = item.status.as_ref().map(|s| {
                    match s.to_lowercase().as_str() {
                        "running" | "active" => Color::Green,
                        "pending" | "waiting" => Color::Yellow,
                        "completed" | "done" => Color::Blue,
                        "failed" | "error" => Color::Red,
                        _ => Color::White,
                    }
                }).unwrap_or(Color::White);

                Style::default().fg(status_color)
            };

            ListItem::new(Line::from(vec![
                Span::styled(content, style),
            ]))
        })
        .collect();

    let list = List::new(items)
        .block(Block::default()
            .borders(Borders::ALL)
            .title(format!(" {} ", app.view_type.as_str())));

    frame.render_widget(list, area);
}

/// Render the preview panel
fn render_preview(frame: &mut Frame, app: &App, area: Rect) {
    let preview = Paragraph::new(Text::raw(&app.preview_content))
        .wrap(Wrap { trim: false })
        .block(Block::default()
            .borders(Borders::ALL)
            .title(" Preview "));

    frame.render_widget(preview, area);
}

/// Render footer with help text and status
fn render_footer(frame: &mut Frame, app: &App, area: Rect) {
    // Use output-specific help text when in output view
    let help_text = if app.view_type == ViewType::TaskOutput {
        get_output_help_text()
    } else {
        get_help_text(app.input_mode)
    };

    // Build status text with WS connection state for output view
    let ws_status = if app.view_type == ViewType::TaskOutput {
        match app.ws_state {
            WsConnectionState::Connected => " [WS: Connected]",
            WsConnectionState::Connecting => " [WS: Connecting...]",
            WsConnectionState::Reconnecting => " [WS: Reconnecting...]",
            WsConnectionState::Disconnected => " [WS: Disconnected]",
        }
    } else {
        ""
    };

    let status_text = app.status_message
        .as_ref()
        .map(|s| format!(" | {}", s))
        .unwrap_or_default();

    let footer_text = format!("{}{}{}", help_text, ws_status, status_text);

    let footer = Paragraph::new(footer_text)
        .style(Style::default().fg(Color::DarkGray))
        .block(Block::default().borders(Borders::ALL));

    frame.render_widget(footer, area);
}

/// Render confirmation dialog as a centered popup
fn render_confirm_dialog(frame: &mut Frame, app: &App) {
    let item_name = app.get_pending_delete_name()
        .unwrap_or_else(|| "this item".to_string());

    // Calculate popup size and position
    let area = frame.area();
    let popup_width = 50.min(area.width.saturating_sub(4));
    let popup_height = 7;

    let popup_x = (area.width.saturating_sub(popup_width)) / 2;
    let popup_y = (area.height.saturating_sub(popup_height)) / 2;

    let popup_area = Rect {
        x: popup_x,
        y: popup_y,
        width: popup_width,
        height: popup_height,
    };

    // Clear the area behind the popup
    frame.render_widget(Clear, popup_area);

    // Build popup content
    let text = vec![
        Line::from(""),
        Line::from(Span::styled(
            "Delete Confirmation",
            Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
        )),
        Line::from(""),
        Line::from(format!("Delete '{}'?", item_name)),
        Line::from(""),
        Line::from(vec![
            Span::styled("y", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": confirm  "),
            Span::styled("n", Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)),
            Span::raw(": cancel"),
        ]),
    ];

    let popup = Paragraph::new(text)
        .alignment(Alignment::Center)
        .block(Block::default()
            .borders(Borders::ALL)
            .border_style(Style::default().fg(Color::Red))
            .title(" Confirm "));

    frame.render_widget(popup, popup_area);
}

/// Render edit dialog as a centered popup
fn render_edit_dialog(frame: &mut Frame, app: &App) {
    // Calculate popup size and position - make it wider
    let area = frame.area();
    let popup_width = 80.min(area.width.saturating_sub(4));
    let popup_height = 14;

    let popup_x = (area.width.saturating_sub(popup_width)) / 2;
    let popup_y = (area.height.saturating_sub(popup_height)) / 2;

    let popup_area = Rect {
        x: popup_x,
        y: popup_y,
        width: popup_width,
        height: popup_height,
    };

    // Clear the area behind the popup
    frame.render_widget(Clear, popup_area);

    // Determine which field is active
    let editing_name = app.input_mode == InputMode::EditName;

    // Calculate max display width (popup width - borders - label)
    let max_field_width = (popup_width as usize).saturating_sub(16);

    // Build the name field with cursor and truncation
    let name_display = if editing_name {
        let cursor_pos = app.edit_state.cursor.min(app.edit_state.name.len());
        let (before, after) = app.edit_state.name.split_at(cursor_pos);
        let display = format!("{}|{}", before, after);
        // Show end of string if cursor is past visible area
        if display.len() > max_field_width {
            let start = display.len().saturating_sub(max_field_width);
            format!("...{}", &display[start..])
        } else {
            display
        }
    } else {
        if app.edit_state.name.len() > max_field_width {
            format!("{}...", &app.edit_state.name[..max_field_width.saturating_sub(3)])
        } else {
            app.edit_state.name.clone()
        }
    };

    // Build the description field with cursor and truncation
    let desc_display = if !editing_name {
        let cursor_pos = app.edit_state.cursor.min(app.edit_state.description.len());
        let (before, after) = app.edit_state.description.split_at(cursor_pos);
        let display = format!("{}|{}", before, after);
        // Show end of string if cursor is past visible area
        if display.len() > max_field_width {
            let start = display.len().saturating_sub(max_field_width);
            format!("...{}", &display[start..])
        } else {
            display
        }
    } else {
        if app.edit_state.description.len() > max_field_width {
            format!("{}...", &app.edit_state.description[..max_field_width.saturating_sub(3)])
        } else {
            app.edit_state.description.clone()
        }
    };

    // Determine field label based on view type
    let desc_label = match app.view_type {
        ViewType::Tasks => "Plan",
        _ => "Desc",
    };

    // Style for active vs inactive fields
    let active_style = Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD);
    let inactive_style = Style::default().fg(Color::White);
    let label_style = Style::default().fg(Color::DarkGray);

    // Build popup content - use left alignment for fields
    let text = vec![
        Line::from(""),
        Line::from(Span::styled(
            " Edit Item",
            Style::default().fg(Color::Cyan).add_modifier(Modifier::BOLD),
        )),
        Line::from(""),
        // Name field
        Line::from(vec![
            Span::styled(" Name: ", label_style),
            Span::styled(
                name_display,
                if editing_name { active_style } else { inactive_style },
            ),
        ]),
        Line::from(""),
        // Description field
        Line::from(vec![
            Span::styled(format!(" {}: ", desc_label), label_style),
            Span::styled(
                desc_display,
                if !editing_name { active_style } else { inactive_style },
            ),
        ]),
        Line::from(""),
        Line::from(""),
        Line::from(vec![
            Span::styled(" Tab", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": switch  "),
            Span::styled("Enter", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": save  "),
            Span::styled("Esc", Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)),
            Span::raw(": cancel"),
        ]),
    ];

    let popup = Paragraph::new(text)
        .block(Block::default()
            .borders(Borders::ALL)
            .border_style(Style::default().fg(Color::Cyan))
            .title(" Edit "));

    frame.render_widget(popup, popup_area);
}

/// Render the create contract dialog
fn render_create_dialog(frame: &mut Frame, app: &App) {
    // Calculate popup size and position - make it taller if suggestions are shown
    let area = frame.area();
    let state = &app.create_state;
    let current_field = state.current_field();
    // Show suggestions whenever we have them (like the frontend does)
    let show_suggestions = state.show_suggestions && !state.repo_suggestions.is_empty();

    let popup_width = 70.min(area.width.saturating_sub(4));
    let base_height = 20;
    let suggestion_height = if show_suggestions {
        (state.repo_suggestions.len().min(5) + 2) as u16
    } else {
        0
    };
    let popup_height = base_height + suggestion_height;

    let popup_x = (area.width.saturating_sub(popup_width)) / 2;
    let popup_y = (area.height.saturating_sub(popup_height)) / 2;

    let popup_area = Rect {
        x: popup_x,
        y: popup_y,
        width: popup_width,
        height: popup_height,
    };

    // Clear the area behind the popup
    frame.render_widget(Clear, popup_area);

    let max_field_width = (popup_width as usize).saturating_sub(18);

    // Styles
    let active_style = Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD);
    let inactive_style = Style::default().fg(Color::White);
    let label_style = Style::default().fg(Color::DarkGray);
    let hint_style = Style::default().fg(Color::DarkGray).add_modifier(Modifier::ITALIC);
    let suggestion_style = Style::default().fg(Color::White);
    let selected_suggestion_style = Style::default().fg(Color::Black).bg(Color::Cyan);

    // Helper to build text field with cursor
    let build_field = |value: &str, cursor: usize, is_active: bool| -> String {
        if is_active {
            let cursor_pos = cursor.min(value.len());
            let (before, after) = value.split_at(cursor_pos);
            let display = format!("{}|{}", before, after);
            if display.len() > max_field_width {
                let start = display.len().saturating_sub(max_field_width);
                format!("...{}", &display[start..])
            } else {
                display
            }
        } else {
            if value.len() > max_field_width {
                format!("{}...", &value[..max_field_width.saturating_sub(3)])
            } else if value.is_empty() {
                "(empty)".to_string()
            } else {
                value.to_string()
            }
        }
    };

    // Build field displays
    let name_display = build_field(&state.name, state.cursor, current_field == CreateFormField::Name);
    let desc_display = build_field(&state.description, state.cursor, current_field == CreateFormField::Description);
    let repo_display = build_field(&state.repository_url, state.cursor, current_field == CreateFormField::Repository);

    // Contract type selector
    let type_display = if state.contract_type == "simple" {
        vec![
            Span::styled("[●] ", Style::default().fg(Color::Green)),
            Span::raw("Simple "),
            Span::styled("[ ] ", Style::default().fg(Color::DarkGray)),
            Span::styled("Specification", Style::default().fg(Color::DarkGray)),
        ]
    } else {
        vec![
            Span::styled("[ ] ", Style::default().fg(Color::DarkGray)),
            Span::styled("Simple ", Style::default().fg(Color::DarkGray)),
            Span::styled("[●] ", Style::default().fg(Color::Green)),
            Span::raw("Specification"),
        ]
    };

    let mut text = vec![
        Line::from(""),
        Line::from(Span::styled(
            " New Contract",
            Style::default().fg(Color::Cyan).add_modifier(Modifier::BOLD),
        )),
        Line::from(""),
        // Name field (required)
        Line::from(vec![
            Span::styled(" Name*:       ", label_style),
            Span::styled(
                name_display,
                if current_field == CreateFormField::Name { active_style } else { inactive_style },
            ),
        ]),
        Line::from(Span::styled("               Contract name (required)", hint_style)),
        Line::from(""),
        // Description field
        Line::from(vec![
            Span::styled(" Description: ", label_style),
            Span::styled(
                desc_display,
                if current_field == CreateFormField::Description { active_style } else { inactive_style },
            ),
        ]),
        Line::from(Span::styled("               Brief description of the work", hint_style)),
        Line::from(""),
        // Contract type selector
        Line::from(vec![
            Span::styled(" Type:        ", label_style),
        ].into_iter().chain(
            if current_field == CreateFormField::ContractType {
                type_display.into_iter().map(|s| s).collect::<Vec<_>>()
            } else {
                type_display.into_iter().map(|mut s| {
                    s.style = s.style.fg(Color::DarkGray);
                    s
                }).collect()
            }
        ).collect::<Vec<_>>()),
        Line::from(Span::styled("               Simple: Plan→Execute | Spec: Research→Specify→Plan→Execute→Review", hint_style)),
        Line::from(""),
        // Repository URL field
        Line::from(vec![
            Span::styled(" Repository:  ", label_style),
            Span::styled(
                repo_display,
                if current_field == CreateFormField::Repository { active_style } else { inactive_style },
            ),
        ]),
        Line::from(Span::styled("               Git repository URL (optional)", hint_style)),
    ];

    // Add suggestions section
    if show_suggestions {
        text.push(Line::from(""));
        text.push(Line::from(Span::styled(
            " Recent repositories (↑/↓ to select, Enter to apply):",
            Style::default().fg(Color::Cyan),
        )));

        for (i, suggestion) in state.repo_suggestions.iter().take(5).enumerate() {
            let is_selected = i == state.selected_suggestion;
            let url_or_path = suggestion.repository_url.as_ref()
                .or(suggestion.local_path.as_ref())
                .map(|s| s.as_str())
                .unwrap_or("");

            // Truncate if too long
            let display_url = if url_or_path.len() > max_field_width - 10 {
                format!("...{}", &url_or_path[url_or_path.len().saturating_sub(max_field_width - 13)..])
            } else {
                url_or_path.to_string()
            };

            let prefix = if is_selected { " → " } else { "   " };
            let count_suffix = format!(" ({}×)", suggestion.use_count);

            text.push(Line::from(vec![
                Span::styled(
                    format!("{}{}{}", prefix, display_url, count_suffix),
                    if is_selected { selected_suggestion_style } else { suggestion_style },
                ),
            ]));
        }
    } else if state.suggestions_loaded && state.repo_suggestions.is_empty() {
        // Show message when suggestions loaded but empty
        text.push(Line::from(""));
        text.push(Line::from(Span::styled(
            " (No recent repositories - add repos to contracts to see suggestions here)",
            hint_style,
        )));
    }

    text.push(Line::from(""));

    // Help line - show different help when suggestions are visible
    if show_suggestions {
        text.push(Line::from(vec![
            Span::styled(" ↑/↓", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": select  "),
            Span::styled("Enter", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": apply  "),
            Span::styled("Tab", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": next field  "),
            Span::styled("Esc", Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)),
            Span::raw(": cancel"),
        ]));
    } else {
        text.push(Line::from(vec![
            Span::styled(" Tab/↑↓", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": switch  "),
            Span::styled("Enter", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": create  "),
            Span::styled("Space", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
            Span::raw(": toggle type  "),
            Span::styled("Esc", Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)),
            Span::raw(": cancel"),
        ]));
    }

    let popup = Paragraph::new(text)
        .block(Block::default()
            .borders(Borders::ALL)
            .border_style(Style::default().fg(Color::Cyan))
            .title(" Create Contract "));

    frame.render_widget(popup, popup_area);
}

/// Render the task output view
fn render_output_view(frame: &mut Frame, app: &App, area: Rect) {
    let buffer = &app.output_buffer;

    // Calculate visible area (subtract 2 for borders)
    let visible_height = area.height.saturating_sub(2) as usize;

    // Build lines to display
    let total_lines = buffer.lines.len();
    let start_idx = if total_lines > visible_height {
        total_lines
            .saturating_sub(visible_height)
            .saturating_sub(buffer.scroll_offset)
    } else {
        0
    };

    let lines: Vec<Line> = buffer.lines
        .iter()
        .skip(start_idx)
        .take(visible_height)
        .map(|line| render_output_line(line))
        .collect();

    // Build title with scroll indicator
    let scroll_indicator = if buffer.auto_scroll {
        "[auto-scroll]".to_string()
    } else if buffer.scroll_offset > 0 {
        format!("[+{}]", buffer.scroll_offset)
    } else {
        String::new()
    };

    let title = format!(" Task Output {} ", scroll_indicator);

    let paragraph = Paragraph::new(lines)
        .block(Block::default()
            .borders(Borders::ALL)
            .title(title)
            .border_style(Style::default().fg(match app.ws_state {
                WsConnectionState::Connected => Color::Green,
                WsConnectionState::Connecting | WsConnectionState::Reconnecting => Color::Yellow,
                WsConnectionState::Disconnected => Color::Red,
            })));

    frame.render_widget(paragraph, area);
}

/// Render a single output line with appropriate styling
fn render_output_line(line: &super::app::OutputLine) -> Line<'static> {
    match line.message_type {
        OutputMessageType::Assistant => {
            // Blue left indicator for assistant messages
            Line::from(vec![
                Span::styled("│ ", Style::default().fg(Color::Blue)),
                Span::styled(line.content.clone(), Style::default().fg(Color::White)),
            ])
        }
        OutputMessageType::ToolUse => {
            // Yellow asterisk for tool calls
            let tool_name = line.tool_name.clone().unwrap_or_else(|| "tool".to_string());
            Line::from(vec![
                Span::styled("* ", Style::default().fg(Color::Yellow)),
                Span::styled(format!("[{}] ", tool_name), Style::default().fg(Color::Yellow).add_modifier(Modifier::BOLD)),
                Span::styled(line.content.clone(), Style::default().fg(Color::DarkGray)),
            ])
        }
        OutputMessageType::ToolResult => {
            // Green/red indicator for tool results
            let indicator = if line.is_error { "✗ " } else { "  + " };
            let color = if line.is_error { Color::Red } else { Color::Green };
            Line::from(vec![
                Span::styled(indicator, Style::default().fg(color)),
                Span::styled(line.content.clone(), Style::default().fg(Color::Gray)),
            ])
        }
        OutputMessageType::Result => {
            // Green checkmark for final results
            let mut spans = vec![
                Span::styled("✓ ", Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)),
                Span::styled(line.content.clone(), Style::default().fg(Color::Green)),
            ];
            // Add cost/duration if available
            if let Some(cost) = line.cost_usd {
                spans.push(Span::styled(
                    format!(" [${:.4}]", cost),
                    Style::default().fg(Color::DarkGray),
                ));
            }
            if let Some(ms) = line.duration_ms {
                spans.push(Span::styled(
                    format!(" [{}ms]", ms),
                    Style::default().fg(Color::DarkGray),
                ));
            }
            Line::from(spans)
        }
        OutputMessageType::System => {
            // Dim gray for system messages
            Line::from(vec![
                Span::styled("  ", Style::default()),
                Span::styled(line.content.clone(), Style::default().fg(Color::DarkGray)),
            ])
        }
        OutputMessageType::Error => {
            // Red for errors
            Line::from(vec![
                Span::styled("! ", Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)),
                Span::styled(line.content.clone(), Style::default().fg(Color::Red)),
            ])
        }
        OutputMessageType::Raw => {
            // Plain text
            Line::from(line.content.clone())
        }
    }
}