Compare commits

..

No commits in common. "cb9703f820461d8741f068838395f4de776b8c7a" and "4d509839f558e6c837d0134f3cfbc5a9bc1727c3" have entirely different histories.

5 changed files with 18 additions and 32 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View file

@ -72,7 +72,7 @@ Nix's binary cache, though._
## Customizing ## Customizing
You can't\*. You can't.
### Why? ### Why?
@ -102,11 +102,6 @@ run `direnv allow` to get started.
Non-nix users will need `cargo` and `gcc` installed on their system, see Non-nix users will need `cargo` and `gcc` installed on their system, see
`Cargo.toml` for available release profiles. `Cargo.toml` for available release profiles.
## Thanks
Huge thanks to everyone who took the time to make pull requests or nag me in
person about current issues.
## License ## License
Microfetch is licensed under [GPL3](LICENSE). See the license file for details. Microfetch is licensed under [GPL3](LICENSE). See the license file for details.

View file

@ -9,20 +9,23 @@ use crate::desktop::get_desktop_info;
use crate::release::{get_os_pretty_name, get_system_info}; use crate::release::{get_os_pretty_name, get_system_info};
use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname}; use crate::system::{get_memory_usage, get_root_disk_usage, get_shell, get_username_and_hostname};
use crate::uptime::get_current; use crate::uptime::get_current;
use std::io;
use color_eyre::Report; use color_eyre::Report;
use nix::sys::sysinfo::sysinfo;
fn main() -> Result<(), Report> { fn main() -> Result<(), Report> {
color_eyre::install()?; color_eyre::install()?;
let info = sysinfo().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
let fields = Fields { let fields = Fields {
user_info: get_username_and_hostname(), user_info: get_username_and_hostname(),
os_name: get_os_pretty_name()?, os_name: get_os_pretty_name()?,
kernel_version: get_system_info()?, kernel_version: get_system_info()?,
shell: get_shell(), shell: get_shell(),
desktop: get_desktop_info(), desktop: get_desktop_info(),
uptime: get_current()?, uptime: get_current(&info)?,
memory_usage: get_memory_usage()?, memory_usage: get_memory_usage(&info),
storage: get_root_disk_usage()?, storage: get_root_disk_usage()?,
colors: print_dots(), colors: print_dots(),
}; };

View file

@ -1,5 +1,6 @@
use color_eyre::Result; use color_eyre::Result;
use nix::sys::statvfs::statvfs; use nix::sys::statvfs::statvfs;
use nix::sys::sysinfo::SysInfo;
use std::env; use std::env;
use std::io::{self}; use std::io::{self};
@ -39,33 +40,21 @@ pub fn get_root_disk_usage() -> Result<String, io::Error> {
)) ))
} }
pub fn get_memory_usage() -> Result<String, io::Error> { pub fn get_memory_usage(info: &SysInfo) -> String {
#[inline(always)] #[inline(always)]
fn parse_memory_info() -> Result<(f64, f64), io::Error> { fn parse_memory_info(info: &SysInfo) -> (f64, f64) {
let mut total_memory_kb = 0.0; let total_memory_kb = (info.ram_total() / 1024) as f64;
let mut available_memory_kb = 0.0; let available_memory_kb = (info.ram_unused() / 1024) as f64;
for line in std::fs::read_to_string("/proc/meminfo")?.lines() { let total_memory_gb = total_memory_kb / (1024.0 * 1024.0);
let mut split = line.split_whitespace(); let available_memory_gb = available_memory_kb / (1024.0 * 1024.0);
let key = split.next().unwrap_or("");
if key == "MemTotal:" {
total_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0);
} else if key == "MemAvailable:" {
available_memory_kb = split.next().unwrap_or("0").parse().unwrap_or(0.0);
}
}
let total_memory_gb = total_memory_kb / 1024.0 / 1024.0;
let available_memory_gb = available_memory_kb / 1024.0 / 1024.0;
let used_memory_gb = total_memory_gb - available_memory_gb; let used_memory_gb = total_memory_gb - available_memory_gb;
Ok((used_memory_gb, total_memory_gb)) (used_memory_gb, total_memory_gb)
} }
let (used_memory, total_memory) = parse_memory_info()?; let (used_memory, total_memory) = parse_memory_info(info);
let percentage_used = (used_memory / total_memory * 100.0).round() as u64; let percentage_used = (used_memory / total_memory * 100.0).round() as u64;
Ok(format!( format!("{used_memory:.2} GiB / {total_memory:.2} GiB ({CYAN}{percentage_used}%{RESET})")
"{used_memory:.2} GiB / {total_memory:.2} GiB ({CYAN}{percentage_used}%{RESET})"
))
} }

View file

@ -1,9 +1,8 @@
use color_eyre::Result; use color_eyre::Result;
use nix::sys::sysinfo::sysinfo; use nix::sys::sysinfo::SysInfo;
use std::io; use std::io;
pub fn get_current() -> Result<String, io::Error> { pub fn get_current(info: &SysInfo) -> Result<String, io::Error> {
let info = sysinfo().map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
let uptime_seconds = info.uptime().as_secs_f64(); let uptime_seconds = info.uptime().as_secs_f64();
let total_minutes = (uptime_seconds / 60.0).round() as u64; let total_minutes = (uptime_seconds / 60.0).round() as u64;