ratatui-interact 0.5.3

Interactive TUI components for ratatui with focus management and mouse support
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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
//! Step display widget
//!
//! A multi-step progress display with expandable sub-steps and output areas.
//!
//! # Example
//!
//! ```rust
//! use ratatui_interact::components::{StepDisplay, StepDisplayState, Step, StepStatus};
//!
//! // Create steps
//! let steps = vec![
//!     Step::new("Build project")
//!         .with_sub_steps(vec!["Compile", "Link", "Package"]),
//!     Step::new("Run tests"),
//!     Step::new("Deploy"),
//! ];
//!
//! // Create state
//! let mut state = StepDisplayState::new(steps);
//!
//! // Update step status
//! state.start_step(0);
//! state.complete_step(0);
//! state.start_step(1);
//! ```

use ratatui::{
    buffer::Buffer,
    layout::Rect,
    style::{Color, Modifier, Style},
    text::{Line, Span},
    widgets::{Paragraph, Widget},
};

use crate::utils::display::{pad_to_width, truncate_to_width};

/// Status of a step or sub-step
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum StepStatus {
    /// Not yet started
    #[default]
    Pending,
    /// Currently running
    Running,
    /// Successfully completed
    Completed,
    /// Failed with error
    Failed,
    /// Skipped
    Skipped,
}

impl StepStatus {
    /// Get the icon for this status
    pub fn icon(&self) -> &'static str {
        match self {
            StepStatus::Pending => "[ ]",
            StepStatus::Running => "[▶]",
            StepStatus::Completed => "[✓]",
            StepStatus::Failed => "[✗]",
            StepStatus::Skipped => "[↷]",
        }
    }

    /// Get the color for this status
    pub fn color(&self) -> Color {
        match self {
            StepStatus::Pending => Color::DarkGray,
            StepStatus::Running => Color::Yellow,
            StepStatus::Completed => Color::Green,
            StepStatus::Failed => Color::Red,
            StepStatus::Skipped => Color::DarkGray,
        }
    }

    /// Get the sub-step icon
    pub fn sub_icon(&self) -> &'static str {
        match self {
            StepStatus::Pending => "",
            StepStatus::Running => "",
            StepStatus::Completed => "",
            StepStatus::Failed => "",
            StepStatus::Skipped => "",
        }
    }
}

/// A sub-step within a step
#[derive(Debug, Clone)]
pub struct SubStep {
    /// Name of the sub-step
    pub name: String,
    /// Current status
    pub status: StepStatus,
}

impl SubStep {
    /// Create a new sub-step
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            status: StepStatus::Pending,
        }
    }
}

/// A step in the process
#[derive(Debug, Clone)]
pub struct Step {
    /// Name of the step
    pub name: String,
    /// Current status
    pub status: StepStatus,
    /// Sub-steps
    pub sub_steps: Vec<SubStep>,
    /// Whether the output is expanded
    pub expanded: bool,
    /// Output lines
    pub output: Vec<String>,
    /// Output scroll position
    pub scroll: u16,
}

impl Step {
    /// Create a new step
    pub fn new(name: impl Into<String>) -> Self {
        Self {
            name: name.into(),
            status: StepStatus::Pending,
            sub_steps: Vec::new(),
            expanded: false,
            output: Vec::new(),
            scroll: 0,
        }
    }

    /// Add sub-steps
    pub fn with_sub_steps(mut self, names: Vec<&str>) -> Self {
        self.sub_steps = names.into_iter().map(SubStep::new).collect();
        self
    }

    /// Add a line to output
    pub fn add_output(&mut self, line: impl Into<String>) {
        self.output.push(line.into());
        // Auto-scroll to bottom
        let visible_lines = 5;
        if self.output.len() > visible_lines {
            self.scroll = (self.output.len() - visible_lines) as u16;
        }
    }

    /// Clear output
    pub fn clear_output(&mut self) {
        self.output.clear();
        self.scroll = 0;
    }

    /// Get sub-step progress (completed, total)
    pub fn sub_step_progress(&self) -> (usize, usize) {
        let completed = self
            .sub_steps
            .iter()
            .filter(|s| s.status == StepStatus::Completed)
            .count();
        (completed, self.sub_steps.len())
    }
}

/// State for step display widget
#[derive(Debug, Clone)]
pub struct StepDisplayState {
    /// Steps
    pub steps: Vec<Step>,
    /// Currently focused step index
    pub focused_step: Option<usize>,
    /// Console scroll position
    pub scroll: u16,
}

