auraline 0.6.0

utility that renders information into a string suitable to be embedded in the shell prompt.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use crate::{chunk::Chunk, options::Options};
use smol_str::{format_smolstr, SmolStr};
use sysinfo::{MemoryRefreshKind, RefreshKind};

pub async fn show(opts: &Options) -> Option<Chunk<SmolStr>> {
    if !opts.memory {
        return None;
    }
    let info = sysinfo::System::new_with_specifics(
        RefreshKind::nothing().with_memory(MemoryRefreshKind::everything()),
    );
    let mem_perc = info.used_memory() as f64 / info.total_memory() as f64 * 100.0;
    Some(Chunk::new(
        opts.select_str("μ", ""),
        format_smolstr!("{:.1}%", mem_perc),
    ))
}