diff --git a/README.adoc b/README.adoc index 25e5405..c4154ac 100644 --- a/README.adoc +++ b/README.adoc @@ -33,6 +33,21 @@ You can optionally specify `check_type`: * `Html`: Default value, checks if a request is succeessful and returns HTTP OK - 200. * `Actuator`: Like `Html`, but checks if _Actuator_ shows that the application is up and running. +=== Colors + +To change the colors, use the following configuration. As an example the colors of the default configuration are shown. + +---- +... +[colors] +up = "#00FF00" +warn = "#FFFF00" +down = "#FF0000" +... +---- + +The color configuration is optional. If used, all colors must be specified. + === Execute commands _This feature is still experimental._ diff --git a/src/main.rs b/src/main.rs index e793f9a..d22c24b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,9 +8,17 @@ use tokio::task; #[derive(Deserialize)] struct Config { interval: Option, + colors: Option, checks: Vec, } +#[derive(Deserialize)] +struct ColorConfig { + up: String, + warn: String, + down: String, +} + #[derive(Deserialize)] struct CheckConfig { name: String, @@ -42,10 +50,18 @@ struct CheckResult { impl Display for CheckResult { fn fmt(&self, f: &mut Formatter<'_>) -> Result { + let color_config = match get_config().colors { + Some(color_config) => color_config, + None => ColorConfig { + up: String::from("#00FF00"), + warn: String::from("#FFFF00"), + down: String::from("#FF0000"), + }, + }; let color = match &self.state { - CheckState::Up => "#00FF00", - CheckState::Warn => "#FFFF00", - CheckState::Down => "#FF0000", + CheckState::Up => color_config.up, + CheckState::Warn => color_config.warn, + CheckState::Down => color_config.down, }; write!( f, @@ -105,7 +121,7 @@ async fn print_states(check_configs: &[CheckConfig]) { println!("{}],", entries.join(",")); } -async fn get_config() -> Config { +fn get_config() -> Config { let home_dir = dirs::home_dir().unwrap(); match fs::read_to_string(format!( "{}/.checkbar.toml", @@ -115,18 +131,20 @@ async fn get_config() -> Config { Ok(config) => config, Err(_e) => Config { interval: None, + colors: None, checks: vec![], }, }, - Err(_e) => Config { + Err(_) => Config { interval: None, + colors: None, checks: vec![], }, } } async fn get_click_cmd(name: String) -> Option { - for check in get_config().await.checks { + for check in get_config().checks { if check.name == name { return check.click_cmd; } @@ -175,7 +193,7 @@ async fn main() { let checks = task::spawn(async { loop { - let config = get_config().await; + let config = get_config(); print_states(&config.checks).await; std::thread::sleep(Duration::from_secs(config.interval.unwrap_or(60))); }