Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions crates/lib/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
use std::{env, fs, path::Path};

fn main() {
let mut constants: Vec<String> = Vec::new();

constants.push(format!(
"pub const COLOR_LOGO1: &'static str = \"{}\";",
match env::var("COLOR_LOGO1") {
Ok(color) => {
let r =
u32::from_str_radix(&color[1..3], 16).expect("Invalid COLOR_LOGO1");
let g =
u32::from_str_radix(&color[3..5], 16).expect("Invalid COLOR_LOGO1");
let b =
u32::from_str_radix(&color[5..7], 16).expect("Invalid COLOR_LOGO1");
format!("\\x1b[38;2;{r};{g};{b};m")
},
Err(_) => "\x1b[34m".to_string(),
}
));

constants.push(format!(
"pub const COLOR_LOGO2: &'static str = \"{}\";",
match env::var("COLOR_LOGO2") {
Ok(color) => {
let r =
u32::from_str_radix(&color[1..3], 16).expect("Invalid COLOR_LOGO2");
let g =
u32::from_str_radix(&color[3..5], 16).expect("Invalid COLOR_LOGO2");
let b =
u32::from_str_radix(&color[5..7], 16).expect("Invalid COLOR_LOGO2");
format!("\\x1b[38;2;{r};{g};{b};m")
},
Err(_) => "\x1b[36m".to_string(),
}
));

constants.push(format!(
"pub const COLOR_ICON: &'static str = \"{}\";",
match env::var("COLOR_ICON") {
Ok(color) => {
let r =
u32::from_str_radix(&color[1..3], 16).expect("Invalid COLOR_ICON");
let g =
u32::from_str_radix(&color[3..5], 16).expect("Invalid COLOR_ICON");
let b =
u32::from_str_radix(&color[5..7], 16).expect("Invalid COLOR_ICON");
format!("\\x1b[38;2;{r};{g};{b};m")
},
Err(_) => "\x1b[36m".to_string(),
}
));

constants.push(format!(
"pub const COLOR_KEY: &'static str = \"{}\";",
match env::var("COLOR_KEY") {
Ok(color) => {
let r =
u32::from_str_radix(&color[1..3], 16).expect("Invalid COLOR_KEY");
let g =
u32::from_str_radix(&color[3..5], 16).expect("Invalid COLOR_KEY");
let b =
u32::from_str_radix(&color[5..7], 16).expect("Invalid COLOR_KEY");
format!("\\x1b[38;2;{r};{g};{b};m")
},
Err(_) => "\x1b[34m".to_string(),
}
));

let val = match env::var("COLOR_VALUE") {
Ok(color) => {
let r =
u32::from_str_radix(&color[1..3], 16).expect("Invalid COLOR_VALUE");
let g =
u32::from_str_radix(&color[3..5], 16).expect("Invalid COLOR_VALUE");
let b =
u32::from_str_radix(&color[5..7], 16).expect("Invalid COLOR_VALUE");
format!("\\x1b[38;2;{r};{g};{b};m")
},
Err(_) => "".to_string(),
};
constants.push(format!("pub const COLOR_VAL: &'static str = \"{}\";", val));

let out_dir = env::var("OUT_DIR").unwrap();
let path1 = Path::new(&out_dir).join("colors_config.rs");
let code = constants.join("\n");
fs::write(path1, code).unwrap();
let path2 = Path::new(&out_dir).join("color_helpers.rs");
fs::write(
path2,
format!("pub const RPAREN: &'static str = \"{})\";\n", val),
)
.unwrap();
}
17 changes: 17 additions & 0 deletions crates/lib/src/colors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include!(concat!(env!("OUT_DIR"), "/colors_config.rs"));

use alloc::string::String;

/// Color codes for terminal output
Expand All @@ -9,6 +11,11 @@ pub struct Colors {
pub yellow: &'static str,
pub red: &'static str,
pub magenta: &'static str,
pub l1: &'static str,
pub l2: &'static str,
pub icon: &'static str,
pub key: &'static str,
pub value: &'static str,
}

