Skip to content

Commit

Permalink
[fix] changed the render method to take impl FrameWrapperInstance ins…
Browse files Browse the repository at this point in the history
…tead of Frame<B>
  • Loading branch information
theghostmac committed Oct 26, 2024
1 parent 495eae4 commit 57d729b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 45 deletions.
92 changes: 48 additions & 44 deletions src/help_window.rs
Original file line number Diff line number Diff line change
@@ -1,59 +1,63 @@
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 {
pub fn new() -> Self {
HelpWindow
}

pub fn render<B: Backend>(&self, f: &mut Frame<B>, 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 <seconds> - 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 <seconds> - 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);
}
}
2 changes: 1 addition & 1 deletion src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 57d729b

Please sign in to comment.