let mut array = SwaybarArray::new();
let set_net_error = |is_empty: bool, array: &mut SwaybarArray| {
if is_empty {
- let down_obj = SwaybarObject::from_string("net_down".to_owned(), "Net ERROR".into());
+ let down_obj =
+ SwaybarObject::from_error_string("net_down".to_owned(), "Net ERROR".into());
array.push_object(down_obj);
- let up_obj = SwaybarObject::from_string("net_up".to_owned(), "Net ERROR".into());
+ let up_obj = SwaybarObject::from_error_string("net_up".to_owned(), "Net ERROR".into());
array.push_object(up_obj);
} else {
let down_ref_opt = array.get_by_name_mut("net_down");
if let Some(net) = net_obj.as_mut() {
if let Err(e) = handle_net(is_empty, net, &mut array) {
let mut stderr_handle = io::stderr().lock();
- stderr_handle.write_all(e.to_string().as_bytes()).ok();
+ stderr_handle.write_all(format!("{}\n", e).as_bytes()).ok();
net_obj = None;
set_net_error(is_empty, &mut array);
}
}
}
+ pub fn from_error_string(name: String, msg: String) -> Self {
+ Self {
+ full_text: msg,
+ short_text: None,
+ color: Some("#ff2222ff".into()),
+ background: None,
+ border: Some("#ffffffff".into()),
+ border_top: None,
+ border_bottom: None,
+ border_left: None,
+ border_right: None,
+ min_width: None,
+ align: None,
+ name: Some(name),
+ instance: None,
+ urgent: None,
+ separator: None,
+ separator_block_width: None,
+ markup: None,
+ }
+ }
+
pub fn update_as_net_down(&mut self, metric: String) {
self.full_text = metric;
self.color = Some("#ff8888ff".to_owned());