impl StepDisplayState {
    /// Create a new step display state
    pub fn new(steps: Vec<Step>) -> Self {
        Self {
            steps,
            focused_step: None,
            scroll: 0,
        }
    }

    /// Get total progress (0.0 to 1.0)
    pub fn progress(&self) -> f64 {
        if self.steps.is_empty() {
            return 0.0;
        }
        let completed = self
            .steps
            .iter()
            .filter(|s| s.status == StepStatus::Completed)
            .count();
        completed as f64 / self.steps.len() as f64
    }

    /// Get current step index (first non-completed)
    pub fn current_step(&self) -> usize {
        self.steps
            .iter()
            .position(|s| s.status != StepStatus::Completed && s.status != StepStatus::Skipped)
            .unwrap_or(self.steps.len())
    }

    /// Start a step
    pub fn start_step(&mut self, index: usize) {
        if let Some(step) = self.steps.get_mut(index) {
            step.status = StepStatus::Running;
            step.expanded = true;
        }
    }

    /// Complete a step
    pub fn complete_step(&mut self, index: usize) {
        if let Some(step) = self.steps.get_mut(index) {
            step.status = StepStatus::Completed;
        }
    }

    /// Fail a step
    pub fn fail_step(&mut self, index: usize) {
        if let Some(step) = self.steps.get_mut(index) {
            step.status = StepStatus::Failed;
        }
    }

    /// Skip a step
    pub fn skip_step(&mut self, index: usize) {
        if let Some(step) = self.steps.get_mut(index) {
            step.status = StepStatus::Skipped;
        }
    }

    /// Start a sub-step
    pub fn start_sub_step(&mut self, step_index: usize, sub_index: usize) {
        if let Some(step) = self.steps.get_mut(step_index) {
            if let Some(sub) = step.sub_steps.get_mut(sub_index) {
                sub.status = StepStatus::Running;
            }
        }
    }

    /// Complete a sub-step
    pub fn complete_sub_step(&mut self, step_index: usize, sub_index: usize) {
        if let Some(step) = self.steps.get_mut(step_index) {
            if let Some(sub) = step.sub_steps.get_mut(sub_index) {
                sub.status = StepStatus::Completed;
            }
        }
    }

    /// Add output to a step
    pub fn add_output(&mut self, step_index: usize, line: impl Into<String>) {
        if let Some(step) = self.steps.get_mut(step_index) {
            step.add_output(line);
        }
    }

    /// Toggle expansion of a step
    pub fn toggle_expanded(&mut self, index: usize) {
        if let Some(step) = self.steps.get_mut(index) {
            step.expanded = !step.expanded;
        }
    }

    /// Scroll output for a step
    pub fn scroll_output(&mut self, index: usize, delta: i32) {
        if let Some(step) = self.steps.get_mut(index) {
            let max_scroll = step.output.len().saturating_sub(5) as i32;
            let new_scroll = (step.scroll as i32 + delta).clamp(0, max_scroll);
            step.scroll = new_scroll as u16;
        }
    }
}

/// Style for step display
#[derive(Debug, Clone)]
pub struct StepDisplayStyle {
    /// Output box border color when focused
    pub focused_border: Color,
    /// Output box border color when not focused
    pub unfocused_border: Color,
    /// Maximum visible output lines
    pub max_output_lines: usize,
}

impl Default for StepDisplayStyle {
    fn default() -> Self {
        Self {
            focused_border: Color::Cyan,
            unfocused_border: Color::DarkGray,
            max_output_lines: 5,
        }
    }
}

impl From<&crate::theme::Theme> for StepDisplayStyle {
    fn from(theme: &crate::theme::Theme) -> Self {
        let p = &theme.palette;
        Self {
            focused_border: p.border_accent,
            unfocused_border: p.border_disabled,
            max_output_lines: 5,
        }
    }
}

/// Step display widget
pub struct StepDisplay<'a> {
    state: &'a StepDisplayState,
    style: StepDisplayStyle,
}

impl<'a> StepDisplay<'a> {
    /// Create a new step display
    pub fn new(state: &'a StepDisplayState) -> Self {
        Self {
            state,
            style: StepDisplayStyle::default(),
        }
    }

    /// Set the style
    pub fn style(mut self, style: StepDisplayStyle) -> Self {
        self.style = style;
        self
    }

    /// Apply a theme to derive the style
    pub fn theme(self, theme: &crate::theme::Theme) -> Self {
        self.style(StepDisplayStyle::from(theme))
    }

