diff --git a/src/help_window.rs b/src/help_window.rs index 902d84f..4d9296c 100644 --- a/src/help_window.rs +++ b/src/help_window.rs @@ -1,11 +1,11 @@ use ratatui::{ - backend::Backend, layout::{Constraint, Direction, Layout, Rect}, style::{Color, Style}, widgets::{Block, Borders, Clear, Paragraph}, - Frame, }; +use crate::runner::FrameWrapperInterface; + pub struct HelpWindow; impl HelpWindow { @@ -13,47 +13,51 @@ impl HelpWindow { HelpWindow } - pub fn render(&self, f: &mut Frame, area: Rect) { - let block = Block::default() - .title("Help") - .borders(Borders::ALL) - .style(Style::default().fg(Color::White).bg(Color::Black)); - - let inner_area = block.inner(area); - - let chunks = Layout::default() - .direction(Direction::Vertical) - .constraints([ - Constraint::Length(1), - Constraint::Length(1), - Constraint::Length(1), - Constraint::Length(1), - Constraint::Length(1), - Constraint::Length(1), - Constraint::Length(1), - Constraint::Length(1), - ]) - .split(inner_area); - - let help_text = vec![ - "Navigation:", - "s - Start/unpause the test", - "Esc - Pause the test", - "q - Quit", - "", - "Configuration:", - "--duration - Set test duration", - "--numbers - Include numbers in the test", - "--uppercase - Include uppercase letters", - "Run 'donkeytype help' for more options", - ]; - - for (i, &text) in help_text.iter().enumerate() { - let paragraph = Paragraph::new(text).style(Style::default().fg(Color::White)); - f.render_widget(paragraph, chunks[i]); + pub fn render(&self, frame: &mut impl FrameWrapperInterface, area: Rect) { + let block = Block::default() + .title("Help") + .borders(Borders::ALL) + .style(Style::default().fg(Color::White).bg(Color::Black)); + + let inner_area = block.inner(area); + + let chunks = Layout::default() + .direction(Direction::Vertical) + .constraints([ + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(1), + Constraint::Length(1), + ]) + .split(inner_area); + + let help_text = vec![ + "Navigation:", + "s - Start/unpause the test", + "Esc - Pause the test", + "q - Quit", + "", + "Configuration:", + "--duration - Set test duration", + "--numbers - Include numbers in the test", + "--uppercase - Include uppercase letters", + "Run 'donkeytype help' for more options", + ]; + + // Render Clear widget first + frame.render_widget(Clear, area); + + // Render block + frame.render_widget(block, area); + + // Render text paragraphs + for (i, &text) in help_text.iter().enumerate() { + let paragraph = Paragraph::new(text).style(Style::default().fg(Color::White)); + frame.render_widget(paragraph, chunks[i]); + } } - - f.render_widget(Clear, area); - f.render_widget(block, area); - } } diff --git a/src/runner.rs b/src/runner.rs index c42f644..05b6aaa 100644 --- a/src/runner.rs +++ b/src/runner.rs @@ -230,7 +230,7 @@ impl Runner { if self.show_help { let help_area = centered_rect(60, 60, frame.size()); - self.help_window.render(frame.frame(), help_area); + self.help_window.render(frame, help_area); } let expected_input_str = self