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

Match rewrite rules iteratively, using array structure #2439

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kj
Copy link
Contributor

@kj kj commented Aug 29, 2023

Disclaimer: I don't know C++, so this is the result of trial and error!

This is not ready to be merged (although it works for me), I just wanted to check if this was something that might be desirable? Basically, I wanted to guarantee the order of rewrite rules (which is possible when rewrite rules are specified as an array, but not an object), and to allow successive rules to match against and replace the results of previous rules.

Here is an example config:

{
  "wlr/taskbar": {
    "format": "{name}%%%{title}",
    "on-click": "activate",
    "sort-by-app-id": true,
    "rewrite": [
      [".*(Alacritty).*?%%%(.*)", "\uf120  $2"],
      [".*(Audacious).*", "\uf001  $1"],
      [".*(Chromium).*", "\uf268  $1"],
      [".*(Firefox).*", "\ue007  $1"],
      [".*(Lutris|RetroArch|Steam).*", "\uf11b  $1"],
      ["^.*?%%%(.*)", "$1"],
      ["^(.{16}).+", "$1…"]
    ]
  }
}

The motivation was to have both the {name} and the {title} available in the format string so I can match against either on a case by case basis (falling back to one of the two if nothing earlier matches).

The array structure should be an alternative to the existing object structure although I didn't get that far as I'm just not comfortable with C++. If an object is passed to the function it should probably just restructure it into an array.

The other change, which could potentially alter the behaviour of existing configs (so probably more of a concern) is that it matches against the current value of res rather than the original value in the conditional which decides whether or not to apply the rule.

This guarantees rule order, and allows successive rules to match against
and replace the results of previous rules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant