feat: colors

This commit is contained in:
neoarz
2026-01-07 15:20:48 -05:00
parent 20868595a8
commit 0f84471a9f
9 changed files with 109 additions and 40 deletions

View File

@@ -4,7 +4,5 @@
- [ ] Fix [wm.rs](src/helpers/wm.rs) to match fastfetch
- [ ] Get rid of sysinfo crate entirely use native methods
- [ ] Get rid of unsafe 😭

View File

@@ -75,7 +75,7 @@ pub fn get_battery_info() -> String {
status.push_str("Discharging");
}
let mut result = format!("({}) {}%", device_name, percentage);
let mut result = format!("({}) {}", device_name, crate::output::colors::battery_percent(percentage));
if !external_connected && !is_charging {
if let Some(time_mins) = avg_time_to_empty {

View File

@@ -23,7 +23,7 @@ pub fn get_display_info() -> String {
};
format!(
"Display ({}): {}x{} @ {}x in {}\", {} Hz {}",
"({}): {}x{} @ {}x in {}\", {} Hz {}",
name, p_width, p_height, main.scale_factor as u32, inches, main.frequency as u32, tag
)
} else {

View File

@@ -73,7 +73,7 @@ pub fn get_memory_info() -> String {
};
format!(
"{:.2} GiB / {:.2} GiB ({:.0}%)",
used_gib, total_gib, percentage
"{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, crate::output::colors::percent(percentage)
)
}

View File

@@ -78,8 +78,8 @@ pub fn get_storage_info() -> String {
let read_only = (fs.f_flags & MNT_RDONLY) != 0;
let mut result = format!(
"{:.2} GiB / {:.2} GiB ({:.0}%)",
used_gib, total_gib, percentage
"{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, crate::output::colors::percent(percentage)
);
if !filesystem.is_empty() {

View File

@@ -32,8 +32,8 @@ pub fn get_swap_info() -> String {
};
return format!(
"{:.2} GiB / {:.2} GiB ({:.0}%)",
used_gib, total_gib, percentage
"{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, crate::output::colors::percent(percentage)
);
}

View File

@@ -1,10 +1,13 @@
// neoarz
// neo64fetch - "jarvis, rewrite this project in rust"
// use colored::*;
use std::env;
use sysinfo::System;
mod helpers;
mod output;
use output::colors;
struct Stats {
// Neoarz[at]Mac
@@ -72,33 +75,37 @@ fn main() {
locale: helpers::locale::get_locale_info(),
};
// TODO: Add ascii art support later
// Testing each component separately; going to comment out at the end
{
println!("{}", stats.username);
println!("{}", stats.hostname);
println!("{}", stats.os);
println!("{}", stats.host);
println!("{}", stats.architecture);
println!("{}", stats.kernel);
println!("{}", stats.uptime);
println!("{}", stats.packages);
println!("{}", stats.shell);
println!("{}", stats.display);
println!("{}", stats.desktop_env);
println!("{}", stats.window_manager);
println!("{}", stats.window_manager_theme);
println!("{}", stats.font);
println!("{}", stats.cursor);
println!("{}", stats.terminal);
println!("{}", stats.terminal_font);
println!("{}", stats.cpu);
println!("{}", stats.gpu);
println!("{}", stats.memory);
println!("{}", stats.swap);
println!("{}", stats.storage);
println!("{}", stats.ip);
println!("{}", stats.battery);
println!("{}", stats.locale);
}
// user@host
println!("{}", colors::title(&stats.username, &stats.hostname));
// separator
println!("{}", colors::separator(stats.username.len() + stats.hostname.len() + 1));
// info
println!("{}", colors::info("OS", &format!("{} {}", stats.os, stats.architecture)));
println!("{}", colors::info("Host", &stats.host));
println!("{}", colors::info("Kernel", &stats.kernel));
println!("{}", colors::info("Uptime", &stats.uptime));
println!("{}", colors::info("Packages", &stats.packages));
println!("{}", colors::info("Shell", &stats.shell));
println!("{}", colors::info("Display", &stats.display));
println!("{}", colors::info("DE", &stats.desktop_env));
println!("{}", colors::info("WM", &stats.window_manager));
println!("{}", colors::info("WM Theme", &stats.window_manager_theme));
println!("{}", colors::info("Font", &stats.font));
println!("{}", colors::info("Cursor", &stats.cursor));
println!("{}", colors::info("Terminal", &stats.terminal));
println!("{}", colors::info("Terminal Font", &stats.terminal_font));
println!("{}", colors::info("CPU", &stats.cpu));
println!("{}", colors::info("GPU", &stats.gpu));
println!("{}", colors::info("Memory", &stats.memory));
println!("{}", colors::info("Swap", &stats.swap));
println!("{}", colors::info("Disk (/)", &stats.storage));
println!("{}", colors::info("Local IP", &stats.ip));
println!("{}", colors::info("Battery", &stats.battery));
println!("{}", colors::info("Locale", &stats.locale));
// color blocks
println!();
println!("{}", colors::color_blocks());
}

63
src/output/colors.rs Normal file
View File

@@ -0,0 +1,63 @@
use colored::Colorize;
// title
pub fn title(user: &str, host: &str) -> String {
format!("{}@{}", user.cyan().bold(), host.cyan().bold())
}
// separator
pub fn separator(len: usize) -> String {
"-".repeat(len)
}
// percent (for colors based on usage level)
pub fn percent(value: f64) -> String {
let text = format!("{}%", value as u32);
if value > 80.0 {
text.red().to_string()
} else if value > 50.0 {
text.yellow().to_string()
} else {
text.green().to_string()
}
}
// battery is different because its inverted (low is bad)
pub fn battery_percent(value: u32) -> String {
let text = format!("{}%", value);
if value < 20 {
text.red().to_string()
} else if value < 50 {
text.yellow().to_string()
} else {
text.green().to_string()
}
}
// info
pub fn info(key: &str, value: &str) -> String {
format!("{}: {}", key.yellow().bold(), value)
}
// color blocks
pub fn color_blocks() -> String {
let normal = " ".on_black().to_string()
+ &" ".on_red().to_string()
+ &" ".on_green().to_string()
+ &" ".on_yellow().to_string()
+ &" ".on_blue().to_string()
+ &" ".on_magenta().to_string()
+ &" ".on_cyan().to_string()
+ &" ".on_white().to_string();
let bright = " ".on_bright_black().to_string()
+ &" ".on_bright_red().to_string()
+ &" ".on_bright_green().to_string()
+ &" ".on_bright_yellow().to_string()
+ &" ".on_bright_blue().to_string()
+ &" ".on_bright_magenta().to_string()
+ &" ".on_bright_cyan().to_string()
+ &" ".on_bright_white().to_string();
format!("{}\n{}", normal, bright)
}

1
src/output/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod colors;