Prevent crashes when terminal is too small

This commit is contained in:
Joachim Lusiardi 2023-12-25 08:44:44 +01:00
parent de5ea76913
commit 67faae44b1
1 changed files with 16 additions and 0 deletions

View File

@ -43,6 +43,22 @@ fn main() -> Result<()> {
let mut area = frame.size();
frame.render_widget(Block::default().style(Style::default().bg(Color::Green)), area);
// don't draw stuff except an info box if the terminal is too small (less than 80x25)
// to prevent the read drawing code from crashing the game.
if area.width < 80 || area.height < 25 {
let block = Block::default()
.title("Info")
.borders(Borders::ALL)
.border_style(Style::default().fg(Color::White))
.border_type(BorderType::Rounded)
.style(Style::default().bg(Color::Black));
let paragraph = Paragraph::new("Terminal needs to be at leas 80x25!")
.block(block)
.wrap(Wrap { trim: true });
frame.render_widget(paragraph, area);
return
}
if area.width > 80 {
area.x = (area.width - 80) / 2;
area.width = 80;