mirror of
https://github.com/pcvolkmer/checkbar.git
synced 2025-07-02 14:22:54 +00:00
Provide custom time format config option
This commit is contained in:
@ -13,6 +13,8 @@ pub struct Config {
|
||||
deserialize_with = "deserialize_duration"
|
||||
)]
|
||||
pub interval: Duration,
|
||||
#[serde(default = "Config::default_time_format")]
|
||||
pub time_format: String,
|
||||
#[serde(default)]
|
||||
pub colors: ColorConfig,
|
||||
#[serde(default)]
|
||||
@ -20,6 +22,10 @@ pub struct Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
fn default_time_format() -> String {
|
||||
return "%R".to_string();
|
||||
}
|
||||
|
||||
fn get_config_file() -> String {
|
||||
match env::args().nth(1) {
|
||||
Some(config_file) => config_file,
|
||||
@ -46,6 +52,7 @@ impl Default for Config {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
interval: Duration::from_secs(60),
|
||||
time_format: Self::default_time_format(),
|
||||
colors: ColorConfig::default(),
|
||||
checks: vec![],
|
||||
}
|
||||
|
@ -24,15 +24,15 @@ pub struct ClickEvent {
|
||||
pub button: MouseButton,
|
||||
}
|
||||
|
||||
pub async fn print_states(check_configs: &[CheckConfig]) {
|
||||
pub async fn print_states(config: &Config) {
|
||||
print!("[");
|
||||
let mut entries = vec![];
|
||||
for check_config in check_configs {
|
||||
for check_config in &config.checks {
|
||||
entries.push(format!("{}", check_host(check_config).await));
|
||||
}
|
||||
entries.push(
|
||||
json!({
|
||||
"full_text": chrono::Local::now().format("%H:%M").to_string()
|
||||
"full_text": chrono::Local::now().format(config.time_format.as_str()).to_string()
|
||||
})
|
||||
.to_string(),
|
||||
);
|
||||
|
@ -31,7 +31,7 @@ async fn main() {
|
||||
let checks = task::spawn(async {
|
||||
loop {
|
||||
let config = Config::read();
|
||||
print_states(&config.checks).await;
|
||||
print_states(&config).await;
|
||||
let _ = sleep(config.interval).await;
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user