-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Prevent crashes when terminal size shrinks too small - Display notice to resize screen
- Loading branch information
Showing
3 changed files
with
94 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use ratatui::buffer::Buffer; | ||
use ratatui::layout::Alignment; | ||
use ratatui::layout::Rect; | ||
use ratatui::style::{Modifier, Style, Stylize}; | ||
use ratatui::text::Line; | ||
use ratatui::widgets::Widget; | ||
use ratatui::widgets::{Block, BorderType, Borders, Paragraph}; | ||
|
||
use super::{app_color, utils}; | ||
|
||
#[derive(Clone, Copy)] | ||
pub struct InsufficientSizeNotice; | ||
|
||
impl InsufficientSizeNotice { | ||
pub fn new() -> Self { | ||
Self {} | ||
} | ||
} | ||
|
||
impl Widget for InsufficientSizeNotice { | ||
fn render(self, area: Rect, buf: &mut Buffer) { | ||
let mut rect = Rect { | ||
x: 0, | ||
y: 0, | ||
width: area.width, | ||
height: 3, | ||
}; | ||
|
||
utils::center_rect_in_container(&mut rect, &area); | ||
|
||
let block = Block::default() | ||
.borders(Borders::ALL) | ||
.border_type(BorderType::Rounded) | ||
.border_style(Style::default().fg(*app_color::BORDER)); | ||
|
||
let paragraph = Paragraph::new(vec![ | ||
Line::from("Your terminal size is too small"), | ||
Line::from("Please resize to use the app"), | ||
]) | ||
.alignment(Alignment::Center) | ||
.add_modifier(Modifier::BOLD); | ||
|
||
block.render(area, buf); | ||
paragraph.render(rect, buf); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters