Skip to content
Merged
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
57 changes: 57 additions & 0 deletions crates/plotnik-lib/src/colors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! ANSI color codes for terminal output.
//!
//! Four semantic colors with orthogonal dim modifier:
//! - Blue: Definition names, keys, type names
//! - Green: String literals, terminal markers
//! - Dim: Structure, nav, effects, metadata
//! - Reset: Return to default

/// ANSI color palette for CLI output.
///
/// Designed for jq-inspired colorization that works in both light and dark themes.
/// Uses only standard 16-color ANSI codes (no RGB).
#[derive(Clone, Copy, Debug)]
pub struct Colors {
pub blue: &'static str,
pub green: &'static str,
pub dim: &'static str,
pub reset: &'static str,
}

impl Default for Colors {
fn default() -> Self {
Self::OFF
}
}

impl Colors {
/// Colors enabled (ANSI escape codes).
pub const ON: Self = Self {
blue: "\x1b[34m",
green: "\x1b[32m",
dim: "\x1b[2m",
reset: "\x1b[0m",
};

/// Colors disabled (empty strings).
pub const OFF: Self = Self {
blue: "",
green: "",
dim: "",
reset: "",
};

/// Create colors based on enabled flag.
pub fn new(enabled: bool) -> Self {
if enabled {
Self::ON
} else {
Self::OFF
}
}

/// Check if colors are enabled.
pub fn is_enabled(&self) -> bool {
!self.blue.is_empty()
}
}
2 changes: 2 additions & 0 deletions crates/plotnik-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

pub mod analyze;
pub mod bytecode;
pub mod colors;
pub mod compile;
pub mod diagnostics;
pub mod emit;
Expand All @@ -32,6 +33,7 @@ pub mod typegen;
/// Fatal errors (like fuel exhaustion) use the outer `Result`.
pub type PassResult<T> = std::result::Result<(T, Diagnostics), Error>;

pub use colors::Colors;
pub use diagnostics::{Diagnostics, DiagnosticsPrinter, Severity, Span};
pub use query::{Query, QueryBuilder};
pub use query::{SourceId, SourceMap};
Expand Down