diff --git a/src/main.rs b/src/main.rs index c543311..785d28b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,12 @@ mod swaybar_object; fn main() { - println!("Hello, world!"); - + println!( + "{}", + serde_json::to_string(&swaybar_object::SwaybarHeader::new()) + .expect("Should be able to serialize SwaybarHeader") + ); + println!("["); let mut array = swaybar_object::SwaybarArray::new(); array.push_object(swaybar_object::SwaybarObject::default()); array.push_object(swaybar_object::SwaybarObject::new()); diff --git a/src/swaybar_object.rs b/src/swaybar_object.rs index 672b56c..4ae99df 100644 --- a/src/swaybar_object.rs +++ b/src/swaybar_object.rs @@ -3,6 +3,17 @@ use std::fmt::Display; use chrono::prelude::*; use serde::{Deserialize, Serialize}; +#[derive(Serialize, Deserialize, Debug)] +pub struct SwaybarHeader { + pub version: u32, + #[serde(skip_serializing_if = "Option::is_none")] + pub click_events: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub cont_signal: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub stop_signal: Option, +} + #[derive(Serialize, Deserialize, Debug)] pub struct SwaybarObject { pub full_text: String, @@ -45,6 +56,17 @@ pub struct SwaybarArray { objects: Vec, } +impl SwaybarHeader { + pub fn new() -> Self { + Self { + version: 1, + click_events: None, + cont_signal: None, + stop_signal: None, + } + } +} + impl SwaybarObject { pub fn new() -> Self { Self {