Skip to content

Commit

Permalink
add kdl v2 support
Browse files Browse the repository at this point in the history
This adds v2 support with fallback to v1 for legacy configs.
It might be a bit bumpy at first but I'm hoping it works ok.
Probably worth treating as experimental for now.
  • Loading branch information
zkat committed Feb 17, 2025
1 parent 44c9797 commit 564043f
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 51 deletions.
191 changes: 143 additions & 48 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion niri-config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ repository.workspace = true
[dependencies]
bitflags.workspace = true
csscolorparser = "0.7.0"
kdl = { version = "6.3.3", features = ["v1-fallback"] }
knuffel = "3.2.0"
miette = { version = "5.10.0", features = ["fancy-no-backtrace"] }
miette = { version = "7.5.0", features = ["fancy-no-backtrace"] }
niri-ipc = { version = "25.1.0", path = "../niri-ipc" }
regex = "1.11.1"
smithay = { workspace = true, features = ["backend_libinput"] }
Expand Down
8 changes: 6 additions & 2 deletions niri-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::str::FromStr;
use std::time::Duration;

use bitflags::bitflags;
use kdl::{KdlDocument, KdlError};
use knuffel::errors::DecodeError;
use knuffel::Decode as _;
use layer_rule::LayerRule;
Expand Down Expand Up @@ -2042,9 +2043,12 @@ impl Config {
Ok(config)
}

pub fn parse(filename: &str, text: &str) -> Result<Self, knuffel::Error> {
pub fn parse(filename: &str, text: &str) -> Result<Self, KdlError> {
let _span = tracy_client::span!("Config::parse");
knuffel::parse(filename, text)
let mut doc: KdlDocument = text.parse()?;
doc.ensure_v1();
Ok(knuffel::parse(filename, text)
.expect("This should always succeed, if it passed the first time."))
}
}

Expand Down

0 comments on commit 564043f

Please # to comment.