From b73fb753beac5f66f48c9c133272937966d4b188 Mon Sep 17 00:00:00 2001 From: Paul Lecuq Date: Sun, 12 Sep 2021 23:46:33 +0200 Subject: [PATCH] updated config methods --- src/config/mod.rs | 15 ++++++++++++++- src/padcontrol/mod.rs | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index bea54c4..0ac8aef 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -26,6 +26,18 @@ impl Config { } } + fn feed_missing(&mut self) { + if self.authtoken.is_none() { + self.authtoken = Some(String::from("")); + } + if self.refresh.is_none() { + self.refresh = Some(5u64); + } + if self.limit.is_none() { + self.limit = Some(20i64); + } + } + pub fn load<'a>(&mut self, configfile: &'a str) { let fileopen: Result; let filemeta = std::fs::metadata(configfile); @@ -53,7 +65,8 @@ impl Config { Err(_e) => Config::new(), }; *self = cfg; - self.save(configfile); + self.feed_missing(); + self.save(&configfile); } pub fn save<'a>(&self, configfile: &'a str) { diff --git a/src/padcontrol/mod.rs b/src/padcontrol/mod.rs index 7c66f7e..a4eea34 100644 --- a/src/padcontrol/mod.rs +++ b/src/padcontrol/mod.rs @@ -3,6 +3,7 @@ use crate::zabbix::api::get_zabbix_problems; use crate::zabbix::problems::ZabbixLayout; use launchy::Color; use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, Pad}; +use std::io::Write; pub const MATRIX_SIZE: i32 = 8; @@ -34,6 +35,8 @@ pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut println!("Refresh rate is {} seconds", cfg.refresh.unwrap()); loop { let zabbix_data = get_zabbix_problems(cfg); + print!("."); + std::io::stdout().flush().unwrap(); datamatrix.compute(&zabbix_data); let mut x = 0i32; let mut y = 1i32; @@ -52,7 +55,8 @@ pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut x = 0; }; } - let _a = canvas.flush(); + canvas.flush().unwrap(); + std::io::stdout().flush().unwrap(); std::thread::sleep(std::time::Duration::from_secs(cfg.refresh.unwrap_or(5))); } }