mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-23 02:05:33 +07:00
Partially implement config includes
Subsequent commits will add merging for all leftover sections.
This commit is contained in:
@@ -1103,8 +1103,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rule_color_can_override_base_gradient() {
|
||||
let config = Config::parse(
|
||||
"test.kdl",
|
||||
let config = Config::parse_mem(
|
||||
r##"
|
||||
// Start with gradient set.
|
||||
layout {
|
||||
@@ -1127,7 +1126,7 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut border = config.resolve_layout().border;
|
||||
let mut border = config.layout.border;
|
||||
for rule in &config.window_rules {
|
||||
border.merge_with(&rule.border);
|
||||
}
|
||||
@@ -1151,8 +1150,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn rule_color_can_override_rule_gradient() {
|
||||
let config = Config::parse(
|
||||
"test.kdl",
|
||||
let config = Config::parse_mem(
|
||||
r##"
|
||||
// Start with gradient set.
|
||||
layout {
|
||||
@@ -1196,7 +1194,7 @@ mod tests {
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let mut border = config.resolve_layout().border;
|
||||
let mut border = config.layout.border;
|
||||
let mut tab_indicator_rule = TabIndicatorRule::default();
|
||||
for rule in &config.window_rules {
|
||||
border.merge_with(&rule.border);
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
use std::error::Error;
|
||||
use std::fmt;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use miette::Diagnostic;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct ConfigParseResult<T, E> {
|
||||
pub config: Result<T, E>,
|
||||
|
||||
// We always try to return includes for the file watcher.
|
||||
//
|
||||
// If the main config is valid, but an included file fails to parse, config will be an Err(),
|
||||
// but includes will still be filled, so that fixing just the included file is enough to
|
||||
// trigger a reload.
|
||||
pub includes: Vec<PathBuf>,
|
||||
}
|
||||
|
||||
/// Error type that chains main errors with include errors.
|
||||
///
|
||||
/// Allows miette's Report formatting to have main + include errors all in one.
|
||||
#[derive(Debug)]
|
||||
pub struct ConfigIncludeError {
|
||||
pub main: knuffel::Error,
|
||||
pub includes: Vec<knuffel::Error>,
|
||||
}
|
||||
|
||||
impl<T, E> ConfigParseResult<T, E> {
|
||||
pub fn from_err(err: E) -> Self {
|
||||
Self {
|
||||
config: Err(err),
|
||||
includes: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn map_config_res<U, V>(
|
||||
self,
|
||||
f: impl FnOnce(Result<T, E>) -> Result<U, V>,
|
||||
) -> ConfigParseResult<U, V> {
|
||||
ConfigParseResult {
|
||||
config: f(self.config),
|
||||
includes: self.includes,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for ConfigIncludeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.main, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for ConfigIncludeError {
|
||||
fn source(&self) -> Option<&(dyn Error + 'static)> {
|
||||
self.main.source()
|
||||
}
|
||||
}
|
||||
|
||||
impl Diagnostic for ConfigIncludeError {
|
||||
fn code<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
|
||||
self.main.code()
|
||||
}
|
||||
|
||||
fn severity(&self) -> Option<miette::Severity> {
|
||||
self.main.severity()
|
||||
}
|
||||
|
||||
fn help<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
|
||||
self.main.help()
|
||||
}
|
||||
|
||||
fn url<'a>(&'a self) -> Option<Box<dyn fmt::Display + 'a>> {
|
||||
self.main.url()
|
||||
}
|
||||
|
||||
fn source_code(&self) -> Option<&dyn miette::SourceCode> {
|
||||
self.main.source_code()
|
||||
}
|
||||
|
||||
fn labels(&self) -> Option<Box<dyn Iterator<Item = miette::LabeledSpan> + '_>> {
|
||||
self.main.labels()
|
||||
}
|
||||
|
||||
fn diagnostic_source(&self) -> Option<&dyn Diagnostic> {
|
||||
self.main.diagnostic_source()
|
||||
}
|
||||
|
||||
fn related<'a>(&'a self) -> Option<Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a>> {
|
||||
let main_related = self.main.related();
|
||||
let includes_iter = self.includes.iter().map(|err| err as &'a dyn Diagnostic);
|
||||
|
||||
let iter: Box<dyn Iterator<Item = &'a dyn Diagnostic> + 'a> = match main_related {
|
||||
Some(main) => Box::new(main.chain(includes_iter)),
|
||||
None => Box::new(includes_iter),
|
||||
};
|
||||
|
||||
Some(iter)
|
||||
}
|
||||
}
|
||||
+555
-328
File diff suppressed because it is too large
Load Diff
@@ -36,6 +36,17 @@ impl Default for Cursor {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Clone, PartialEq)]
|
||||
pub struct ScreenshotPath(#[knuffel(argument)] pub Option<String>);
|
||||
|
||||
impl Default for ScreenshotPath {
|
||||
fn default() -> Self {
|
||||
Self(Some(String::from(
|
||||
"~/Pictures/Screenshots/Screenshot from %Y-%m-%d %H-%M-%S.png",
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(knuffel::Decode, Debug, Default, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct HotkeyOverlay {
|
||||
#[knuffel(child)]
|
||||
|
||||
Reference in New Issue
Block a user