diff --git a/src/formats/json.rs b/src/formats/json.rs index 086777a..930ede0 100644 --- a/src/formats/json.rs +++ b/src/formats/json.rs @@ -20,6 +20,14 @@ impl Notification { } } + // Default action, as json string + pub fn default_action_json(&self) -> Value { + match self.default_action() { + None => serde_json::Value::from("None"), + Some(actn) => serde_json::Value::String(actn.0), + } + } + // Hints, as json pub fn hints_json(&self) -> Value { if self.hints().is_empty() { @@ -48,7 +56,7 @@ impl Notification { "hints": &self.hints_json(), "expiration_timeout": self.expir_timeout(), "urgency": self.urgency(), - "default_action": self.default_action().map(|actn| actn.0), + "default_action": self.default_action_json(), }) } } diff --git a/src/formats/plain.rs b/src/formats/plain.rs index a9d663e..ea469f0 100644 --- a/src/formats/plain.rs +++ b/src/formats/plain.rs @@ -2,10 +2,9 @@ use crate::notification::Notification; impl Notification { - // Plain string format, useful for printing - pub fn plain(&self) -> String { - // Actions - let actions: String = if self.actions().is_empty() { + // Actions, plain text format + pub fn actions_plain(&self) -> String { + if self.actions().is_empty() { "None".to_string() } else { self.actions() @@ -15,14 +14,20 @@ impl Notification { acc.push_str(&format!("\n\t{id}: {label}")); acc }) - }; - // Default action - let default_action: String = match self.default_action() { + } + } + + // Default action, as plain text + pub fn default_action_plain(&self) -> String { + match self.default_action() { None => "None".to_string(), Some(actn) => actn.0, - }; - // Hints - let hints: String = if self.hints().is_empty() { + } + } + + // Hints, as plain text + pub fn hints_plain(&self) -> String { + if self.hints().is_empty() { "None".to_string() } else { self.hints() @@ -31,20 +36,22 @@ impl Notification { acc.push_str(&format!("\n\t{}: {}", key, **value)); acc }) - }; + } + } - // Return the notification as a plain string + // Return the notification as a plain string + pub fn plain(&self) -> String { let plain_string: String = format!("App Name: {}\nReplace ID: {}\nIcon: {}\nSummary: {}\nBody: {}\nActions: {}\nHints: {}\nExpiration Timeout: {}\nUrgency: {}\nDefault Action: {}", &self.app_name(), &self.replace_id(), &self.icon(), &self.summary(), &self.body(), - actions, - hints, + &self.actions_plain(), + &self.hints_plain(), &self.expir_timeout(), &self.urgency(), - default_action, + &self.default_action_plain(), ); plain_string }