Clear data before new bar display iteration
This makes sure that data displayed is always fresh
This commit is contained in:
parent
4452cdbaa0
commit
79e1a5956e
@ -116,6 +116,12 @@ impl UnibarModuleCpu {
|
|||||||
|
|
||||||
impl bar_modules::BarModuleActions for UnibarModuleCpu {
|
impl bar_modules::BarModuleActions for UnibarModuleCpu {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.cpu_times_sample_1 = CpuTimes::new();
|
||||||
|
self.cpu_times_sample_2 = CpuTimes::new();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
self.cpu_times_sample_1 = self.read_cpu_times().expect("Trouble getting CPU times sample 1");
|
self.cpu_times_sample_1 = self.read_cpu_times().expect("Trouble getting CPU times sample 1");
|
||||||
|
@ -21,8 +21,12 @@ impl UnibarModuleDate {
|
|||||||
impl bar_modules::BarModuleActions for UnibarModuleDate {
|
impl bar_modules::BarModuleActions for UnibarModuleDate {
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.date_time = Local::now();
|
self.date_time = Local::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn generate_data(&mut self) {
|
||||||
if self.opts.debug {
|
if self.opts.debug {
|
||||||
println!("-----> Date dump {:#?}", self.date_time);
|
println!("-----> Date dump {:#?}", self.date_time);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,11 @@ impl UnibarModuleMemory {
|
|||||||
|
|
||||||
impl bar_modules::BarModuleActions for UnibarModuleMemory {
|
impl bar_modules::BarModuleActions for UnibarModuleMemory {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.meminfo_str = "".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
let path = Path::new("/proc/meminfo");
|
let path = Path::new("/proc/meminfo");
|
||||||
@ -42,7 +47,6 @@ impl bar_modules::BarModuleActions for UnibarModuleMemory {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
self.meminfo_str.pop();
|
self.meminfo_str.pop();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
|
@ -6,8 +6,8 @@ use crate::bar_modules;
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct UnibarModuleMusic {
|
pub struct UnibarModuleMusic {
|
||||||
opts: common::AppOptions,
|
opts: common::AppOptions,
|
||||||
current_stdout :String,
|
current_stdout: String,
|
||||||
progress_stdout :String,
|
progress_stdout: String,
|
||||||
state_stdout: String,
|
state_stdout: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,6 +25,13 @@ impl UnibarModuleMusic {
|
|||||||
|
|
||||||
impl bar_modules::BarModuleActions for UnibarModuleMusic {
|
impl bar_modules::BarModuleActions for UnibarModuleMusic {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.current_stdout = "".to_string();
|
||||||
|
self.progress_stdout = "".to_string();
|
||||||
|
self.state_stdout = "stopped".to_string();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
// MPD format options here:
|
// MPD format options here:
|
||||||
|
@ -26,15 +26,24 @@ impl UnibarModuleNetwork {
|
|||||||
|
|
||||||
impl bar_modules::BarModuleActions for UnibarModuleNetwork {
|
impl bar_modules::BarModuleActions for UnibarModuleNetwork {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.network_info = json!(serde_json::Value::Null);
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
// Output of 'ip -j address' command has network information
|
// Output of 'ip -j address' command has network information
|
||||||
let ip_addr_output = Command::new("ip")
|
match Command::new("ip")
|
||||||
.arg("-j") // Output in json format
|
.arg("-j") // Output in json format
|
||||||
.arg("address")
|
.arg("address")
|
||||||
.stdout(Stdio::piped())
|
.stdout(Stdio::piped())
|
||||||
.output()
|
.output() {
|
||||||
.unwrap();
|
Err(e) => {
|
||||||
|
eprintln!("Error getting network information {e}");
|
||||||
|
self.network_info = json!(serde_json::Value::Null);
|
||||||
|
}
|
||||||
|
Ok(ip_addr_output) => {
|
||||||
self.ip_addr_stdout = String::from_utf8(ip_addr_output.stdout).unwrap();
|
self.ip_addr_stdout = String::from_utf8(ip_addr_output.stdout).unwrap();
|
||||||
self.ip_addr_stdout.pop();
|
self.ip_addr_stdout.pop();
|
||||||
|
|
||||||
@ -66,6 +75,8 @@ impl bar_modules::BarModuleActions for UnibarModuleNetwork {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
if self.opts.debug {
|
if self.opts.debug {
|
||||||
println!("-----> ip_addr - {:#?}", self.network_info);
|
println!("-----> ip_addr - {:#?}", self.network_info);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,11 @@ impl UnibarModulePower {
|
|||||||
|
|
||||||
impl bar_modules::BarModuleActions for UnibarModulePower {
|
impl bar_modules::BarModuleActions for UnibarModulePower {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.power_info = PowerData::new();
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
// Following command is used to get power data:
|
// Following command is used to get power data:
|
||||||
|
@ -21,8 +21,12 @@ impl UnibarModuleTime {
|
|||||||
impl bar_modules::BarModuleActions for UnibarModuleTime {
|
impl bar_modules::BarModuleActions for UnibarModuleTime {
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn clear(&mut self) {
|
||||||
self.date_time = Local::now();
|
self.date_time = Local::now();
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn generate_data(&mut self) {
|
||||||
if self.opts.debug {
|
if self.opts.debug {
|
||||||
println!("-----> Time dump {:#?}", self.date_time);
|
println!("-----> Time dump {:#?}", self.date_time);
|
||||||
}
|
}
|
||||||
|
@ -150,6 +150,11 @@ impl UnibarModuleWeather {
|
|||||||
|
|
||||||
impl bar_modules::BarModuleActions for UnibarModuleWeather {
|
impl bar_modules::BarModuleActions for UnibarModuleWeather {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn clear(&mut self) {
|
||||||
|
self.weather_info = json!(serde_json::Value::Null);
|
||||||
|
}
|
||||||
|
|
||||||
// --------------------
|
// --------------------
|
||||||
fn generate_data(&mut self) {
|
fn generate_data(&mut self) {
|
||||||
// Print a web page onto stdout
|
// Print a web page onto stdout
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
// --------------------
|
// --------------------
|
||||||
/// All Bar modules must implement the actions
|
/// All Bar modules must implement the actions
|
||||||
pub trait BarModuleActions {
|
pub trait BarModuleActions {
|
||||||
|
/// Do necessary clean up before starting new fetch
|
||||||
|
fn clear(&mut self);
|
||||||
|
|
||||||
/// Do necessary processing to generate data for this bar module
|
/// Do necessary processing to generate data for this bar module
|
||||||
fn generate_data(&mut self);
|
fn generate_data(&mut self);
|
||||||
|
|
||||||
|
@ -86,13 +86,15 @@ impl Unibar {
|
|||||||
for md in &mut self.bar_modules_enabled {
|
for md in &mut self.bar_modules_enabled {
|
||||||
let mut mod_parts = Vec::new();
|
let mut mod_parts = Vec::new();
|
||||||
|
|
||||||
// Each bar module implements following 3 steps:
|
// Each bar module implements following 4 steps:
|
||||||
|
// * Clear data from previous iteration
|
||||||
// * Generate raw data with pertinent information
|
// * Generate raw data with pertinent information
|
||||||
// * Return a unicode icon to be displayed
|
// * Return a unicode icon to be displayed
|
||||||
// * Return a String content to be displayed after the icon
|
// * Return a String content to be displayed after the icon
|
||||||
//
|
//
|
||||||
// Following generates ICON+CONTENT string for a module to be displayed
|
// Following generates ICON+CONTENT string for a module to be displayed
|
||||||
// in the bar
|
// in the bar
|
||||||
|
md.clear();
|
||||||
md.generate_data();
|
md.generate_data();
|
||||||
mod_parts.push(md.get_icon());
|
mod_parts.push(md.get_icon());
|
||||||
mod_parts.push(md.get_content());
|
mod_parts.push(md.get_content());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user