Expand description
punfetch (lib)
A blazingly fast system info fetcher library written in Rust.
For the binary, see punfetch (bin).
Custom fetch example
// Required to be in scope to derive `Render`
use owo_colors::{
AnsiColors::{Green, Red, Yellow},
DynColors, OwoColorize,
};
// Recommended to use `default-features=false` to avoid binary deps
use punfetch::info::{PercentBar, DEFAULT_BAR_WIDTH};
use punfetch::{
// For the info module, add `features=["sysinfo"]`
info::{sys, ColorBar, HostInfo},
Distro,
Printer,
Render,
};
#[derive(Render)]
struct ExampleInfo {
pub field: String,
pub field_two: String,
pub optional: Option<String>,
}
impl ExampleInfo {
pub fn new() -> Self {
Self {
field: "value".into(),
field_two: "this is another value".into(),
optional: None,
}
}
}
fn main() {
let sys = sys();
let host_info = HostInfo::new(&sys);
// Create a printer with true colors enabled
let mut printer = Printer::default();
// Find the distro
let distro = Distro::search(host_info.distro.clone());
// Add some ascii art with true colors
printer.with_ascii(distro.ascii(Some(true)));
// Add a color
printer.with_color(distro.color(Some(true)));
// Add the host info
printer.with_info(host_info);
// Let's add a percentage bar
printer.with_info(PercentBar {
title: "Example Stats".to_string(),
total: 100.0,
items: vec![
// title, value, percentage
("foo".to_string(), 50.0, 1.0),
("bar".to_string(), 25.0, 0.25),
("baz".to_string(), 13.0, 0.13),
],
colors: vec![
DynColors::Ansi(Green),
DynColors::Ansi(Yellow),
DynColors::Ansi(Red),
],
width: DEFAULT_BAR_WIDTH,
});
// Add our custom info
printer.with_info(ExampleInfo::new());
// Add a color bar
printer.with_info(ColorBar::default());
// Render the output!
printer.render()
}
Modules
- A collection of structs implementing
Render
Structs
- Generic system fetch printer accepting a distro or image, some configuration, and
Render
-able info
Enums
- The big list of distros! Provides ascii art and colors for each, and a way to search for a match
Traits
- Trait for types be added to the
Printer
.
Derive Macros
- Derive a Render implementation for a struct.