allow exiting from modals; add buttons

This commit is contained in:
🪞👃🪞 2025-04-04 16:32:53 +03:00
parent a4ee3d2912
commit 2e072cb51c
6 changed files with 81 additions and 68 deletions

72
Cargo.lock generated
View file

@ -156,9 +156,9 @@ dependencies = [
[[package]] [[package]]
name = "borsh" name = "borsh"
version = "1.5.6" version = "1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b2b74d67a0fc0af8e9823b79fd1c43a0900e5a8f0e0f4cc9210796bf3a820126" checksum = "ad8646f98db542e39fc66e68a20b2144f6a732636df7c2354e74645faaa433ce"
dependencies = [ dependencies = [
"borsh-derive", "borsh-derive",
"cfg_aliases", "cfg_aliases",
@ -166,9 +166,9 @@ dependencies = [
[[package]] [[package]]
name = "borsh-derive" name = "borsh-derive"
version = "1.5.6" version = "1.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d37ed1b2c9b78421218a0b4f6d8349132d6ec2cfeba1cfb0118b0a8e268df9e" checksum = "fdd1d3c0c2f5833f22386f252fe8ed005c7f59fdcddeef025c01b4c3b9fd9ac3"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"proc-macro-crate", "proc-macro-crate",
@ -283,18 +283,18 @@ checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]] [[package]]
name = "clap" name = "clap"
version = "4.5.32" version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6088f3ae8c3608d19260cd7445411865a485688711b78b5be70d78cd96136f83" checksum = "d8aa86934b44c19c50f87cc2790e19f54f7a67aedb64101c2e1a2e5ecfb73944"
dependencies = [ dependencies = [
"clap_builder", "clap_builder",
] ]
[[package]] [[package]]
name = "clap_builder" name = "clap_builder"
version = "4.5.32" version = "4.5.35"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "22a7ef7f676155edfb82daa97f99441f3ebf4a58d5e32f295a56259f1b6facc8" checksum = "2414dbb2dd0695280da6ea9261e327479e9d37b0630f6b53ba2a11c60c679fd9"
dependencies = [ dependencies = [
"anstream", "anstream",
"anstyle", "anstyle",
@ -388,9 +388,9 @@ dependencies = [
[[package]] [[package]]
name = "darling" name = "darling"
version = "0.20.10" version = "0.20.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"darling_macro", "darling_macro",
@ -398,9 +398,9 @@ dependencies = [
[[package]] [[package]]
name = "darling_core" name = "darling_core"
version = "0.20.10" version = "0.20.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e"
dependencies = [ dependencies = [
"fnv", "fnv",
"ident_case", "ident_case",
@ -412,9 +412,9 @@ dependencies = [
[[package]] [[package]]
name = "darling_macro" name = "darling_macro"
version = "0.20.10" version = "0.20.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead"
dependencies = [ dependencies = [
"darling_core", "darling_core",
"quote", "quote",
@ -463,9 +463,9 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"
[[package]] [[package]]
name = "errno" name = "errno"
version = "0.3.10" version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.59.0", "windows-sys 0.59.0",
@ -479,18 +479,18 @@ checksum = "dd2e7510819d6fbf51a5545c8f922716ecfb14df168a3242f7d33e0239efe6a1"
[[package]] [[package]]
name = "file_type" name = "file_type"
version = "0.8.1" version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e237c2e6ae6183998137b1157b9e0fddfa25ce480f99f40ec1a5c2d49747c6d1" checksum = "a463c5a8c1d775e4cde89f8fbe047a3d6969fa66557fbc6223ef6644f476506d"
dependencies = [ dependencies = [
"phf", "phf",
] ]
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.1.0" version = "1.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc" checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@ -727,9 +727,9 @@ dependencies = [
[[package]] [[package]]
name = "log" name = "log"
version = "0.4.26" version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]] [[package]]
name = "lru" name = "lru"
@ -748,9 +748,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
[[package]] [[package]]
name = "miniz_oxide" name = "miniz_oxide"
version = "0.8.5" version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5" checksum = "ff70ce3e48ae43fa075863cef62e8b43b71a4f2382229920e0df362592919430"
dependencies = [ dependencies = [
"adler2", "adler2",
] ]
@ -823,9 +823,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.21.1" version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d75b0bedcc4fe52caa0e03d9f1151a323e4aa5e2d78ba3580400cd3c9e2bc4bc" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]] [[package]]
name = "opener" name = "opener"
@ -1166,9 +1166,9 @@ dependencies = [
[[package]] [[package]]
name = "rubato" name = "rubato"
version = "0.16.1" version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdd96992d7e24b3d7f35fdfe02af037a356ac90d41b466945cf3333525a86eea" checksum = "5258099699851cfd0082aeb645feb9c084d9a5e1f1b8d5372086b989fc5e56a1"
dependencies = [ dependencies = [
"num-complex", "num-complex",
"num-integer", "num-integer",
@ -1445,8 +1445,8 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369"
[[package]] [[package]]
name = "tengri" name = "tengri"
version = "0.5.0" version = "0.5.1"
source = "git+https://codeberg.org/unspeaker/tengri?rev=b43cd0f#b43cd0f64f2de9ae0a0f7d41b6869de4a41065bb" source = "git+https://codeberg.org/unspeaker/tengri?rev=829d35b#829d35b61fc4323273613695f02bb1e6bfde0cbd"
dependencies = [ dependencies = [
"tengri_input", "tengri_input",
"tengri_output", "tengri_output",
@ -1455,18 +1455,18 @@ dependencies = [
[[package]] [[package]]
name = "tengri_input" name = "tengri_input"
version = "0.5.0" version = "0.5.1"
source = "git+https://codeberg.org/unspeaker/tengri?rev=b43cd0f#b43cd0f64f2de9ae0a0f7d41b6869de4a41065bb" source = "git+https://codeberg.org/unspeaker/tengri?rev=829d35b#829d35b61fc4323273613695f02bb1e6bfde0cbd"
[[package]] [[package]]
name = "tengri_output" name = "tengri_output"
version = "0.5.0" version = "0.5.1"
source = "git+https://codeberg.org/unspeaker/tengri?rev=b43cd0f#b43cd0f64f2de9ae0a0f7d41b6869de4a41065bb" source = "git+https://codeberg.org/unspeaker/tengri?rev=829d35b#829d35b61fc4323273613695f02bb1e6bfde0cbd"
[[package]] [[package]]
name = "tengri_tui" name = "tengri_tui"
version = "0.5.0" version = "0.5.1"
source = "git+https://codeberg.org/unspeaker/tengri?rev=b43cd0f#b43cd0f64f2de9ae0a0f7d41b6869de4a41065bb" source = "git+https://codeberg.org/unspeaker/tengri?rev=829d35b#829d35b61fc4323273613695f02bb1e6bfde0cbd"
dependencies = [ dependencies = [
"atomic_float", "atomic_float",
"better-panic", "better-panic",

View file

@ -5,7 +5,7 @@ edition = "2024"
[dependencies.tengri] [dependencies.tengri]
git = "https://codeberg.org/unspeaker/tengri" git = "https://codeberg.org/unspeaker/tengri"
rev = "b43cd0f" rev = "829d35b"
[dependencies] [dependencies]
clap = { version = "^4.5.4", features = [ "cargo" ] } clap = { version = "^4.5.4", features = [ "cargo" ] }

View file

@ -1,14 +1,17 @@
use crate::*; use crate::*;
impl Taggart { impl Taggart {
pub fn mode_quit (&mut self, event: &Event) {
todo!()
}
pub fn quit_begin (&mut self, input: &TuiIn) { pub fn quit_begin (&mut self, input: &TuiIn) {
if self.tasks.len() == 0 { if self.tasks.len() == 0 {
input.done() input.done()
} else { } else {
self.mode = Some(Mode::Quit { value: false }) self.mode = Some(Mode::Quit { value: 1 })
}
}
pub fn mode_quit (&mut self, event: &Event) {
match event {
press!(Esc) => { self.mode = None },
_ => todo!()
} }
} }
} }

View file

@ -1,12 +1,15 @@
use crate::*; use crate::*;
impl Taggart { impl Taggart {
pub fn mode_save (&mut self, event: &Event) {
todo!()
}
pub fn save_begin (&mut self) { pub fn save_begin (&mut self) {
if self.tasks.len() > 0 { if self.tasks.len() > 0 {
self.mode = Some(Mode::Save { value: false }) self.mode = Some(Mode::Save { value: 1 })
}
}
pub fn mode_save (&mut self, event: &Event) {
match event {
press!(Esc) => { self.mode = None },
_ => todo!()
} }
} }
} }

View file

@ -26,10 +26,10 @@ pub enum Mode {
index: usize, index: usize,
}, },
Save { Save {
value: bool, value: u8,
}, },
Quit { Quit {
value: bool, value: u8,
}, },
} }

View file

@ -4,17 +4,6 @@ pub(crate) use pad::PadStr;
mod table; pub use self::table::*; mod table; pub use self::table::*;
impl Taggart {
pub(crate) const FG_BROWSE: Color = Color::Rgb(255, 192, 0);
pub(crate) const BG_BROWSE: Color = Color::Rgb(0, 0, 0);
pub(crate) const BG_EDIT: Color = Color::Rgb(48, 128, 0);
pub(crate) const FG_EDIT: Color = Color::Rgb(255, 255, 255);
pub(crate) const BG_SAVE: Color = Color::Rgb(192, 96, 0);
pub(crate) const FG_SAVE: Color = Color::Rgb(255, 255, 255);
pub(crate) const BG_QUIT: Color = Color::Rgb(128, 0, 0);
pub(crate) const FG_QUIT: Color = Color::Rgb(255, 255, 255);
}
impl Content<TuiOut> for Taggart { impl Content<TuiOut> for Taggart {
fn content (&self) -> impl Render<TuiOut> { fn content (&self) -> impl Render<TuiOut> {
let w = self.display.w(); let w = self.display.w();
@ -35,11 +24,10 @@ impl Content<TuiOut> for Taggart {
Color::Rgb(48,48,48), Color::Rgb(48,48,48),
Modifier::DIM Modifier::DIM
); );
let message = format!("You have {} unsaved change(s)", self.tasks.len()); let message = Bsp::s(format!("Save {} change(s)?", self.tasks.len()),
let modal = Fill::xy(Align::c(Tui::modify(false, Modifier::DIM, Tui::fg_bg( Bsp::s("",
Color::Rgb(255,255,255), Bsp::e(" Clear changes ", Bsp::e(" Continue editing ", " Save "))));
Color::Rgb(0, 0, 0), let modal = Self::modal(message);
Expand::xy(2, 2, "Save?")))));
Content::render(&modal, to) Content::render(&modal, to)
}, },
Some(Mode::Quit { value }) => { Some(Mode::Quit { value }) => {
@ -48,11 +36,10 @@ impl Content<TuiOut> for Taggart {
Color::Rgb(48,48,48), Color::Rgb(48,48,48),
Modifier::DIM Modifier::DIM
); );
let message = format!("You have {} unsaved change(s)", self.tasks.len()); let message = Bsp::s(format!("Save {} change(s) before exiting?", self.tasks.len()),
let modal = Fill::xy(Align::c(Tui::modify(false, Modifier::DIM, Tui::fg_bg( Bsp::s("",
Color::Rgb(255,255,255), Bsp::e(" Exit without saving ", Bsp::e(" Cancel ", " Save and exit "))));
Color::Rgb(0, 0, 0), let modal = Self::modal(message);
Expand::xy(2, 2, "Save?")))));
Content::render(&modal, to) Content::render(&modal, to)
}, },
_ => {}, _ => {},
@ -61,6 +48,26 @@ impl Content<TuiOut> for Taggart {
} }
impl Taggart { impl Taggart {
pub(crate) const FG_BROWSE: Color = Color::Rgb(255, 192, 0);
pub(crate) const BG_BROWSE: Color = Color::Rgb(0, 0, 0);
pub(crate) const BG_EDIT: Color = Color::Rgb(48, 128, 0);
pub(crate) const FG_EDIT: Color = Color::Rgb(255, 255, 255);
pub(crate) const BG_SAVE: Color = Color::Rgb(192, 96, 0);
pub(crate) const FG_SAVE: Color = Color::Rgb(255, 255, 255);
pub(crate) const BG_QUIT: Color = Color::Rgb(128, 0, 0);
pub(crate) const FG_QUIT: Color = Color::Rgb(255, 255, 255);
pub(crate) const FG_MODAL: Color = Color::Rgb(255, 255, 255);
pub(crate) const BG_MODAL: Color = Color::Rgb(0, 0, 0);
fn modal (content: impl Content<TuiOut>) -> impl Content<TuiOut> {
let position = |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));
position(style(border(content)))
}
fn title_bar (&self) -> impl Content<TuiOut> { fn title_bar (&self) -> impl Content<TuiOut> {
status_bar( status_bar(
Color::Rgb(0, 0, 0), Color::Rgb(0, 0, 0),