https://github.com/anotherhadi/hyprlang-parser
A Golang implementation library for the hypr config language (Hyprlang).
https://github.com/anotherhadi/hyprlang-parser
golang hyprland hyprlang parser
Last synced: 9 months ago
JSON representation
A Golang implementation library for the hypr config language (Hyprlang).
- Host: GitHub
- URL: https://github.com/anotherhadi/hyprlang-parser
- Owner: anotherhadi
- License: mit
- Created: 2024-01-03T14:57:09.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-02-11T15:06:47.000Z (almost 2 years ago)
- Last Synced: 2024-06-21T17:54:14.430Z (over 1 year ago)
- Topics: golang, hyprland, hyprlang, parser
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hyprlang Parser
A Golang implementation library for the hypr config language.
## Installation
```bash
go get https://github.com/anotherhadi/hyprlang-parser@latest
```
## Functions
**Understanding Section and Variable Parameters:**
For most functions, you'll need to provide a "section" and a "variable" parameter.
- The "section" represents the name of the section, which is separated by forward slashes (/).
- The main section can be represented by either an empty string ("") or a single forward slash ("/").
- A decoration section could be "decoration" (or "/decoration/", as per your preference).
So, for example, to retrieve the enabled variable in the decoration section for blur:
- Set `section="decoration/blur"`
- Set `variable="enabled"`
---
| Function | Explanation | Example |
|------------------|------------------------------------------------|-------------------------------------------------|
| LoadConfig | Loads a configuration file at the specified path and returns a Config struct. It also adds the sourced configuration files. | ```config, err := LoadConfig("~/.config/hypr/hyprland.conf")``` |
| WriteConfig | Writes/saves changed configurations. | ```err := config.WriteConfig()``` |
| GetFirst | Returns the first value for the specified variable in the given section. | ```value := config.GetFirst("input", "kb_layout")``` |
| GetAll | Returns all the values for the specified variable in the given section. | ```values := config.GetAll("", "exec-once")``` |
| EditFirst | Changes the value of the first occurrence of the specified variable in the given section to the provided value. Returns an error if the variable was not found. | ```err := config.EditFirst("input/touchpad", "natural_scroll", "true")``` |
| EditN | Changes the value of the nth occurrence of the specified variable in the given section to the provided value. Returns an error if the variable was not found. | ```err := config.EditN("animations", "bezier", "winIn, 0.05, 0.9, 0.1, 1.1", 2)``` |
| Add | Creates a new variable with the provided value in the specified section. It creates the sections if they don't exist. If sections are not found, it will add the sections and the variable to the first config file. | ```config.Add("decoration/blur", "size", "3")``` |
| RemoveFirst | Removes the first occurrence of the specified variable in the given section. Returns an error if the variable is not found. | ```err := config.RemoveFirst("", "exec-once")``` |
| RemoveN | Removes the nth occurrence of the specified variable in the given section. Returns an error if the variable is not found. | ```err := config.RemoveN("", "exec-once", 2)``` |
## Example:
You can find more examples and usage in [`hyprlang_parser_test.go`](hyprlang_parser_test.go).