factor out modules; modal -> dialog

This commit is contained in:
🪞👃🪞 2025-04-06 16:05:48 +03:00
parent c075871e50
commit b157a87647
7 changed files with 163 additions and 158 deletions

50
src/view/dialog.rs Normal file
View file

@ -0,0 +1,50 @@
use crate::*;
impl Taggart {
pub(crate) const FG_MODAL: Color = Color::Rgb(255, 255, 255);
pub(crate) const BG_MODAL: Color = Color::Rgb(0, 0, 0);
fn dialog (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
let pos = |x|Fill::xy( Align::c(x));
let style = |x|Tui::modify(false, Modifier::DIM, Tui::fg_bg(Self::FG_MODAL, Self::BG_MODAL, x));
let border = |x|Margin::xy(1, 1, Bsp::b(Border(true, Lozenge(true, Default::default())), x));
let bg = |x|Bsp::a(x, Repeat(" "));
pos(style(border(bg(content))))
}
fn dialog_help (&self) {
}
fn dialog_save (&self, value: u8) {
let choices = [
if value == 0 { "[ Clear changes ]" } else { " Clear changes " },
if value == 1 { "[ Continue editing ]" } else { " Continue editing " },
if value == 2 { "[ Write and continue ]" } else { " Write and continue " },
];
Self::dialog(Bsp::s(
format!("Save {} change(s)?", self.tasks.len()),
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))));
}
fn dialog_quit (&self, value: u8) {
let choices = [
if value == 0 { "[ Exit without saving ]" } else { " Exit without saving " },
if value == 1 { "[ Cancel ]" } else { " Cancel " },
if value == 2 { "[ Write and exit ]" } else { " Write and exit " },
];
Self::dialog(Bsp::s(
format!("Save {} change(s) before exiting?", self.tasks.len()),
Bsp::s("", Bsp::e(choices[0], Bsp::e(choices[1], choices[2])))));
}
pub fn render_dialog (&self, to: &mut TuiOut) {
match self.mode {
Some(Mode::Save { value }) => {
to.tint_all(Color::Rgb(96,96,96), Color::Rgb(48,48,48), Modifier::DIM);
Content::render(&self.dialog_save(value), to)
},
Some(Mode::Quit { value }) => {
to.tint_all(Color::Rgb(96,96,96), Color::Rgb(48,48,48), Modifier::DIM);
Content::render(&self.dialog_quit(value), to)
},
Some(Mode::Help { .. }) => {
},
_ => {},
}
}
}