mirror of
https://github.com/pcvolkmer/checkbar.git
synced 2025-04-19 19:16:50 +00:00
Use json macro instead of formatting json strings
This commit is contained in:
parent
031f36ca04
commit
bfb9e9b6cd
23
src/main.rs
23
src/main.rs
@ -1,4 +1,5 @@
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use serde_json::json;
|
||||||
use std::fmt::{Display, Formatter, Result};
|
use std::fmt::{Display, Formatter, Result};
|
||||||
use std::env;
|
use std::env;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
@ -65,10 +66,16 @@ impl Display for CheckResult {
|
|||||||
CheckState::Warn => color_config.warn,
|
CheckState::Warn => color_config.warn,
|
||||||
CheckState::Down => color_config.down,
|
CheckState::Down => color_config.down,
|
||||||
};
|
};
|
||||||
|
|
||||||
write!(
|
write!(
|
||||||
f,
|
f,
|
||||||
"{{\"full_text\":\"{}\",\"name\":\"{}\",\"separator_block_width\":16,\"color\":\"{}\"}}",
|
"{}",
|
||||||
self.name, self.name, color
|
json!({
|
||||||
|
"full_text": self.name,
|
||||||
|
"name": self.name,
|
||||||
|
"separator_block_width": 16,
|
||||||
|
"color": color
|
||||||
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,10 +123,9 @@ async fn print_states(check_configs: &[CheckConfig]) {
|
|||||||
for check_config in check_configs {
|
for check_config in check_configs {
|
||||||
entries.push(format!("{}", check_host(check_config).await));
|
entries.push(format!("{}", check_host(check_config).await));
|
||||||
}
|
}
|
||||||
entries.push(format!(
|
entries.push(json!({
|
||||||
"{{\"full_text\":\"check@{}\"}}",
|
"full_text": chrono::Local::now().format("%H:%M").to_string()
|
||||||
chrono::Local::now().format("%H:%M")
|
}).to_string());
|
||||||
));
|
|
||||||
println!("{}],", entries.join(","));
|
println!("{}],", entries.join(","));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,7 +175,10 @@ async fn run_click_cmd(cmd: String) {
|
|||||||
|
|
||||||
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
|
#[tokio::main(flavor = "multi_thread", worker_threads = 2)]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
println!("{{\"version\":1,\"click_events\":true}}");
|
println!("{}", json!({
|
||||||
|
"version": 1,
|
||||||
|
"click_events": true
|
||||||
|
}));
|
||||||
println!("[");
|
println!("[");
|
||||||
|
|
||||||
let inputs = task::spawn(async {
|
let inputs = task::spawn(async {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user