    /// Build content lines
    fn build_lines(&self, area: Rect) -> Vec<Line<'static>> {
        let mut lines = Vec::new();
        let full_width = area.width as usize;

        for (idx, step) in self.state.steps.iter().enumerate() {
            // Step header
            let icon_color = step.status.color();
            let step_style = match step.status {
                StepStatus::Running => Style::default()
                    .fg(Color::Yellow)
                    .add_modifier(Modifier::BOLD),
                StepStatus::Failed => Style::default().fg(Color::Red),
                StepStatus::Completed => Style::default().fg(Color::Green),
                _ => Style::default().fg(Color::White),
            };

            let header_suffix = if !step.sub_steps.is_empty() {
                let (completed, total) = step.sub_step_progress();
                format!(" ({}/{})", completed, total)
            } else {
                String::new()
            };

            lines.push(Line::from(vec![
                Span::styled(
                    format!("{} ", step.status.icon()),
                    Style::default().fg(icon_color),
                ),
                Span::styled(format!("Step {}: ", idx + 1), step_style),
                Span::styled(step.name.clone(), step_style),
                Span::styled(header_suffix, Style::default().fg(Color::DarkGray)),
            ]));

            // Sub-steps (if running or expanded)
            if !step.sub_steps.is_empty() && (step.expanded || step.status == StepStatus::Running) {
                for sub in &step.sub_steps {
                    let sub_color = sub.status.color();
                    let sub_style = match sub.status {
                        StepStatus::Running => Style::default().fg(Color::Yellow),
                        StepStatus::Completed => Style::default().fg(Color::Green),
                        StepStatus::Failed => Style::default().fg(Color::Red),
                        StepStatus::Skipped => Style::default().fg(Color::DarkGray),
                        _ => Style::default().fg(Color::White),
                    };

                    lines.push(Line::from(vec![
                        Span::raw("    "),
                        Span::styled(
                            format!("{} ", sub.status.sub_icon()),
                            Style::default().fg(sub_color),
                        ),
                        Span::styled(sub.name.clone(), sub_style),
                    ]));
                }
            }

            // Output frame (if expanded and has output)
            if step.expanded && !step.output.is_empty() {
                let is_focused = self.state.focused_step == Some(idx);
                let border_color = if is_focused {
                    self.style.focused_border
                } else {
                    self.style.unfocused_border
                };

                let border_width = full_width.saturating_sub(6);
                let content_width = full_width.saturating_sub(8);

                // Top border
                lines.push(Line::from(Span::styled(
                    format!("  ┌{:─<width$}┐  ", " Output ", width = border_width),
                    Style::default().fg(border_color),
                )));

                // Output content
                let visible_lines = self.style.max_output_lines;
                let scroll = step.scroll as usize;
                let total = step.output.len();

                for i in 0..visible_lines {
                    let line_idx = scroll + i;
                    let content = if line_idx < total {
                        truncate_to_width(&step.output[line_idx], content_width)
                    } else {
                        String::new()
                    };

                    let padded = pad_to_width(&content, content_width);
                    lines.push(Line::from(vec![
                        Span::styled("", Style::default().fg(border_color)),
                        Span::styled(padded, Style::default().fg(Color::Gray)),
                        Span::styled("", Style::default().fg(border_color)),
                    ]));
                }

                // Bottom border with scroll info
                let scroll_info = if total > visible_lines {
                    format!(" [{}/{} lines] ", scroll + visible_lines.min(total), total)
                } else {
                    String::new()
                };

                lines.push(Line::from(Span::styled(
                    format!("  └{:─<width$}┘  ", scroll_info, width = border_width),
                    Style::default().fg(border_color),
                )));

                // Empty line after output
                lines.push(Line::from(""));
            }
        }

        lines
    }
}

impl Widget for StepDisplay<'_> {
    fn render(self, area: Rect, buf: &mut Buffer) {
        let lines = self.build_lines(area);
        let para = Paragraph::new(lines).scroll((self.state.scroll, 0));
        para.render(area, buf);
    }
}