impl Colors {
Expand All @@ -23,6 +30,11 @@ impl Colors {
yellow: "",
red: "",
magenta: "",
l1: "",
l2: "",
icon: "",
key: "",
value: "",
}
} else {
Self {
Expand All @@ -33,6 +45,11 @@ impl Colors {
yellow: "\x1b[33m",
red: "\x1b[31m",
magenta: "\x1b[35m",
l1: COLOR_LOGO1,
l2: COLOR_LOGO2,
icon: COLOR_ICON,
key: COLOR_KEY,
value: COLOR_VAL,
}
}
}
Expand Down
29 changes: 16 additions & 13 deletions crates/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,19 +363,22 @@ fn print_system_info(fields: &Fields) -> Result<(), Error> {
core::fmt::write(
&mut w,
format_args!(
"\n {b}⠀⠀⠀⠀⠀⠀⢼⣿⣄⠀⠀⠀{cy}⠹⣿⣷⡀⠀⣠⣿⡧⠀⠀⠀⠀⠀⠀{rs} {user_info} ~{rs}\
\n {b}⠀⠀⠀⠀⠀⠀⠈⢿⣿⣆⠀⠀⠀{cy}⠘⣿⣿⣴⣿⡿⠁⠀⠀⠀⠀⠀⠀{rs} {cy}\u{F313} {b}System{rs} \u{E621} {os_name}\
\n {b}⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡜{cy}⢿⣿⣟⠀⠀⠀{b}⢀⡄⠀⠀⠀{rs} {cy}\u{E712} {b}Kernel{rs} \u{E621} {kernel_version}\
\n {b}⠀⠀⠀⠉⠉⠉⠉{cy}⣩⣭⡭{b}⠉⠉⠉⠉⠉{cy}⠈⢿⣿⣆⠀{b}⢠⣿⣿⠂⠀⠀{rs} {cy}\u{F2DB} {b}CPU{rs} \u{E621} {cpu_name}\
\n {cy}⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⢻⡟{b}⣡⣿⣿⠃⠀⠀⠀{rs} {cy}\u{F4BC} {b}Topology{rs} \u{E621} {cpu_cores}\
\n {cy}⢸⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀{b}⣰⣿⣿⣿⣿⣿⣿⡇{rs} {cy}\u{E795} {b}Shell{rs} \u{E621} {shell}\
\n {cy}⠀⠀⠀⢠⣿⣿⢋{b}⣼⣧⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀{rs} {cy}\u{F017} {b}Uptime{rs} \u{E621} {uptime}\
\n {cy}⠀⠀⠠⣿⣿⠃⠀{b}⠹⣿⣷⡀{cy}⣀⣀⣀⣀⣀{b}⣚⣛⣋{cy}⣀⣀⣀⣀⠀⠀⠀{rs} {cy}\u{F2D2} {b}Desktop{rs} \u{E621} {desktop}\
\n {cy}⠀⠀⠀⠘⠁⠀⠀⠀{b}⣽⣿⣷⡜{cy}⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀{rs} {cy}\u{F035B} {b}Memory{rs} \u{E621} {memory_usage}\
\n {b}⠀⠀⠀⠀⠀⠀⢀⣾⣿⠟⣿⣿⡄⠀⠀⠀{cy}⠹⣿⣷⡀⠀⠀⠀⠀⠀⠀{rs} {cy}\u{F194E} {b}Storage (/){rs} \u{E621} {storage}\
\n {b}⠀⠀⠀⠀⠀⠀⢺⣿⠋⠀⠈⢿⣿⣆⠀⠀⠀{cy}⠙⣿⡗⠀⠀⠀⠀⠀⠀{rs} {cy}\u{E22B} {b}Colors{rs} \u{E621} {colors}\n\n",
b = c.blue,
cy = c.cyan,
"\n {l1}⠀⠀⠀⠀⠀⠀⢼⣿⣄⠀⠀⠀{l2}⠹⣿⣷⡀⠀⣠⣿⡧⠀⠀⠀⠀⠀⠀{rs} {user_info} ~{rs}\
\n {l1}⠀⠀⠀⠀⠀⠀⠈⢿⣿⣆⠀⠀⠀{l2}⠘⣿⣿⣴⣿⡿⠁⠀⠀⠀⠀⠀⠀{rs} {icon}\u{F313} {key}System{rs} \u{E621} {val}{os_name}{rs}\
\n {l1}⠀⠀⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⡜{l2}⢿⣿⣟⠀⠀⠀{l1}⢀⡄⠀⠀⠀{rs} {icon}\u{E712} {key}Kernel{rs} \u{E621} {val}{kernel_version}{rs}\
\n {l1}⠀⠀⠀⠉⠉⠉⠉{l2}⣩⣭⡭{l1}⠉⠉⠉⠉⠉{l2}⠈⢿⣿⣆⠀{l1}⢠⣿⣿⠂⠀⠀{rs} {icon}\u{F2DB} {key}CPU{rs} \u{E621} {val}{cpu_name}{rs}\
\n {l2}⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⢻⡟{l1}⣡⣿⣿⠃⠀⠀⠀{rs} {icon}\u{F4BC} {key}Topology{rs} \u{E621} {val}{cpu_cores}{rs}\
\n {l2}⢸⣿⣿⣿⣿⣿⣿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀{l1}⣰⣿⣿⣿⣿⣿⣿⡇{rs} {icon}\u{E795} {key}Shell{rs} \u{E621} {val}{shell}{rs}\
\n {l2}⠀⠀⠀⢠⣿⣿⢋{l1}⣼⣧⠀⠀⠀⠀⠀⠀⠀⠀⣼⣿⡟⠀⠀⠀⠀⠀⠀{rs} {icon}\u{F017} {key}Uptime{rs} \u{E621} {val}{uptime}{rs}\
\n {l2}⠀⠀⠠⣿⣿⠃⠀{l1}⠹⣿⣷⡀{l2}⣀⣀⣀⣀⣀{l1}⣚⣛⣋{l2}⣀⣀⣀⣀⠀⠀⠀{rs} {icon}\u{F2D2} {key}Desktop{rs} \u{E621} {val}{desktop}{rs}\
\n {l2}⠀⠀⠀⠘⠁⠀⠀⠀{l1}⣽⣿⣷⡜{l2}⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀{rs} {icon}\u{F035B} {key}Memory{rs} \u{E621} {val}{memory_usage}{rs}\
\n {l1}⠀⠀⠀⠀⠀⠀⢀⣾⣿⠟⣿⣿⡄⠀⠀⠀{l2}⠹⣿⣷⡀⠀⠀⠀⠀⠀⠀{rs} {icon}\u{F194E} {key}Storage (/){rs} \u{E621} {val}{storage}{rs}\
\n {l1}⠀⠀⠀⠀⠀⠀⢺⣿⠋⠀⠈⢿⣿⣆⠀⠀⠀{l2}⠙⣿⡗⠀⠀⠀⠀⠀⠀{rs} {icon}\u{E22B} {key}Colors{rs} \u{E621} {val}{colors}{rs}\n\n",
l1 = c.l1,
l2 = c.l2,
icon = c.icon,
key = c.key,
val = c.value,
rs = c.reset,
user_info = user_info,
os_name = os_name,
Expand Down
10 changes: 6 additions & 4 deletions crates/lib/src/system.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include!(concat!(env!("OUT_DIR"), "/color_helpers.rs"));

use alloc::string::String;
use core::mem::MaybeUninit;

Expand Down Expand Up @@ -88,11 +90,11 @@ pub fn get_root_disk_usage() -> Result<String, Error> {
result.push_str(" GiB / ");
write_float(&mut result, total_size, 2);
result.push_str(" GiB (");
result.push_str(colors.cyan);
result.push_str(colors.icon);
write_float(&mut result, usage, 0);
result.push('%');
result.push_str(colors.reset);
result.push(')');
result.push_str(RPAREN);

Ok(result)
}
Expand Down Expand Up @@ -258,11 +260,11 @@ pub fn get_memory_usage() -> Result<String, Error> {
result.push_str(" GiB / ");
write_float(&mut result, total_memory, 2);
result.push_str(" GiB (");
result.push_str(colors.cyan);
result.push_str(colors.icon);
write_u64(&mut result, percentage_used);
result.push('%');
result.push_str(colors.reset);
result.push(')');
result.push_str(RPAREN);

Ok(result)
}