diff --git a/CHANGELOG.md b/CHANGELOG.md index 7757117..7a73097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - When using `embassy` option, `async_main.rs` file was renamed to `main.rs` (#93) - The UI no longer allows selecting options with missing requirements, and does not allow deselecting options that are required by other options. (#101) +- Options can now declare negative requirements (e.g. `!alloc` can not be enabled if `alloc` is used) (#101) ### Fixed diff --git a/src/tui.rs b/src/tui.rs index 45f7060..9d9e495 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -103,11 +103,35 @@ impl Repository { return false; } - for requirement in option.requires { - if !self.is_selected(requirement) { + // Are this option's requirements met? + for &requirement in option.requires { + let (key, expected) = if let Some(requirement) = requirement.strip_prefix('!') { + (requirement, false) + } else { + (requirement, true) + }; + + if self.is_selected(key) != expected { return false; } } + + // Does any of the enabled options have a requirement against this one? + for selected in self.selected.iter() { + let Some(selected_option) = find_option(selected, self.options) else { + ratatui::restore(); + panic!("selected option not found: {selected}"); + }; + + for requirement in selected_option.requires.iter() { + if let Some(requirement) = requirement.strip_prefix('!') { + if requirement == option.name { + return false; + } + } + } + } + true }