#![allow(dead_code)]
use presentar_core::Color;
pub const CPU_COLOR: Color = Color {
r: 0.392,
g: 0.784,
b: 1.0,
a: 1.0,
};
pub const MEMORY_COLOR: Color = Color {
r: 0.706,
g: 0.471,
b: 1.0,
a: 1.0,
};
pub const DISK_COLOR: Color = Color {
r: 0.392,
g: 0.706,
b: 1.0,
a: 1.0,
};
pub const NETWORK_COLOR: Color = Color {
r: 1.0,
g: 0.588,
b: 0.392,
a: 1.0,
};
pub const PROCESS_COLOR: Color = Color {
r: 0.863,
g: 0.706,
b: 0.392,
a: 1.0,
};
pub const GPU_COLOR: Color = Color {
r: 0.392,
g: 1.0,
b: 0.588,
a: 1.0,
};
pub const BATTERY_COLOR: Color = Color {
r: 1.0,
g: 0.863,
b: 0.392,
a: 1.0,
};
pub const SENSORS_COLOR: Color = Color {
r: 1.0,
g: 0.392,
b: 0.588,
a: 1.0,
};
pub const PSI_COLOR: Color = Color {
r: 0.784,
g: 0.314,
b: 0.314,
a: 1.0,
};
pub const CONNECTIONS_COLOR: Color = Color {
r: 0.471,
g: 0.706,
b: 0.863,
a: 1.0,
};
pub const FILES_COLOR: Color = Color {
r: 0.706,
g: 0.549,
b: 0.392,
a: 1.0,
};
pub const CONTAINERS_COLOR: Color = Color {
r: 0.392,
g: 0.706,
b: 0.863,
a: 1.0,
};
pub const NET_RX_COLOR: Color = Color {
r: 0.0,
g: 0.8,
b: 0.4,
a: 1.0,
};
pub const NET_TX_COLOR: Color = Color {
r: 0.8,
g: 0.4,
b: 0.8,
a: 1.0,
};
pub const DISK_READ_COLOR: Color = Color {
r: 0.0,
g: 0.8,
b: 0.8,
a: 1.0,
};
pub const DISK_WRITE_COLOR: Color = Color {
r: 1.0,
g: 0.6,
b: 0.2,
a: 1.0,
};
pub const WHITE: Color = Color {
r: 1.0,
g: 1.0,
b: 1.0,
a: 1.0,
};
pub const GRAY: Color = Color {
r: 0.5,
g: 0.5,
b: 0.5,
a: 1.0,
};
pub const DARK_GRAY: Color = Color {
r: 0.2,
g: 0.2,
b: 0.2,
a: 1.0,
};
pub const BLACK: Color = Color {
r: 0.0,
g: 0.0,
b: 0.0,
a: 1.0,
};
pub const GREEN: Color = Color {
r: 0.0,
g: 0.8,
b: 0.0,
a: 1.0,
};
pub const YELLOW: Color = Color {
r: 1.0,
g: 0.8,
b: 0.0,
a: 1.0,
};
pub const RED: Color = Color {
r: 1.0,
g: 0.2,
b: 0.2,
a: 1.0,
};
pub const CYAN: Color = Color {
r: 0.0,
g: 0.8,
b: 0.8,
a: 1.0,
};
pub const MAGENTA: Color = Color {
r: 0.8,
g: 0.4,
b: 0.8,
a: 1.0,
};
pub const SELECTION_BG: Color = Color {
r: 0.2,
g: 0.3,
b: 0.5,
a: 1.0,
};
pub const HEADER_BG: Color = Color {
r: 0.15,
g: 0.15,
b: 0.2,
a: 1.0,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_cpu_color_matches_ttop() {
assert!((CPU_COLOR.r - 0.392).abs() < 0.001);
assert!((CPU_COLOR.g - 0.784).abs() < 0.001);
assert!((CPU_COLOR.b - 1.0).abs() < 0.001);
}
#[test]
fn test_memory_color_matches_ttop() {
assert!((MEMORY_COLOR.r - 0.706).abs() < 0.001);
assert!((MEMORY_COLOR.g - 0.471).abs() < 0.001);
assert!((MEMORY_COLOR.b - 1.0).abs() < 0.001);
}
#[test]
fn test_all_panel_colors_full_alpha() {
let colors = [
CPU_COLOR,
MEMORY_COLOR,
DISK_COLOR,
NETWORK_COLOR,
PROCESS_COLOR,
GPU_COLOR,
BATTERY_COLOR,
SENSORS_COLOR,
PSI_COLOR,
CONNECTIONS_COLOR,
FILES_COLOR,
CONTAINERS_COLOR,
];
for color in colors {
assert!(
(color.a - 1.0).abs() < 0.001,
"Panel color must have full alpha"
);
}
}
#[test]
fn test_network_colors_distinct() {
assert!(
(NET_RX_COLOR.r - NET_TX_COLOR.r).abs() > 0.1
|| (NET_RX_COLOR.g - NET_TX_COLOR.g).abs() > 0.1
|| (NET_RX_COLOR.b - NET_TX_COLOR.b).abs() > 0.1,
"RX and TX colors must be visually distinct"
);
}
#[test]
fn test_disk_colors_distinct() {
assert!(
(DISK_READ_COLOR.r - DISK_WRITE_COLOR.r).abs() > 0.1
|| (DISK_READ_COLOR.g - DISK_WRITE_COLOR.g).abs() > 0.1
|| (DISK_READ_COLOR.b - DISK_WRITE_COLOR.b).abs() > 0.1,
"Read and Write colors must be visually distinct"
);
}
#[test]
fn test_status_colors_traffic_light() {
assert!(GREEN.g > GREEN.r && GREEN.g > GREEN.b);
assert!(YELLOW.r > 0.5 && YELLOW.g > 0.5 && YELLOW.b < 0.5);
assert!(RED.r > RED.g && RED.r > RED.b);
}
#[test]
fn test_white_is_white() {
assert!((WHITE.r - 1.0).abs() < 0.001);
assert!((WHITE.g - 1.0).abs() < 0.001);
assert!((WHITE.b - 1.0).abs() < 0.001);
}
#[test]
fn test_black_is_black() {
assert!(BLACK.r.abs() < 0.001);
assert!(BLACK.g.abs() < 0.001);
assert!(BLACK.b.abs() < 0.001);
}
#[test]
fn test_gray_is_balanced() {
assert!((GRAY.r - GRAY.g).abs() < 0.001);
assert!((GRAY.g - GRAY.b).abs() < 0.001);
}
#[test]
fn test_selection_bg_distinguishable() {
let avg = (SELECTION_BG.r + SELECTION_BG.g + SELECTION_BG.b) / 3.0;
assert!(avg > 0.1 && avg < 0.9, "Selection BG should be mid-tone");
}
#[test]
fn test_cpu_color_hex() {
let r = (CPU_COLOR.r * 255.0).round() as u8;
let g = (CPU_COLOR.g * 255.0).round() as u8;
let b = (CPU_COLOR.b * 255.0).round() as u8;
assert_eq!(r, 100);
assert_eq!(g, 200);
assert_eq!(b, 255);
}
#[test]
fn test_memory_color_hex() {
let r = (MEMORY_COLOR.r * 255.0).round() as u8;
let g = (MEMORY_COLOR.g * 255.0).round() as u8;
let b = (MEMORY_COLOR.b * 255.0).round() as u8;
assert_eq!(r, 180);
assert_eq!(g, 120);
assert_eq!(b, 255);
}
#[test]
fn test_process_color_hex() {
let r = (PROCESS_COLOR.r * 255.0).round() as u8;
let g = (PROCESS_COLOR.g * 255.0).round() as u8;
let b = (PROCESS_COLOR.b * 255.0).round() as u8;
assert_eq!(r, 220);
assert_eq!(g, 180);
assert_eq!(b, 100);
}
#[test]
fn test_gpu_color_hex() {
let r = (GPU_COLOR.r * 255.0).round() as u8;
let g = (GPU_COLOR.g * 255.0).round() as u8;
let b = (GPU_COLOR.b * 255.0).round() as u8;
assert_eq!(r, 100);
assert_eq!(g, 255);
assert_eq!(b, 150);
}
#[test]
fn test_network_color_hex() {
let r = (NETWORK_COLOR.r * 255.0).round() as u8;
let g = (NETWORK_COLOR.g * 255.0).round() as u8;
let b = (NETWORK_COLOR.b * 255.0).round() as u8;
assert_eq!(r, 255);
assert_eq!(g, 150);
assert_eq!(b, 100);
}
#[test]
fn test_all_colors_valid() {
let colors = [
CPU_COLOR,
MEMORY_COLOR,
DISK_COLOR,
NETWORK_COLOR,
PROCESS_COLOR,
GPU_COLOR,
BATTERY_COLOR,
SENSORS_COLOR,
PSI_COLOR,
CONNECTIONS_COLOR,
FILES_COLOR,
CONTAINERS_COLOR,
NET_RX_COLOR,
NET_TX_COLOR,
DISK_READ_COLOR,
DISK_WRITE_COLOR,
WHITE,
GRAY,
DARK_GRAY,
BLACK,
GREEN,
YELLOW,
RED,
CYAN,
MAGENTA,
SELECTION_BG,
HEADER_BG,
];
for color in colors {
assert!(!color.r.is_nan() && !color.r.is_infinite());
assert!(!color.g.is_nan() && !color.g.is_infinite());
assert!(!color.b.is_nan() && !color.b.is_infinite());
assert!(!color.a.is_nan() && !color.a.is_infinite());
}
}
#[test]
fn test_all_colors_in_range() {
let colors = [
CPU_COLOR,
MEMORY_COLOR,
DISK_COLOR,
NETWORK_COLOR,
PROCESS_COLOR,
GPU_COLOR,
BATTERY_COLOR,
SENSORS_COLOR,
PSI_COLOR,
CONNECTIONS_COLOR,
FILES_COLOR,
CONTAINERS_COLOR,
];
for color in colors {
assert!(color.r >= 0.0 && color.r <= 1.0);
assert!(color.g >= 0.0 && color.g <= 1.0);
assert!(color.b >= 0.0 && color.b <= 1.0);
assert!(color.a >= 0.0 && color.a <= 1.0);
}
}
#[test]
fn test_panel_colors_distinguishable() {
let colors = [
("CPU", CPU_COLOR),
("Memory", MEMORY_COLOR),
("Network", NETWORK_COLOR),
("Process", PROCESS_COLOR),
("GPU", GPU_COLOR),
];
for i in 0..colors.len() {
for j in (i + 1)..colors.len() {
let (name1, c1) = colors[i];
let (name2, c2) = colors[j];
let diff = (c1.r - c2.r).abs() + (c1.g - c2.g).abs() + (c1.b - c2.b).abs();
assert!(
diff > 0.15,
"{} and {} colors should be distinguishable (diff={})",
name1,
name2,
diff
);
}
}
}
#[test]
fn test_cyan_is_cyan() {
assert!(CYAN.g > 0.5 && CYAN.b > 0.5);
assert!(CYAN.r < CYAN.g && CYAN.r < CYAN.b);
}
#[test]
fn test_magenta_is_magenta() {
assert!(MAGENTA.r > 0.5 && MAGENTA.b > 0.5);
}
}