mirror of
https://codeberg.org/unspeaker/perch.git
synced 2025-12-06 01:26:43 +01:00
50 lines
2.2 KiB
Rust
50 lines
2.2 KiB
Rust
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 { .. }) => {
|
|
},
|
|
_ => {},
|
|
}
|
|
}
|
|
}
|