lib: switch to braille NixOS logo, split CPU into name + cores

This commit is contained in:
Amaan Qureshi 2026-04-11 03:57:40 -04:00
commit a41511a3b4
No known key found for this signature in database

View file

@ -2,6 +2,7 @@
extern crate alloc; extern crate alloc;
pub mod colors; pub mod colors;
pub mod cpu;
pub mod desktop; pub mod desktop;
pub mod release; pub mod release;
pub mod system; pub mod system;
@ -23,6 +24,7 @@ pub use microfetch_asm::{
sys_close, sys_close,
sys_open, sys_open,
sys_read, sys_read,
sys_sched_getaffinity,
sys_statfs, sys_statfs,
sys_sysinfo, sys_sysinfo,
sys_uname, sys_uname,
@ -281,6 +283,8 @@ struct Fields {
user_info: String, user_info: String,
os_name: String, os_name: String,
kernel_version: String, kernel_version: String,
cpu_name: String,
cpu_cores: String,
shell: String, shell: String,
uptime: String, uptime: String,
desktop: String, desktop: String,
@ -320,7 +324,7 @@ impl core::fmt::Write for StackWriter<'_> {
} }
/// Custom logo art embedded at compile time via the `MICROFETCH_LOGO` /// Custom logo art embedded at compile time via the `MICROFETCH_LOGO`
/// environment variable. Set it to 9 newline-separated lines of ASCII/Unicode /// environment variable. Set it to 11 newline-separated lines of ASCII/Unicode
/// art when building to replace the default NixOS logo: /// art when building to replace the default NixOS logo:
/// ///
/// `MICROFETCH_LOGO="$(cat my_logo.txt)"` cargo build --release /// `MICROFETCH_LOGO="$(cat my_logo.txt)"` cargo build --release
@ -338,6 +342,8 @@ fn print_system_info(fields: &Fields) -> Result<(), Error> {
user_info, user_info,
os_name, os_name,
kernel_version, kernel_version,
cpu_name,
cpu_cores,
shell, shell,
uptime, uptime,
desktop, desktop,
@ -349,7 +355,7 @@ fn print_system_info(fields: &Fields) -> Result<(), Error> {
let no_color = colors::is_no_color(); let no_color = colors::is_no_color();
let c = colors::Colors::new(no_color); let c = colors::Colors::new(no_color);
let mut buf = [0u8; 2048]; let mut buf = [0u8; 2560];
let mut w = StackWriter::new(&mut buf); let mut w = StackWriter::new(&mut buf);
if CUSTOM_LOGO.is_empty() { if CUSTOM_LOGO.is_empty() {
@ -357,24 +363,25 @@ fn print_system_info(fields: &Fields) -> Result<(), Error> {
core::fmt::write( core::fmt::write(
&mut w, &mut w,
format_args!( format_args!(
"\n {b} ▟█▖ {cy}▝█▙ ▗█▛ {user_info} ~{rs}\n {b} \ "\n {b}⠀⠀⠀⠀⠀⠀⢼⣿⣄⠀⠀⠀{cy}⠹⣿⣷⡀⠀⣠⣿⡧⠀⠀⠀⠀⠀⠀{rs} {user_info} ~{rs}\
{cy} {b} {cy}\u{F313} {b}System{rs} \ \n {b}{cy}{rs} {cy}\u{F313} {b}System{rs} {os_name}\
{os_name}\n {b} {cy} {b} {cy}\u{E712} \ \n {b}{cy}{b}{rs} {cy}\u{E712} {b}Kernel{rs} {kernel_version}\
{b}Kernel{rs} {kernel_version}\n {cy} \ \n {b}{cy}{b}{cy}{b}{rs} {cy}\u{F2DB} {b}CPU{rs} {cpu_name}\
{cy}{b} {cy}\u{E795} {b}Shell{rs} {shell}\n \ \n {cy}{b}{rs} {cy}\u{F4BC} {b}Topology{rs} {cpu_cores}\
{cy} {b} {cy}\u{F017} {b}Uptime{rs} \ \n {cy}{b}{rs} {cy}\u{E795} {b}Shell{rs} {shell}\
{uptime}\n {cy} {b} {b} {cy}\u{F2D2} \ \n {cy}{b}{rs} {cy}\u{F017} {b}Uptime{rs} {uptime}\
{b}Desktop{rs} {desktop}\n {cy} \ \n {cy}{b}{cy}{b}{cy}{rs} {cy}\u{F2D2} {b}Desktop{rs} {desktop}\
{b}{cy} {cy}\u{F035B} {b}Memory{rs} \ \n {cy}{b}{cy}{rs} {cy}\u{F035B} {b}Memory{rs} {memory_usage}\
{memory_usage}\n {cy} {b}{cy} \ \n {b}{cy}{rs} {cy}\u{F194E} {b}Storage (/){rs} {storage}\
{cy}\u{F194E} {b}Storage (/){rs} {storage}\n {b} \ \n {b}{cy}{rs} {cy}\u{E22B} {b}Colors{rs} {colors}\n\n",
{cy} {cy}\u{E22B} {b}Colors{rs} {colors}\n\n",
b = c.blue, b = c.blue,
cy = c.cyan, cy = c.cyan,
rs = c.reset, rs = c.reset,
user_info = user_info, user_info = user_info,
os_name = os_name, os_name = os_name,
kernel_version = kernel_version, kernel_version = kernel_version,
cpu_name = cpu_name,
cpu_cores = cpu_cores,
shell = shell, shell = shell,
uptime = uptime, uptime = uptime,
desktop = desktop, desktop = desktop,
@ -385,14 +392,14 @@ fn print_system_info(fields: &Fields) -> Result<(), Error> {
) )
.ok(); .ok();
} else { } else {
// Custom logo is 9 lines from MICROFETCH_LOGO env var, one per info row. // Custom logo is 11 lines from MICROFETCH_LOGO env var, one per info row.
// Lines beyond 9 are ignored; missing lines render as empty. // Lines beyond 11 are ignored; missing lines render as empty.
let mut lines = CUSTOM_LOGO.split('\n'); let mut lines = CUSTOM_LOGO.split('\n');
let logo_rows: [&str; 9] = let logo_rows: [&str; 11] =
core::array::from_fn(|_| lines.next().unwrap_or("")); core::array::from_fn(|_| lines.next().unwrap_or(""));
// Row format mirrors the default logo path exactly. // Row format mirrors the default logo path exactly.
let rows: [(&str, &str, &str, &str, &str); 9] = [ let rows: [(&str, &str, &str, &str, &str); 11] = [
("", "", user_info.as_str(), " ", " ~"), ("", "", user_info.as_str(), " ", " ~"),
("\u{F313} ", "System", os_name.as_str(), " ", ""), ("\u{F313} ", "System", os_name.as_str(), " ", ""),
( (
@ -402,6 +409,8 @@ fn print_system_info(fields: &Fields) -> Result<(), Error> {
" ", " ",
"", "",
), ),
("\u{F2DB} ", "CPU", cpu_name.as_str(), " ", ""),
("\u{F4BC} ", "Topology", cpu_cores.as_str(), " ", ""),
("\u{E795} ", "Shell", shell.as_str(), " ", ""), ("\u{E795} ", "Shell", shell.as_str(), " ", ""),
("\u{F017} ", "Uptime", uptime.as_str(), " ", ""), ("\u{F017} ", "Uptime", uptime.as_str(), " ", ""),
("\u{F2D2} ", "Desktop", desktop.as_str(), " ", ""), ("\u{F2D2} ", "Desktop", desktop.as_str(), " ", ""),
@ -417,7 +426,7 @@ fn print_system_info(fields: &Fields) -> Result<(), Error> {
]; ];
core::fmt::write(&mut w, format_args!("\n")).ok(); core::fmt::write(&mut w, format_args!("\n")).ok();
for i in 0..9 { for i in 0..11 {
let (icon, key, value, spacing, suffix) = rows[i]; let (icon, key, value, spacing, suffix) = rows[i];
if key.is_empty() { if key.is_empty() {
// Row 1 has no icon/key, just logo + user_info // Row 1 has no icon/key, just logo + user_info
@ -534,6 +543,8 @@ pub unsafe fn run(argc: i32, argv: *const *const u8) -> Result<(), Error> {
user_info: system::get_username_and_hostname(&utsname), user_info: system::get_username_and_hostname(&utsname),
os_name: release::get_os_pretty_name()?, os_name: release::get_os_pretty_name()?,
kernel_version: release::get_system_info(&utsname), kernel_version: release::get_system_info(&utsname),
cpu_name: cpu::get_cpu_name(),
cpu_cores: cpu::get_cpu_cores()?,
shell: system::get_shell(), shell: system::get_shell(),
desktop: desktop::get_desktop_info(), desktop: desktop::get_desktop_info(),
uptime: uptime::get_current()?, uptime: uptime::get_current()?,