Added date and time modules
This commit is contained in:
parent
0b7ff61da0
commit
4452cdbaa0
@ -10,4 +10,5 @@ serde = "1.0.196"
|
|||||||
serde_json = "1.0.113"
|
serde_json = "1.0.113"
|
||||||
curl = "0.4.46"
|
curl = "0.4.46"
|
||||||
regex = "1.11.1"
|
regex = "1.11.1"
|
||||||
|
chrono = "0.4.41"
|
||||||
clap = { version = "4.5.1", features = ["derive"] }
|
clap = { version = "4.5.1", features = ["derive"] }
|
||||||
|
47
src/bar_modules/bar_module_date.rs
Normal file
47
src/bar_modules/bar_module_date.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
use chrono::{DateTime, Local};
|
||||||
|
use crate::common;
|
||||||
|
use crate::bar_modules;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct UnibarModuleDate {
|
||||||
|
opts: common::AppOptions,
|
||||||
|
date_time: DateTime<Local>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UnibarModuleDate {
|
||||||
|
// --------------------
|
||||||
|
pub fn new(o :common::AppOptions) -> Self {
|
||||||
|
UnibarModuleDate {
|
||||||
|
opts: o,
|
||||||
|
date_time: Local::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl bar_modules::BarModuleActions for UnibarModuleDate {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn generate_data(&mut self) {
|
||||||
|
self.date_time = Local::now();
|
||||||
|
if self.opts.debug {
|
||||||
|
println!("-----> Date dump {:#?}", self.date_time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn get_content(&self) -> String {
|
||||||
|
return format!("{}", self.date_time.format("%Y %h %d"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn get_icon(&self) -> String {
|
||||||
|
return "📅".to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl bar_modules::BarModuleDebug for UnibarModuleDate {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn post_debug(&self) {
|
||||||
|
}
|
||||||
|
}
|
47
src/bar_modules/bar_module_time.rs
Normal file
47
src/bar_modules/bar_module_time.rs
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
use chrono::{DateTime, Local};
|
||||||
|
use crate::common;
|
||||||
|
use crate::bar_modules;
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct UnibarModuleTime {
|
||||||
|
opts: common::AppOptions,
|
||||||
|
date_time: DateTime<Local>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl UnibarModuleTime {
|
||||||
|
// --------------------
|
||||||
|
pub fn new(o :common::AppOptions) -> Self {
|
||||||
|
UnibarModuleTime {
|
||||||
|
opts: o,
|
||||||
|
date_time: Local::now(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl bar_modules::BarModuleActions for UnibarModuleTime {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn generate_data(&mut self) {
|
||||||
|
self.date_time = Local::now();
|
||||||
|
if self.opts.debug {
|
||||||
|
println!("-----> Time dump {:#?}", self.date_time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn get_content(&self) -> String {
|
||||||
|
return format!("{}", self.date_time.format("%I:%M%p %Z"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn get_icon(&self) -> String {
|
||||||
|
return "🕑".to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl bar_modules::BarModuleDebug for UnibarModuleTime {
|
||||||
|
|
||||||
|
// --------------------
|
||||||
|
fn post_debug(&self) {
|
||||||
|
}
|
||||||
|
}
|
@ -23,3 +23,5 @@ pub mod bar_module_network;
|
|||||||
pub mod bar_module_memory;
|
pub mod bar_module_memory;
|
||||||
pub mod bar_module_cpu;
|
pub mod bar_module_cpu;
|
||||||
pub mod bar_module_power;
|
pub mod bar_module_power;
|
||||||
|
pub mod bar_module_date;
|
||||||
|
pub mod bar_module_time;
|
||||||
|
@ -66,7 +66,8 @@ impl Unibar {
|
|||||||
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_cpu::UnibarModuleCpu::new(self.opts.clone())));
|
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_cpu::UnibarModuleCpu::new(self.opts.clone())));
|
||||||
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_power::UnibarModulePower::new(self.opts.clone())));
|
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_power::UnibarModulePower::new(self.opts.clone())));
|
||||||
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_network::UnibarModuleNetwork::new(self.opts.clone())));
|
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_network::UnibarModuleNetwork::new(self.opts.clone())));
|
||||||
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_weather::UnibarModuleWeather::new(self.opts.clone())));
|
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_date::UnibarModuleDate::new(self.opts.clone())));
|
||||||
|
self.bar_modules_enabled.push(Box::new(bar_modules::bar_module_time::UnibarModuleTime::new(self.opts.clone())));
|
||||||
|
|
||||||
// Run in a forever-loop ...
|
// Run in a forever-loop ...
|
||||||
loop {
|
loop {
|
||||||
@ -117,6 +118,8 @@ impl Unibar {
|
|||||||
Box::new(bar_modules::bar_module_network::UnibarModuleNetwork::new(self.opts.clone())),
|
Box::new(bar_modules::bar_module_network::UnibarModuleNetwork::new(self.opts.clone())),
|
||||||
Box::new(bar_modules::bar_module_cpu::UnibarModuleCpu::new(self.opts.clone())),
|
Box::new(bar_modules::bar_module_cpu::UnibarModuleCpu::new(self.opts.clone())),
|
||||||
Box::new(bar_modules::bar_module_power::UnibarModulePower::new(self.opts.clone())),
|
Box::new(bar_modules::bar_module_power::UnibarModulePower::new(self.opts.clone())),
|
||||||
|
Box::new(bar_modules::bar_module_date::UnibarModuleDate::new(self.opts.clone())),
|
||||||
|
Box::new(bar_modules::bar_module_time::UnibarModuleTime::new(self.opts.clone())),
|
||||||
];
|
];
|
||||||
for md in bar_modules_debugged {
|
for md in bar_modules_debugged {
|
||||||
md.post_debug();
|
md.post_debug();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user