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

modules/custom: Allow json fields as format specifiers #2441

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

rad4day
Copy link

@rad4day rad4day commented Aug 30, 2023

This PR changes the custom module in a (hopefully) backwards compatible way to allow using JSON fields as format specifiers.

As #404 and #676 have both been closed as non-working and I reeeaaally wanted this feature I spent a bit of time trying to figure out how to implement it. That's what I've come up with.
There are probably some weird bugs caused by this code. Disclaimer: I am not a C++ developer.

For example

    "custom/spotify": {
        "format-alt": "{status_icon}",
        "format-alt-click": "click-middle",
        "exec": "/usr/bin/python3 ~/.config/waybar/scripts/mediaplayer.py --player spotify",
        "format": "{status_icon} {artist} - {title}",
        "return-type": "json",
        "escape": true,
    },

which currently outputs the following JSON as a single line, where text is only provided as a fallback and not necessary.

{
  "player_name": "spotify",
  "player_icon": "\uf1bc",
  "artist": "Demoartist",
  "title": "totally a real song",
  "status": "Playing",
  "status_icon": "\uf144",
  "class": [
    "spotify",
    "playing"
  ],
  "text": "Demoartist - totally a real song"
}

What has been tested:

  • classes still work
  • alt format works
  • tooltips work

Percentage Icons are currently untested as I don't have a use case for those. I'd enjoy if somebody could test if they still work or provide a working example.

resolves #432

@alohl669
Copy link

I'm really interested, this feature could open the doors to printing different "format" outputs like format-tooltip or format-alt in the future, isn't it?

@rad4day
Copy link
Author

rad4day commented Jan 23, 2024

@alohl669 With a small change to L140 (adding the formatting engine there) this should be possible I think.

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.

[Feature request] Custom format replacements in custom modules
2 participants