diff --git a/Cargo.toml b/Cargo.toml index e2d3f98..ff853cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,7 @@ version = "0.1.0" edition = "2021" [dependencies] +atomic_enum = "0.2.0" chrono = "0.4.31" clap = { version = "4.4.18", features = ["derive", "cargo"] } crossterm = "0.27.0" diff --git a/src/config.rs b/src/config.rs index e3bf069..c373bcf 100644 --- a/src/config.rs +++ b/src/config.rs @@ -6,7 +6,7 @@ use ini::configparser::ini::Ini; use crate::{ color::{generate_gradient, parse_hex_color, ComputableColor}, - debug, + debug, get_app_mode, AppMode, }; pub struct Config { @@ -107,7 +107,9 @@ fn load_gradient(ini: &Ini) -> ComputableColor { i += 1; } - if !debug::is_debug() && ini.getbool("gradient", "gradient_loop").unwrap().unwrap() { + if get_app_mode() != AppMode::Debug + && ini.getbool("gradient", "gradient_loop").unwrap().unwrap() + { let mut loop_keys = keys.clone(); loop_keys.reverse(); for i in 1..loop_keys.len() { @@ -115,7 +117,7 @@ fn load_gradient(ini: &Ini) -> ComputableColor { } } - let steps: usize = if debug::is_debug() { + let steps: usize = if get_app_mode() == AppMode::Debug { debug::DEBUG_COLOR_DISPLAY_SIZE * 2 } else { ini.getuint("gradient", "gradient_steps") diff --git a/src/debug.rs b/src/debug.rs index aef2ffa..e2ed57b 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -1,7 +1,4 @@ -use std::{ - io::{self, Write}, - sync::atomic::{AtomicBool, Ordering}, -}; +use std::io::{self, Write}; use clap::crate_version; use crossterm::{ @@ -13,8 +10,6 @@ use crate::config::Config; pub const DEBUG_COLOR_DISPLAY_SIZE: usize = 50; -static DEBUG_MODE: AtomicBool = AtomicBool::new(false); - pub fn print_debug_infos(config: &mut Config) -> io::Result<()> { let mut stdout = io::stdout(); @@ -62,11 +57,3 @@ fn print_debug_label(key: &str) -> io::Result<()> { return Ok(()); } - -pub fn enable_debug_mode() -> () { - DEBUG_MODE.store(true, Ordering::Relaxed); -} - -pub fn is_debug() -> bool { - return DEBUG_MODE.load(Ordering::Relaxed); -} diff --git a/src/main.rs b/src/main.rs index 3925640..4749298 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,10 +2,12 @@ use core::panic; use std::{ io::{self, Write}, path::PathBuf, + sync::atomic::Ordering, thread, time::Duration, }; +use atomic_enum::atomic_enum; use chrono::Local; use clap::{Parser, Subcommand}; use config::{write_default_config, Config}; @@ -46,12 +48,29 @@ enum Commands { Debug {}, } +#[atomic_enum] +#[derive(PartialEq)] +pub enum AppMode { + Clock = 0, + Debug, +} + +static APP_MODE: AtomicAppMode = AtomicAppMode::new(AppMode::Debug); + +pub fn get_app_mode() -> AppMode { + return APP_MODE.load(Ordering::Relaxed); +} + +pub fn set_app_mode(mode: AppMode) { + return APP_MODE.store(mode, Ordering::Relaxed); +} + fn main() -> io::Result<()> { let cli = Cli::parse(); match &cli.command { Some(Commands::Debug {}) => { - debug::enable_debug_mode(); + set_app_mode(AppMode::Debug); } _ => {} }