aboutsummaryrefslogtreecommitdiff
path: root/src/run.rs
diff options
context:
space:
mode:
authorMustafa Salih <37256744+MustafaSalih1993@users.noreply.github.com>2021-01-26 02:44:13 +0300
committerGitHub <noreply@github.com>2021-01-26 02:44:13 +0300
commit6c0dfddead48e603826fbf637fe51f02e8320223 (patch)
tree3ac7796df10cd487598e4c256c96a84ab08a39fd /src/run.rs
parent9525a1075199d5fd202d1744dc502ff5a766aa99 (diff)
Reads network bandwith (#39)
* updated crate version * updated crate version * rsblocks now reads netspeed per second
Diffstat (limited to 'src/run.rs')
-rw-r--r--src/run.rs31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/run.rs b/src/run.rs
index c6c72a6..141e32d 100644
--- a/src/run.rs
+++ b/src/run.rs
@@ -1,12 +1,10 @@
+use crate::config::CONFIG;
use crate::types::*;
use crate::utils::*;
-use crate::config::CONFIG;
use std::sync::mpsc;
use std::thread;
use std::time::Duration;
-/* This is ugly, maybe i will try to impliment a threadpool */
-
pub fn run(mut blocks: Blocks) {
let (tx, rx) = mpsc::channel();
@@ -49,6 +47,16 @@ pub fn run(mut blocks: Blocks) {
});
}
+ // net speed thread
+ if CONFIG.netspeed.enabled {
+ let net_tx = tx.clone();
+ thread::spawn(move || loop {
+ // get_netspeed will sleep inside the function
+ let net_data = ThreadsData::NetSpeed(netspeed::get_netspeed());
+ net_tx.send(net_data).unwrap();
+ });
+ }
+
// Disk thread
if CONFIG.disk.enabled {
let disk_tx = tx.clone();
@@ -122,7 +130,7 @@ pub fn run(mut blocks: Blocks) {
//Main
{
// NOTE: order matters to the final format
- let mut bar: Vec<String> = vec![String::from(""); 11];
+ let mut bar: Vec<String> = vec![String::from(""); 12];
//iterating the values recieved from the threads
for data in rx {
match data {
@@ -130,13 +138,14 @@ pub fn run(mut blocks: Blocks) {
ThreadsData::Mpd(x) => bar[1] = x,
ThreadsData::Sound(x) => bar[2] = x,
ThreadsData::Weather(x) => bar[3] = x,
- ThreadsData::Disk(x) => bar[4] = x,
- ThreadsData::Memory(x) => bar[5] = x,
- ThreadsData::CpuTemp(x) => bar[6] = x,
- ThreadsData::LoadAvg(x) => bar[7] = x,
- ThreadsData::Battery(x) => bar[8] = x,
- ThreadsData::Uptime(x) => bar[9] = x,
- ThreadsData::Time(x) => bar[10] = x,
+ ThreadsData::NetSpeed(x) => bar[4] = x,
+ ThreadsData::Disk(x) => bar[5] = x,
+ ThreadsData::Memory(x) => bar[6] = x,
+ ThreadsData::CpuTemp(x) => bar[7] = x,
+ ThreadsData::LoadAvg(x) => bar[8] = x,
+ ThreadsData::Battery(x) => bar[9] = x,
+ ThreadsData::Uptime(x) => bar[10] = x,
+ ThreadsData::Time(x) => bar[11] = x,
}
// match ends here