aboutsummaryrefslogtreecommitdiff
path: root/src/app/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/app/mod.rs')
-rw-r--r--src/app/mod.rs36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/app/mod.rs b/src/app/mod.rs
index d51640f..7bb9c72 100644
--- a/src/app/mod.rs
+++ b/src/app/mod.rs
@@ -5,11 +5,33 @@ use miette::{Diagnostic, ErrReport, Result};
use store::{Context, Store};
use thiserror::Error;
+#[derive(Debug, Default, PartialEq)]
+pub enum AppMode {
+ #[default]
+ Init,
+ Counter,
+ Exit,
+}
+
+impl std::fmt::Display for AppMode {
+ fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
+ write!(
+ f,
+ "{}",
+ match self {
+ AppMode::Init => "INIT",
+ AppMode::Counter => "COUNTER",
+ AppMode::Exit => "EXIT",
+ }
+ )
+ }
+}
+
#[derive(Default)]
pub struct App {
context: Context,
error: Option<ErrReport>,
- exit: bool,
+ mode: AppMode,
}
#[derive(Diagnostic, Debug, Error, PartialEq)]
@@ -26,16 +48,22 @@ impl App {
let store = self.context.unwrap_store();
store.init()?;
+
+ self.mode = AppMode::Counter;
Ok(self)
}
+ pub fn get_app_mode(&self) -> &AppMode {
+ &self.mode
+ }
+
pub fn get_exit_status(&self) -> bool {
- self.exit
+ self.mode == AppMode::Exit
}
pub fn exit(&mut self) -> Result<()> {
tracing::event!(tracing::Level::TRACE, exit = true, "Changing exit status.");
- self.exit = true;
+ self.mode = AppMode::Exit;
Ok(())
}
@@ -183,7 +211,7 @@ mod tests {
let res = app.exit();
assert!(res.is_ok());
- assert!(app.exit);
+ assert_eq!(app.mode, AppMode::Exit);
}
#[test]