fix: Min-term panic (#607)

* Fix min-term panic

* Align center
This commit is contained in:
JEEVITHA KANNAN K S 2024-09-22 22:21:25 +05:30 committed by GitHub
parent aca42f2411
commit b69e823375
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -84,44 +84,32 @@ impl AppState {
let terminal_size = frame.area();
if terminal_size.width < MIN_WIDTH || terminal_size.height < MIN_HEIGHT {
let size_warning_message = format!(
let warning = Paragraph::new(format!(
"Terminal size too small:\nWidth = {} Height = {}\n\nMinimum size:\nWidth = {} Height = {}",
terminal_size.width,
terminal_size.height,
MIN_WIDTH,
MIN_HEIGHT,
);
let warning_paragraph = Paragraph::new(size_warning_message.clone())
))
.alignment(Alignment::Center)
.style(Style::default().fg(ratatui::style::Color::Red).bold())
.wrap(ratatui::widgets::Wrap { trim: true });
// Get the maximum width and height of text lines
let text_lines: Vec<String> = size_warning_message
.lines()
.map(|line| line.to_string())
.collect();
let max_line_length = text_lines.iter().map(|line| line.len()).max().unwrap_or(0);
let num_lines = text_lines.len();
let centered_layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Fill(1),
Constraint::Length(5),
Constraint::Fill(1),
])
.split(terminal_size);
// Calculate the centered area
let centered_area = ratatui::layout::Rect {
x: terminal_size.x + (terminal_size.width - max_line_length as u16) / 2,
y: terminal_size.y + (terminal_size.height - num_lines as u16) / 2,
width: max_line_length as u16,
height: num_lines as u16,
};
frame.render_widget(warning_paragraph, centered_area);
self.drawable = false;
return frame.render_widget(warning, centered_layout[1]);
} else {
self.drawable = true;
}
if !self.drawable {
return;
}
let label_block =
Block::default()
.borders(Borders::all())