-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathunsaved_changes.rs
79 lines (74 loc) · 2.39 KB
/
unsaved_changes.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
use ratatui::{
layout::Alignment,
style::{Color, Modifier, Style},
text::{Line, Span},
widgets::{Block, Borders, Paragraph},
};
use crate::{app::Data, label::Handler as LabelHandler, screen::Handler as ScreenHandler};
use super::{KeyHandler, PopupOutput, Window};
pub(crate) struct UnsavedChanges {
pub(crate) should_quit: bool,
}
impl KeyHandler for UnsavedChanges {
fn is_focusing(&self, window_type: Window) -> bool {
window_type == Window::UnsavedChanges
}
fn left(&mut self, _: &mut Data, _: &mut ScreenHandler, _: &mut LabelHandler) {
if !self.should_quit {
self.should_quit = true;
}
}
fn right(&mut self, _: &mut Data, _: &mut ScreenHandler, _: &mut LabelHandler) {
if self.should_quit {
self.should_quit = false;
}
}
fn get_user_input(&self) -> PopupOutput {
PopupOutput::Boolean(self.should_quit)
}
fn dimensions(&self) -> Option<(u16, u16)> {
Some((50, 5))
}
fn widget(&self) -> Paragraph {
let message = vec![
Line::from(Span::styled(
"Are you sure you want to quit?",
Style::default().fg(Color::White),
)),
Line::from(Span::from("")),
Line::from(vec![
Span::styled(
" Yes ",
if self.should_quit {
Style::default()
} else {
Style::default().fg(Color::White)
},
),
Span::styled(
" No ",
if self.should_quit {
Style::default().fg(Color::White)
} else {
Style::default()
},
),
]),
];
Paragraph::new(message).alignment(Alignment::Center).block(
Block::default()
.title(Span::styled(
"You Have Unsaved Changes.",
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD),
))
.title_alignment(Alignment::Center)
.borders(Borders::ALL)
.style(Style::default().fg(Color::Yellow)),
)
}
}
impl UnsavedChanges {
pub(crate) fn new() -> Self {
UnsavedChanges { should_quit: false }
}
}