Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: multiple openers for a single rule #154

Merged
merged 3 commits into from
Sep 16, 2023
Merged

Conversation

Linus789
Copy link
Contributor

issue: #145

@sxyazi
Copy link
Owner

sxyazi commented Sep 14, 2023

Thank you!

Seems like it could break the existing user config, as they would need to switch to arrays. Is it possible to support both arrays and strings, similar to the keymap rules:

{ on = [ "<Space>" ], exec = [ "select --state=none", "arrow 1" ], desc = "Toggle the current selection state" },
{ on = [ "v" ], exec = "visual_mode", desc = "Enter visual mode (selection mode)" },

Here is the implementation code:

impl Exec {
pub fn deserialize<'de, D>(deserializer: D) -> Result<Vec<Exec>, D::Error>
where
D: Deserializer<'de>,
{
struct ExecVisitor;
impl<'de> Visitor<'de> for ExecVisitor {
type Value = Vec<Exec>;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("a exec string, e.g. tab_switch 0")
}
fn visit_seq<A>(self, mut seq: A) -> Result<Self::Value, A::Error>
where
A: de::SeqAccess<'de>,
{
let mut execs = Vec::new();
while let Some(value) = &seq.next_element::<String>()? {
execs.push(Exec::try_from(value.as_str()).map_err(de::Error::custom)?);
}
Ok(execs)
}
fn visit_str<E>(self, value: &str) -> Result<Self::Value, E>
where
E: de::Error,
{
Ok(vec![Exec::try_from(value).map_err(de::Error::custom)?])
}
}
deserializer.deserialize_any(ExecVisitor)
}
}

@Linus789
Copy link
Contributor Author

Okay, that should work now.

@sxyazi
Copy link
Owner

sxyazi commented Sep 16, 2023

Thank you, I made some simplifying. Merged!

@sxyazi sxyazi merged commit 0924371 into sxyazi:main Sep 16, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants