garage44.eu/jeroen/pinnacle

logclone: git clone https://garage44.eu/jeroen/pinnacle.git

.. /programs/src/bin/info.rs

raw

//! The command `info`: this device's system, cores, memory and time up, as
//! a table for the terminal.

#![no_std]
#![no_main]

extern crate alloc;

use alloc::string::String;
use alloc::vec;
use pinnacle_rt::output::Output;

#[unsafe(no_mangle)]
fn main(argument: u64) -> u64 {
    let out = Output::start(argument);
    let (cores, ram, free) = pinnacle_rt::info();
    let row = |what: &str, value: String| vec![String::from(what), value];
    out.table(
        &["", ""],
        vec![
            row("System", alloc::format!("Pinnacle {}", env!("CARGO_PKG_VERSION"))),
            row("Cores", alloc::format!("{cores}")),
            row("Memory", alloc::format!("{} MiB", ram >> 20)),
            row("Free", alloc::format!("{} MiB", free >> 20)),
            row("Up", alloc::format!("{} s", pinnacle_rt::time() / 1000)),
        ],
    );
    out.status(0, "")
}