plotnik_lib/colors.rs
1//! ANSI color codes for terminal output.
2//!
3//! Four semantic colors with orthogonal dim modifier:
4//! - Blue: Definition names, keys, type names
5//! - Green: String literals, terminal markers
6//! - Dim: Structure, nav, effects, metadata
7//! - Reset: Return to default
8
9/// ANSI color palette for CLI output.
10///
11/// Designed for jq-inspired colorization that works in both light and dark themes.
12/// Uses only standard 16-color ANSI codes (no RGB).
13#[derive(Clone, Copy, Debug)]
14pub struct Colors {
15 pub blue: &'static str,
16 pub green: &'static str,
17 pub dim: &'static str,
18 pub reset: &'static str,
19}
20
21impl Default for Colors {
22 fn default() -> Self {
23 Self::OFF
24 }
25}
26
27impl Colors {
28 /// Colors enabled (ANSI escape codes).
29 pub const ON: Self = Self {
30 blue: "\x1b[34m",
31 green: "\x1b[32m",
32 dim: "\x1b[2m",
33 reset: "\x1b[0m",
34 };
35
36 /// Colors disabled (empty strings).
37 pub const OFF: Self = Self {
38 blue: "",
39 green: "",
40 dim: "",
41 reset: "",
42 };
43
44 /// Create colors based on enabled flag.
45 pub fn new(enabled: bool) -> Self {
46 if enabled { Self::ON } else { Self::OFF }
47 }
48
49 /// Check if colors are enabled.
50 pub fn is_enabled(&self) -> bool {
51 !self.blue.is_empty()
52 }
53}