mirror of
https://github.com/pcvolkmer/checkbar.git
synced 2025-04-19 11:06:50 +00:00
Provide custom time format config option
This commit is contained in:
parent
01bc8e7ade
commit
4eb609c9b5
@ -12,6 +12,9 @@ You should create a configuration file `.checkbar.toml` in your home directory,
|
|||||||
# Update interval in seconds. Default value if not set is 60 sec.
|
# Update interval in seconds. Default value if not set is 60 sec.
|
||||||
interval = 60
|
interval = 60
|
||||||
|
|
||||||
|
# Time format (optional), defaults to "%R" (= "%H:%M)"
|
||||||
|
time_format = "%H:%M:%S" # = "%T"
|
||||||
|
|
||||||
[[checks]]
|
[[checks]]
|
||||||
name = "Host 1"
|
name = "Host 1"
|
||||||
url = "https://host1.example.com"
|
url = "https://host1.example.com"
|
||||||
@ -49,6 +52,9 @@ interval = 60
|
|||||||
interval = "2m 30s"
|
interval = "2m 30s"
|
||||||
----
|
----
|
||||||
|
|
||||||
|
The value for `time_format` is used to set the time format to be shown. It defaults to `%R`.
|
||||||
|
For available options, see: https://docs.rs/chrono/latest/chrono/format/strftime/index.html
|
||||||
|
|
||||||
Each host or application to be checked consists of `name` and `url`.
|
Each host or application to be checked consists of `name` and `url`.
|
||||||
|
|
||||||
You can optionally specify `check_type`:
|
You can optionally specify `check_type`:
|
||||||
|
@ -13,6 +13,8 @@ pub struct Config {
|
|||||||
deserialize_with = "deserialize_duration"
|
deserialize_with = "deserialize_duration"
|
||||||
)]
|
)]
|
||||||
pub interval: Duration,
|
pub interval: Duration,
|
||||||
|
#[serde(default = "Config::default_time_format")]
|
||||||
|
pub time_format: String,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub colors: ColorConfig,
|
pub colors: ColorConfig,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
@ -20,6 +22,10 @@ pub struct Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
|
fn default_time_format() -> String {
|
||||||
|
return "%R".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
fn get_config_file() -> String {
|
fn get_config_file() -> String {
|
||||||
match env::args().nth(1) {
|
match env::args().nth(1) {
|
||||||
Some(config_file) => config_file,
|
Some(config_file) => config_file,
|
||||||
@ -46,6 +52,7 @@ impl Default for Config {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
interval: Duration::from_secs(60),
|
interval: Duration::from_secs(60),
|
||||||
|
time_format: Self::default_time_format(),
|
||||||
colors: ColorConfig::default(),
|
colors: ColorConfig::default(),
|
||||||
checks: vec![],
|
checks: vec![],
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,15 @@ pub struct ClickEvent {
|
|||||||
pub button: MouseButton,
|
pub button: MouseButton,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn print_states(check_configs: &[CheckConfig]) {
|
pub async fn print_states(config: &Config) {
|
||||||
print!("[");
|
print!("[");
|
||||||
let mut entries = vec![];
|
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(format!("{}", check_host(check_config).await));
|
||||||
}
|
}
|
||||||
entries.push(
|
entries.push(
|
||||||
json!({
|
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(),
|
.to_string(),
|
||||||
);
|
);
|
||||||
|
@ -31,7 +31,7 @@ async fn main() {
|
|||||||
let checks = task::spawn(async {
|
let checks = task::spawn(async {
|
||||||
loop {
|
loop {
|
||||||
let config = Config::read();
|
let config = Config::read();
|
||||||
print_states(&config.checks).await;
|
print_states(&config).await;
|
||||||
let _ = sleep(config.interval).await;
|
let _ = sleep(config.interval).await;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user