Prevent crashes when terminal is too small
This commit is contained in:
parent
de5ea76913
commit
67faae44b1
16
src/main.rs
16
src/main.rs
|
@ -43,6 +43,22 @@ fn main() -> Result<()> {
|
||||||
let mut area = frame.size();
|
let mut area = frame.size();
|
||||||
frame.render_widget(Block::default().style(Style::default().bg(Color::Green)), area);
|
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 {
|
if area.width > 80 {
|
||||||
area.x = (area.width - 80) / 2;
|
area.x = (area.width - 80) / 2;
|
||||||
area.width = 80;
|
area.width = 80;
|
||||||
|
|
Loading…
Reference in New Issue