Expand description
§lib.rs - Core Library for rgrc
This module provides the core functionality of rgrc (Rust GRC), a colorization tool that applies syntax highlighting to command output based on configuration rules.
§Architecture
The library is organized into the following components:
- ColorMode: Controls whether color output is enabled (On/Off/Auto)
- Configuration Loading: Functions to load colorization rules from config files
- Submodules:
style: Lightweight ANSI styling (replaces console crate)colorizer: Text colorization enginegrc: Config file parsing with hybrid regex engineenhanced_regex: Custom lookaround implementation (used when fancy feature is disabled)
§Features
- embed-configs (default): Embed configuration files into binary
- fancy-regex (default): Use battle-tested fancy-regex for enhanced patterns
- Disable for smaller binary:
cargo build --no-default-features --features=embed-configs
- Disable for smaller binary:
- timetrace: Enable timing trace for performance profiling
§Regex Engine
rgrc uses a hybrid regex approach:
- Simple patterns → Standard
regexcrate (fast) - Complex patterns →
fancy-regex(default) orEnhancedRegex(lightweight)
See grc::CompiledRegex documentation for details.
§Usage Example
ⓘ
use rgrc::{ColorMode, load_config, load_grcat_config};
// Determine if colors should be used
let color_mode = ColorMode::Auto;
// Load colorization rules for a specific command
let rules = load_config("~/.config/rgrc/grc.conf", "ping");Re-exports§
pub use style::Style;
Modules§
- args
- args.rs - Command-line argument parsing for rgrc
- buffer
- buffer.rs - Buffered writers for rgrc
- colorizer
- colorizer.rs - Text Colorization Engine for rgrc
- enhanced_
regex - Enhanced Regex Implementation - Lightweight Lookaround Support
- grc
- grc.rs - Configuration Parsing for Colorization Rules
- style
- Lightweight ANSI style implementation
- utils
- utils.rs - Utility functions for rgrc
Enums§
- Color
Mode - Control whether colored output should be enabled for this run.
Constants§
- EMBEDDED_
CONFIGS - Embedded configuration files compiled into the binary when the
embed-configsfeature is enabled. Each entry is a tuple of(filename, contents)corresponding to files undershare/conf.*. This file is generated by build.rs — do not edit. - EMBEDDED_
CONFIG_ NAMES - Names of the embedded config files (sorted)
- EMBEDDED_
GRC_ CONF - The bundled
rgrc.confcontents whenembed-configsis enabled. This mirrors the on-disketc/rgrc.conffile and is empty when embedding is disabled. - RESOURCE_
PATHS - Standard resource paths searched for grcat config files.
Functions§
- flush_
and_ rebuild_ cache - Flush and rebuild the cache directory (embed-configs only)
- load_
config - Load colorization rules for a given command from a grc.conf-style configuration file.
- load_
grcat_ config - Load colorization rules from a grcat.conf-style configuration file.
- load_
rules_ for_ command - Load colorization rules for a given pseudo-command by searching all configuration paths.