pass sysinfo to system.rs and uptime.rs (#6)
Some checks are pending
Rust / build (push) Waiting to run

This commit is contained in:
vali 2024-08-15 00:29:57 +00:00 committed by GitHub
parent cd8ddc2177
commit 4d509839f5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 7 deletions

View file

@ -9,6 +9,7 @@ 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; use nix::sys::sysinfo::sysinfo;
@ -16,14 +17,15 @@ 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(),
uptime: get_current()?,
desktop: get_desktop_info(), desktop: get_desktop_info(),
memory_usage: get_memory_usage(sysinfo()?), uptime: get_current(&info)?,
memory_usage: get_memory_usage(&info),
storage: get_root_disk_usage()?, storage: get_root_disk_usage()?,
colors: print_dots(), colors: print_dots(),
}; };

View file

@ -40,9 +40,9 @@ pub fn get_root_disk_usage() -> Result<String, io::Error> {
)) ))
} }
pub fn get_memory_usage(info: SysInfo) -> String { pub fn get_memory_usage(info: &SysInfo) -> String {
#[inline(always)] #[inline(always)]
fn parse_memory_info(info: SysInfo) -> (f64, f64) { fn parse_memory_info(info: &SysInfo) -> (f64, f64) {
let total_memory_kb = (info.ram_total() / 1024) as f64; let total_memory_kb = (info.ram_total() / 1024) as f64;
let available_memory_kb = (info.ram_unused() / 1024) as f64; let available_memory_kb = (info.ram_unused() / 1024) as f64;

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;