Reorganize repository
This commit is contained in:
60
crates/ratatui/src/confirm.rs
Normal file
60
crates/ratatui/src/confirm.rs
Normal file
@@ -0,0 +1,60 @@
|
||||
use ratatui::layout::{Alignment, Constraint, Layout, Rect};
|
||||
use ratatui::style::{Color, Style};
|
||||
use ratatui::text::{Line, Span};
|
||||
use ratatui::widgets::Paragraph;
|
||||
use ratatui::Frame;
|
||||
|
||||
use super::ModalFrame;
|
||||
|
||||
pub struct ConfirmModal<'a> {
|
||||
title: &'a str,
|
||||
message: &'a str,
|
||||
selected: bool,
|
||||
}
|
||||
|
||||
impl<'a> ConfirmModal<'a> {
|
||||
pub fn new(title: &'a str, message: &'a str, selected: bool) -> Self {
|
||||
Self {
|
||||
title,
|
||||
message,
|
||||
selected,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn render_centered(self, frame: &mut Frame, term: Rect) {
|
||||
let inner = ModalFrame::new(self.title)
|
||||
.width(30)
|
||||
.height(5)
|
||||
.border_color(Color::Yellow)
|
||||
.render_centered(frame, term);
|
||||
|
||||
let rows = Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).split(inner);
|
||||
|
||||
frame.render_widget(
|
||||
Paragraph::new(self.message).alignment(Alignment::Center),
|
||||
rows[0],
|
||||
);
|
||||
|
||||
let yes_style = if self.selected {
|
||||
Style::new().fg(Color::Black).bg(Color::Yellow)
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
let no_style = if !self.selected {
|
||||
Style::new().fg(Color::Black).bg(Color::Yellow)
|
||||
} else {
|
||||
Style::default()
|
||||
};
|
||||
|
||||
let buttons = Line::from(vec![
|
||||
Span::styled(" Yes ", yes_style),
|
||||
Span::raw(" "),
|
||||
Span::styled(" No ", no_style),
|
||||
]);
|
||||
|
||||
frame.render_widget(
|
||||
Paragraph::new(buttons).alignment(Alignment::Center),
|
||||
rows[1],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user