Expand description
§Hyprlang-rs
A Rust implementation of the Hyprlang configuration language parser.
Hyprlang is a highly efficient, user-friendly configuration language designed for Linux applications. This crate provides a complete implementation of the Hyprlang specification with idiomatic Rust APIs.
§Features
- Multiple data types: Int, Float, String, Vec2, Color, and custom types
- Variables: User-defined and environment variables with recursive expansion
- Expressions: Mathematical expressions with arithmetic operations
- Nested categories: Hierarchical configuration structure
- Special categories: Key-based, static, and anonymous categories
- Custom handlers: Extensible keyword handlers with flag support
- Comment directives: Conditional parsing and error control
- Multiline values: Line continuation support
- Source directives: Include external configuration files
- Dynamic parsing: Parse and update configuration at runtime
- Mutation & Serialization (optional): Modify config values and save back to files
§Optional Features
§mutation Feature
Enable the mutation feature to unlock configuration modification and serialization capabilities:
[dependencies]
hyprlang = { version = "0.2.1", features = ["mutation"] }This provides:
- Value mutations: [
Config::set_int], [Config::set_float], [Config::set_string], [Config::remove] - Variable mutations:
Config::set_variable, [Config::get_variable_mut], [Config::remove_variable] - Handler mutations: [
Config::add_handler_call], [Config::remove_handler_call] - Category mutations: [
Config::get_special_category_mut], [Config::remove_special_category_instance] - Serialization: [
Config::serialize], [Config::save], [Config::save_as]
See the mutation API documentation on [MutableVariable] and [MutableCategoryInstance] for detailed examples.
§hyprland Feature
The hyprland feature provides a high-level API with pre-configured Hyprland handlers and typed accessors.
See the [Hyprland] struct documentation for details.
§Example
use hyprlang::{Config, ConfigValue};
// Create a new configuration
let mut config = Config::new();
// Parse a configuration string
config.parse(r#"
$SCALE = 2
$WIDTH = 800
window_width = $WIDTH
window_height = 600
scale = $SCALE
total_width = {{WIDTH * SCALE}}
appearance {
color = rgb(255, 255, 255)
position = (100, 200)
}
"#)?;
// Retrieve values
assert_eq!(config.get_int("window_width")?, 800);
assert_eq!(config.get_int("scale")?, 2);
assert_eq!(config.get_int("total_width")?, 1600);
§Advanced Usage
§Custom Handlers
use hyprlang::{Config, HandlerContext};
let mut config = Config::new();
// Register a custom handler
config.register_handler_fn("exec", |ctx| {
println!("Executing: {}", ctx.value);
Ok(())
});
config.parse("exec = /usr/bin/app")?;§Special Categories
use hyprlang::{Config, SpecialCategoryDescriptor};
let mut config = Config::new();
// Register a special category
config.register_special_category(
SpecialCategoryDescriptor::keyed("device", "name")
);
config.parse(r#"
device[mouse] {
sensitivity = 2.5
}
device[keyboard] {
repeat_rate = 50
}
"#)?;
let keys = config.list_special_category_keys("device");
assert!(keys.contains(&"mouse".to_string()));Structs§
- Color
- RGBA color representation
- Config
- Main configuration manager
- Config
Options - Configuration options
- Config
Value Entry - Wrapper for config values with metadata
- Expression
Evaluator - Expression evaluator for arithmetic expressions
- Function
Handler - Function-based handler wrapper
- Handler
Context - Context for handler execution
- Handler
Manager - Manager for keyword handlers
- Special
Category Descriptor - Descriptor for a special category configuration
- Special
Category Instance - A single instance of a special category
- Special
Category Manager - Manager for special categories
- Variable
Manager - Variable storage and resolution system
- Vec2
- A 2D vector with x and y components
Enums§
- Config
Error - Errors that can occur during configuration parsing and management
- Config
Value - Configuration value types
- Handler
Scope - Handler scope type
- Special
Category Type - Type of special category
Constants§
Traits§
- Custom
Value Type - Trait for custom value types
- Handler
- Trait for implementing custom keyword handlers
Functions§
- process_
escapes - Process escape sequences, replacing escaped braces with placeholders
- restore_
escaped_ braces - Restore escaped braces from placeholders to literal {{ and }}
Type Aliases§
- Parse
Result - Result type alias for configuration operations