hex_patch/app/popup/
simple_choice.rs

1use ratatui::text::{Line, Span};
2
3use crate::app::settings::color_settings::ColorSettings;
4
5#[derive(Clone, Copy, Debug, PartialEq)]
6pub enum SimpleChoice {
7    Yes,
8    No,
9    Cancel,
10}
11
12impl SimpleChoice {
13    pub fn to_line(&self, color_settings: &ColorSettings) -> Line<'static> {
14        let mut ret = Line::from(vec![
15            Span::styled(t!("app.yes"), color_settings.yes),
16            Span::raw("  "),
17            Span::styled(t!("app.no"), color_settings.no),
18            Span::raw("  "),
19            Span::styled(t!("app.cancel"), color_settings.menu_text),
20        ]);
21
22        match self {
23            SimpleChoice::Yes => ret.spans[0].style = color_settings.yes_selected,
24            SimpleChoice::No => ret.spans[2].style = color_settings.no_selected,
25            SimpleChoice::Cancel => ret.spans[4].style = color_settings.menu_text_selected,
26        }
27
28        ret
29    }
30
31    pub fn next(&self) -> Self {
32        match self {
33            SimpleChoice::Yes => SimpleChoice::No,
34            SimpleChoice::No => SimpleChoice::Cancel,
35            SimpleChoice::Cancel => SimpleChoice::Yes,
36        }
37    }
38
39    pub fn previous(&self) -> Self {
40        match self {
41            SimpleChoice::Yes => SimpleChoice::Cancel,
42            SimpleChoice::No => SimpleChoice::Yes,
43            SimpleChoice::Cancel => SimpleChoice::No,
44        }
45    }
46}