updated config methods
This commit is contained in:
parent
c2482fa257
commit
b73fb753be
@ -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) {
|
pub fn load<'a>(&mut self, configfile: &'a str) {
|
||||||
let fileopen: Result<File, std::io::Error>;
|
let fileopen: Result<File, std::io::Error>;
|
||||||
let filemeta = std::fs::metadata(configfile);
|
let filemeta = std::fs::metadata(configfile);
|
||||||
@ -53,7 +65,8 @@ impl Config {
|
|||||||
Err(_e) => Config::new(),
|
Err(_e) => Config::new(),
|
||||||
};
|
};
|
||||||
*self = cfg;
|
*self = cfg;
|
||||||
self.save(configfile);
|
self.feed_missing();
|
||||||
|
self.save(&configfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn save<'a>(&self, configfile: &'a str) {
|
pub fn save<'a>(&self, configfile: &'a str) {
|
||||||
|
@ -3,6 +3,7 @@ use crate::zabbix::api::get_zabbix_problems;
|
|||||||
use crate::zabbix::problems::ZabbixLayout;
|
use crate::zabbix::problems::ZabbixLayout;
|
||||||
use launchy::Color;
|
use launchy::Color;
|
||||||
use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, Pad};
|
use launchy::{self, Canvas, CanvasLayout, CanvasLayoutPoller, MsgPollingWrapper, Pad};
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
pub const MATRIX_SIZE: i32 = 8;
|
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());
|
println!("Refresh rate is {} seconds", cfg.refresh.unwrap());
|
||||||
loop {
|
loop {
|
||||||
let zabbix_data = get_zabbix_problems(cfg);
|
let zabbix_data = get_zabbix_problems(cfg);
|
||||||
|
print!(".");
|
||||||
|
std::io::stdout().flush().unwrap();
|
||||||
datamatrix.compute(&zabbix_data);
|
datamatrix.compute(&zabbix_data);
|
||||||
let mut x = 0i32;
|
let mut x = 0i32;
|
||||||
let mut y = 1i32;
|
let mut y = 1i32;
|
||||||
@ -52,7 +55,8 @@ pub fn draw(canvas: &mut CanvasLayout, datamatrix: &mut ZabbixLayout, cfg: &mut
|
|||||||
x = 0;
|
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)));
|
std::thread::sleep(std::time::Duration::from_secs(cfg.refresh.unwrap_or(5)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user