diff options
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/battery.rs | 10 | ||||
-rw-r--r-- | src/utils/cpu.rs | 8 | ||||
-rw-r--r-- | src/utils/disk.rs | 6 | ||||
-rw-r--r-- | src/utils/load_average.rs | 6 | ||||
-rw-r--r-- | src/utils/memory.rs | 10 | ||||
-rw-r--r-- | src/utils/mpd.rs | 8 | ||||
-rw-r--r-- | src/utils/spotify.rs | 6 | ||||
-rw-r--r-- | src/utils/time.rs | 10 | ||||
-rw-r--r-- | src/utils/uptime.rs | 6 | ||||
-rw-r--r-- | src/utils/volume.rs | 8 | ||||
-rw-r--r-- | src/utils/weather.rs | 12 |
11 files changed, 45 insertions, 45 deletions
diff --git a/src/utils/battery.rs b/src/utils/battery.rs index a38d3b4..1278303 100644 --- a/src/utils/battery.rs +++ b/src/utils/battery.rs @@ -1,17 +1,17 @@ -use crate::types::Config; +use crate::config::CONFIG; use std::fs::File; use std::io::Error; use std::io::Read; // getting battery percentage -pub fn get_battery(config: &Config) -> Result<String, Error> { +pub fn get_battery() -> Result<String, Error> { let battery_full_cap_file = format!( "/sys/class/power_supply/{}/charge_full_design", - config.battery.source + CONFIG.battery.source ); let battery_charge_now_file = format!( "/sys/class/power_supply/{}/charge_now", - config.battery.source + CONFIG.battery.source ); let mut buf = String::new(); @@ -31,7 +31,7 @@ pub fn get_battery(config: &Config) -> Result<String, Error> { let battery_percentage = (charge_now as f32 / full_design as f32) * 100.0; let result = format!( " {} {:.0}% {}", - config.battery.icon, battery_percentage, config.seperator + CONFIG.battery.icon, battery_percentage, CONFIG.seperator ); Ok(result) } diff --git a/src/utils/cpu.rs b/src/utils/cpu.rs index 3e582ad..f8ae595 100644 --- a/src/utils/cpu.rs +++ b/src/utils/cpu.rs @@ -1,18 +1,18 @@ -use crate::types::Config; +use crate::config::CONFIG; use std::fs::File; use std::io::Read; // getting cpu temperature -pub fn get_cpu_temp(config: &Config) -> Result<String, std::io::Error> { +pub fn get_cpu_temp() -> Result<String, std::io::Error> { let mut buf = String::new(); File::open("/sys/class/thermal/thermal_zone0/temp")?.read_to_string(&mut buf)?; let value = buf.trim().parse::<f32>().unwrap(); let result = format!( " {} {}° {}", - config.cpu_temperature.icon, + CONFIG.cpu_temperature.icon, value / 1000.0, - config.seperator + CONFIG.seperator ); Ok(result) } diff --git a/src/utils/disk.rs b/src/utils/disk.rs index 2aa7b63..f082ef1 100644 --- a/src/utils/disk.rs +++ b/src/utils/disk.rs @@ -1,6 +1,6 @@ -use crate::types::Config; +use crate::config::CONFIG; -pub fn get_disk(config: &Config) -> String { +pub fn get_disk() -> String { const GB: u64 = (1024 * 1024) * 1024; let statvfs = nix::sys::statvfs::statvfs("/").unwrap(); let mut disk_used = String::new(); @@ -12,6 +12,6 @@ pub fn get_disk(config: &Config) -> String { disk_used.push_str(&format!("{}G", used)); format!( " {} {} {}", - config.disk.icon, disk_used, config.seperator + CONFIG.disk.icon, disk_used, CONFIG.seperator ) } diff --git a/src/utils/load_average.rs b/src/utils/load_average.rs index 2cd271f..4fd38f7 100644 --- a/src/utils/load_average.rs +++ b/src/utils/load_average.rs @@ -1,8 +1,8 @@ -use crate::types::Config; +use crate::config::CONFIG; use std::fs::File; use std::io::Read; -pub fn get_load_avg(config: &Config) -> String { +pub fn get_load_avg() -> String { let mut buf = String::new(); match File::open("/proc/loadavg") { Ok(mut file) => match file.read_to_string(&mut buf) { @@ -12,5 +12,5 @@ pub fn get_load_avg(config: &Config) -> String { _ => return String::from("Error"), }; let buf = buf.split_whitespace().collect::<Vec<_>>()[0]; - format!(" {} {} {}", config.loadavg.icon, buf, config.seperator) + format!(" {} {} {}", CONFIG.loadavg.icon, buf, CONFIG.seperator) } diff --git a/src/utils/memory.rs b/src/utils/memory.rs index 1a6c982..6283527 100644 --- a/src/utils/memory.rs +++ b/src/utils/memory.rs @@ -1,4 +1,4 @@ -use crate::types::Config; +use crate::config::CONFIG; use std::fs::File; use std::io::Read; @@ -7,7 +7,7 @@ mem_used = (mem_total + shmem - mem_free - mem_buffers - mem_cached - mem_srecl thanks for htop's developer on stackoverflow for providing this algorithm to calculate used memory. */ -pub fn get_memory(config: &Config) -> Result<String, std::io::Error> { +pub fn get_memory() -> Result<String, std::io::Error> { let mut buf = String::new(); File::open("/proc/meminfo")?.read_to_string(&mut buf)?; @@ -56,14 +56,14 @@ pub fn get_memory(config: &Config) -> Result<String, std::io::Error> { if mem_used > 1000 { result = format!( " {} {:.1}G {}", - config.memory.icon, + CONFIG.memory.icon, mem_used as f32 / 1000.0, - config.seperator + CONFIG.seperator ); } else { result = format!( " {} {}M {}", - config.memory.icon, mem_used, config.seperator + CONFIG.memory.icon, mem_used, CONFIG.seperator ); } Ok(result) diff --git a/src/utils/mpd.rs b/src/utils/mpd.rs index e521c4f..b7fdbd6 100644 --- a/src/utils/mpd.rs +++ b/src/utils/mpd.rs @@ -1,10 +1,10 @@ -use crate::types::Config; +use crate::config::CONFIG; use mpd::{Client, Song}; // yes, error handling looks fucking sucks! // getting mpd song file -pub fn get_mpd_current(config: &Config) -> String { - let stream_path = format!("{}:{}", config.mpd.host, config.mpd.port); +pub fn get_mpd_current() -> String { + let stream_path = format!("{}:{}", CONFIG.mpd.host, CONFIG.mpd.port); let empty_string = String::from(""); let mut conn = match Client::connect(&stream_path) { Ok(connection) => connection, @@ -20,7 +20,7 @@ pub fn get_mpd_current(config: &Config) -> String { let result = format!( " {} {} {}", - config.mpd.icon, current.file, config.seperator + CONFIG.mpd.icon, current.file, CONFIG.seperator ); result diff --git a/src/utils/spotify.rs b/src/utils/spotify.rs index 4954f3b..a73128d 100644 --- a/src/utils/spotify.rs +++ b/src/utils/spotify.rs @@ -1,11 +1,11 @@ -use crate::types::Config; +use crate::config::CONFIG; use dbus::blocking::stdintf::org_freedesktop_dbus::Properties; use dbus::{arg, blocking::Connection}; use std::time::Duration; // getting spotify current artist and title. // FIXME: I know im lazy asshole, this error handling looks ugly, i dont like it too, need to fix soon. -pub fn get_spotify(config: &Config) -> String { +pub fn get_spotify() -> String { let conn = match Connection::new_session() { Ok(conn) => conn, _ => return String::from(""), @@ -40,6 +40,6 @@ pub fn get_spotify(config: &Config) -> String { format!( " {} {} - {} {}", - config.spotify.icon, artist, title, config.seperator + CONFIG.spotify.icon, artist, title, CONFIG.seperator ) } diff --git a/src/utils/time.rs b/src/utils/time.rs index 3149ce6..fcfb691 100644 --- a/src/utils/time.rs +++ b/src/utils/time.rs @@ -1,13 +1,13 @@ -use crate::types::Config; +use crate::config::CONFIG; use chrono::prelude::*; -pub fn get_time(config: &Config) -> String { +pub fn get_time() -> String { let now = Local::now(); format!( " {} {} {}", - config.time.icon, - now.format(&config.time.format), - config.seperator + CONFIG.time.icon, + now.format(&CONFIG.time.format), + CONFIG.seperator ) } diff --git a/src/utils/uptime.rs b/src/utils/uptime.rs index 90f52a7..b5de930 100644 --- a/src/utils/uptime.rs +++ b/src/utils/uptime.rs @@ -1,8 +1,8 @@ -use crate::types::Config; +use crate::config::CONFIG; use std::fs::File; use std::io::Read; -pub fn get_uptime(config: &Config) -> Result<String, std::io::Error> { +pub fn get_uptime() -> Result<String, std::io::Error> { let mut buf = String::new(); match File::open("/proc/uptime") { Ok(mut file) => file.read_to_string(&mut buf)?, @@ -20,6 +20,6 @@ pub fn get_uptime(config: &Config) -> Result<String, std::io::Error> { } else { format!("{} min", minutes) }; - let result = format!(" {} {} {}", config.uptime.icon, uptime, config.seperator); + let result = format!(" {} {} {}", CONFIG.uptime.icon, uptime, CONFIG.seperator); Ok(result) } diff --git a/src/utils/volume.rs b/src/utils/volume.rs index 061ab60..c020ce8 100644 --- a/src/utils/volume.rs +++ b/src/utils/volume.rs @@ -1,9 +1,9 @@ -use crate::types::Config; +use crate::config::CONFIG; use alsa::mixer::{Mixer, SelemChannelId, SelemId}; // getting volume percentage -pub fn get_volume(config: &Config) -> String { - let card = if config.volume.card == "PULSE" { +pub fn get_volume() -> String { + let card = if CONFIG.volume.card == "PULSE" { "pulse" } else { "default" @@ -27,5 +27,5 @@ pub fn get_volume(config: &Config) -> String { ((raw_volume as f64 / range as f64) * 100.) as u64 }; - format!(" {} {}% {}", config.volume.icon, vol, config.seperator) + format!(" {} {}% {}", CONFIG.volume.icon, vol, CONFIG.seperator) } diff --git a/src/utils/weather.rs b/src/utils/weather.rs index 05fa60b..9dc053b 100644 --- a/src/utils/weather.rs +++ b/src/utils/weather.rs @@ -1,14 +1,14 @@ -use crate::types::Config; +use crate::config::CONFIG; // will make a GET request from wttr.in -pub fn get_weather(config: &Config) -> String { - let format = if config.weather.format.is_empty() { +pub fn get_weather() -> String { + let format = if CONFIG.weather.format.is_empty() { String::from("%l:+%t") } else { - config.weather.format.clone() + CONFIG.weather.format.clone() }; - let url = format!("http://wttr.in/{}?format=\"{}", config.weather.city, format); + let url = format!("http://wttr.in/{}?format=\"{}", CONFIG.weather.city, format); let err_string = String::from("Error"); let res = match minreq::get(url).send() { Ok(resp) => match resp.as_str() { @@ -18,5 +18,5 @@ pub fn get_weather(config: &Config) -> String { Err(_) => err_string, }; - format!(" {} {} {}", config.weather.icon, res, config.seperator) + format!(" {} {} {}", CONFIG.weather.icon, res, CONFIG.seperator) } |