hints_json and improved plaintext
This commit is contained in:
parent
59efd6e20e
commit
62eb2bff11
@ -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(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user