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 - [ ] Fix [wm.rs](src/helpers/wm.rs) to match fastfetch
- [ ] Get rid of sysinfo crate entirely use native methods
- [ ] Get rid of unsafe 😭 - [ ] Get rid of unsafe 😭

View File

@@ -75,7 +75,7 @@ pub fn get_battery_info() -> String {
status.push_str("Discharging"); 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 !external_connected && !is_charging {
if let Some(time_mins) = avg_time_to_empty { if let Some(time_mins) = avg_time_to_empty {

View File

@@ -23,7 +23,7 @@ pub fn get_display_info() -> String {
}; };
format!( 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 name, p_width, p_height, main.scale_factor as u32, inches, main.frequency as u32, tag
) )
} else { } else {

View File

@@ -73,7 +73,7 @@ pub fn get_memory_info() -> String {
}; };
format!( format!(
"{:.2} GiB / {:.2} GiB ({:.0}%)", "{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, percentage 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 read_only = (fs.f_flags & MNT_RDONLY) != 0;
let mut result = format!( let mut result = format!(
"{:.2} GiB / {:.2} GiB ({:.0}%)", "{:.2} GiB / {:.2} GiB ({})",
used_gib, total_gib, percentage used_gib, total_gib, crate::output::colors::percent(percentage)
); );
if !filesystem.is_empty() { if !filesystem.is_empty() {

View File

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

View File

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