#wayland #hyprland #parser #config-file

hyprparser

A parser for Hyprland's configuration file

5 releases

0.1.6 Nov 24, 2024
0.1.5 Nov 4, 2024
0.1.1 Oct 29, 2024

#180 in Configuration

Download history 300/week @ 2024-10-27 738/week @ 2024-11-03 203/week @ 2024-11-10 192/week @ 2024-11-17 280/week @ 2024-11-24 281/week @ 2024-12-01 196/week @ 2024-12-08 163/week @ 2024-12-15 114/week @ 2024-12-22

784 downloads per month

GPL-2.0 license

63KB
364 lines

HyprParser

A parser for Hyprland's configuration files written in Rust 🚀🦀


Crates.io Version

Hyprland Configuration Documentation

Usage

HyprParser is available on Crates.io. It can be added as a dependency with:

$ cargo add hyprparser

Here's an example usage:

# Cargo.toml

[dependencies]
hyprparser = "0.1.2"
// main.rs

use hyprparser::parse_config;
use std::{env, fs, path::Path};

fn main() {
    let config_path = Path::new(&env::var("XDG_CONFIG_HOME").unwrap_or_else(|_| {
        let home = env::var("HOME").unwrap_or_else(|_| ".".to_string());
        format!("{}/.config", home)
    }))
    .join("hypr/hyprland.conf");

    let config_str = fs::read_to_string(&config_path).unwrap();

    let mut parsed_config = parse_config(&config_str);

    parsed_config.add_entry("decoration", "rounding = 10");
    parsed_config.add_entry("decoration.blur", "enabled = true");
    parsed_config.add_entry("decoration.blur", "size = 10");
    parsed_config.add_entry_headless("$terminal", "kitty");

    let updated_config_str = parsed_config.to_string();

    fs::write(&config_path, updated_config_str).unwrap();

    println!("Updated hyprland.conf with new configuration.");
}

TODO

  • Color formatting tests

Credits

Copyright (C) 2024 HyprUtils

No runtime deps