/// Calculate total height needed for step display
pub fn calculate_height(state: &StepDisplayState, style: &StepDisplayStyle) -> u16 {
    let mut height = 0u16;

    for step in &state.steps {
        height += 1; // Step header

        // Sub-steps
        if !step.sub_steps.is_empty() && (step.expanded || step.status == StepStatus::Running) {
            height += step.sub_steps.len() as u16;
        }

        // Output frame
        if step.expanded && !step.output.is_empty() {
            height += 2; // borders
            height += style.max_output_lines as u16;
            height += 1; // empty line after
        }
    }

    height
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_step_status_icons() {
        assert_eq!(StepStatus::Pending.icon(), "[ ]");
        assert_eq!(StepStatus::Running.icon(), "[▶]");
        assert_eq!(StepStatus::Completed.icon(), "[✓]");
        assert_eq!(StepStatus::Failed.icon(), "[✗]");
        assert_eq!(StepStatus::Skipped.icon(), "[↷]");
    }

    #[test]
    fn test_step_status_sub_icons() {
        assert_eq!(StepStatus::Pending.sub_icon(), "");
        assert_eq!(StepStatus::Running.sub_icon(), "");
        assert_eq!(StepStatus::Completed.sub_icon(), "");
        assert_eq!(StepStatus::Failed.sub_icon(), "");
        assert_eq!(StepStatus::Skipped.sub_icon(), "");
    }

    #[test]
    fn test_step_status_colors() {
        assert_eq!(StepStatus::Pending.color(), Color::DarkGray);
        assert_eq!(StepStatus::Running.color(), Color::Yellow);
        assert_eq!(StepStatus::Completed.color(), Color::Green);
        assert_eq!(StepStatus::Failed.color(), Color::Red);
        assert_eq!(StepStatus::Skipped.color(), Color::DarkGray);
    }

    #[test]
    fn test_step_new() {
        let step = Step::new("Build");
        assert_eq!(step.name, "Build");
        assert_eq!(step.status, StepStatus::Pending);
        assert!(step.sub_steps.is_empty());
        assert!(!step.expanded);
        assert!(step.output.is_empty());
    }

    #[test]
    fn test_step_with_sub_steps() {
        let step = Step::new("Build").with_sub_steps(vec!["Compile", "Link", "Package"]);
        assert_eq!(step.sub_steps.len(), 3);
        assert_eq!(step.sub_steps[0].name, "Compile");
        assert_eq!(step.sub_steps[1].name, "Link");
        assert_eq!(step.sub_steps[2].name, "Package");
    }

    #[test]
    fn test_step_progress() {
        let step = Step::new("Test").with_sub_steps(vec!["A", "B", "C"]);
        let (completed, total) = step.sub_step_progress();
        assert_eq!(completed, 0);
        assert_eq!(total, 3);
    }

    #[test]
    fn test_step_add_output() {
        let mut step = Step::new("Test");
        step.add_output("Line 1");
        step.add_output("Line 2");
        assert_eq!(step.output.len(), 2);
        assert_eq!(step.output[0], "Line 1");
    }

    #[test]
    fn test_step_clear_output() {
        let mut step = Step::new("Test");
        step.add_output("Line 1");
        step.add_output("Line 2");
        step.scroll = 1;
        step.clear_output();
        assert!(step.output.is_empty());
        assert_eq!(step.scroll, 0);
    }

    #[test]
    fn test_step_auto_scroll() {
        let mut step = Step::new("Test");
        // Add more than 5 lines to trigger auto-scroll
        for i in 0..10 {
            step.add_output(format!("Line {}", i));
        }
        // scroll should be updated to show latest content
        assert!(step.scroll > 0);
    }

    #[test]
    fn test_sub_step_new() {
        let sub = SubStep::new("Compile");
        assert_eq!(sub.name, "Compile");
        assert_eq!(sub.status, StepStatus::Pending);
    }

    #[test]
    fn test_state_new() {
        let steps = vec![Step::new("Step 1"), Step::new("Step 2")];
        let state = StepDisplayState::new(steps);
        assert_eq!(state.steps.len(), 2);
        assert!(state.focused_step.is_none());
        assert_eq!(state.scroll, 0);
    }

    #[test]
    fn test_state_progress() {
        let steps = vec![
            Step::new("Step 1"),
            Step::new("Step 2"),
            Step::new("Step 3"),
            Step::new("Step 4"),
        ];
        let mut state = StepDisplayState::new(steps);

        assert_eq!(state.progress(), 0.0);

        state.complete_step(0);
        assert!((state.progress() - 0.25).abs() < 0.01);

        state.complete_step(1);
        assert!((state.progress() - 0.5).abs() < 0.01);
    }

    #[test]
    fn test_state_progress_empty() {
        let state = StepDisplayState::new(vec![]);
        assert_eq!(state.progress(), 0.0);
    }

    #[test]
    fn test_state_current_step() {
        let steps = vec![
            Step::new("Step 1"),
            Step::new("Step 2"),
            Step::new("Step 3"),
        ];
        let mut state = StepDisplayState::new(steps);

        assert_eq!(state.current_step(), 0);

        state.complete_step(0);
        assert_eq!(state.current_step(), 1);

        state.skip_step(1);
        assert_eq!(state.current_step(), 2);
    }

    #[test]
    fn test_state_operations() {
        let steps = vec![Step::new("Test")];
        let mut state = StepDisplayState::new(steps);

        state.start_step(0);
        assert_eq!(state.steps[0].status, StepStatus::Running);
        assert!(state.steps[0].expanded);

        state.add_output(0, "Line 1");
        assert_eq!(state.steps[0].output.len(), 1);

        state.complete_step(0);
        assert_eq!(state.steps[0].status, StepStatus::Completed);
    }

    #[test]
    fn test_state_fail_step() {
        let steps = vec![Step::new("Test")];
        let mut state = StepDisplayState::new(steps);

        state.fail_step(0);
        assert_eq!(state.steps[0].status, StepStatus::Failed);
    }

    #[test]
    fn test_state_skip_step() {
        let steps = vec![Step::new("Test")];
        let mut state = StepDisplayState::new(steps);

        state.skip_step(0);
        assert_eq!(state.steps[0].status, StepStatus::Skipped);
    }

    #[test]
    fn test_state_sub_step_operations() {
        let steps = vec![Step::new("Test").with_sub_steps(vec!["A", "B"])];
        let mut state = StepDisplayState::new(steps);

        state.start_sub_step(0, 0);
        assert_eq!(state.steps[0].sub_steps[0].status, StepStatus::Running);

        state.complete_sub_step(0, 0);
        assert_eq!(state.steps[0].sub_steps[0].status, StepStatus::Completed);
    }

    #[test]
    fn test_state_toggle_expanded() {
        let steps = vec![Step::new("Test")];
        let mut state = StepDisplayState::new(steps);

        assert!(!state.steps[0].expanded);
        state.toggle_expanded(0);
        assert!(state.steps[0].expanded);
        state.toggle_expanded(0);
        assert!(!state.steps[0].expanded);
    }

    #[test]
    fn test_state_scroll_output() {
        let mut step = Step::new("Test");
        for i in 0..20 {
            step.add_output(format!("Line {}", i));
        }
        let steps = vec![step];
        let mut state = StepDisplayState::new(steps);
        state.steps[0].scroll = 0;

        state.scroll_output(0, 5);
        assert_eq!(state.steps[0].scroll, 5);

        state.scroll_output(0, -3);
        assert_eq!(state.steps[0].scroll, 2);

        // Should not go negative
        state.scroll_output(0, -10);
        assert_eq!(state.steps[0].scroll, 0);
    }

    #[test]
    fn test_state_invalid_index() {
        let steps = vec![Step::new("Test")];
        let mut state = StepDisplayState::new(steps);

        // These should not panic with invalid indices
        state.start_step(10);
        state.complete_step(10);
        state.fail_step(10);
        state.skip_step(10);
        state.add_output(10, "test");
        state.toggle_expanded(10);
        state.scroll_output(10, 5);
        state.start_sub_step(10, 0);
        state.complete_sub_step(10, 0);
    }

    #[test]
    fn test_step_display_style_default() {
        let style = StepDisplayStyle::default();
        assert_eq!(style.focused_border, Color::Cyan);
        assert_eq!(style.unfocused_border, Color::DarkGray);
        assert_eq!(style.max_output_lines, 5);
    }

    #[test]
    fn test_calculate_height() {
        let steps = vec![
            Step::new("Step 1"),
            Step::new("Step 2").with_sub_steps(vec!["A", "B"]),
        ];
        let mut state = StepDisplayState::new(steps);
        let style = StepDisplayStyle::default();

        // Initially just 2 headers
        let height = calculate_height(&state, &style);
        assert_eq!(height, 2);

        // Expand step 2 with sub-steps
        state.start_step(1);
        let height = calculate_height(&state, &style);
        assert!(height > 2); // Should include sub-steps
    }

    #[test]
    fn test_step_display_render() {
        let steps = vec![
            Step::new("Build").with_sub_steps(vec!["Compile", "Link"]),
            Step::new("Test"),
        ];
        let state = StepDisplayState::new(steps);
        let display = StepDisplay::new(&state);

        let mut buf = Buffer::empty(Rect::new(0, 0, 60, 20));
        display.render(Rect::new(0, 0, 60, 20), &mut buf);
        // Should not panic
    }
}