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

Add support for custom formats with labels #30

Merged
merged 8 commits into from
Aug 7, 2024

Conversation

dshoreman
Copy link
Contributor

@dshoreman dshoreman commented Aug 7, 2024

Hi! I started switching to Waybar at the weekend and found this to replace what I had for Polybar previously. It works great—thanks for merging #29 so quickly btw—but ideally I'd like to show counts separately.

I couldn't find a way to get Waybar passing anything from the "real" format option in the bar config, so instead I've hacked together some basic "label" parsing. It supports a custom prefix/suffix (separated by :) which allows for per-count auto-hiding icons, but at the cost of a really ugly sed block.

New CLI args

  • -f, --format
  • -t, --tooltip

Supported Labels

  • {aur}
  • {dev}
  • {pacman}
  • {total}

Examples

New defaults

"exec": "waybar-updates",

// All examples are based on this:
"format": "{icon}{}",
"format-icons": {
    "pending-updates": " ",
    "updated": ""
}

wbu-0-default

Custom prefix and suffix

"exec": "waybar-updates --format '{total}{ (+:aur: AUR)}'",

wbu-1-text

Multiline Pacman+AUR example with icons

"exec": "waybar-updates -df '{ :pacman:\n  }{ :aur}'",

wbu-2-multiline

Showing only package counts in the tooltip

"exec": "waybar-updates --tooltip '{ :pacman}{  :aur}{  :dev}'",

wbu-3-simplett

Showing all counts individually (and hiding them in the tooltip)

"exec": "waybar-updates -df '{pacman}{  :aur} {  :dev}' -t '{}'",

wbu-4-countsinbar

Adds support for per-value "labels" that will only be visisble when the
associated value is above zero. Useful for seperate icons per value.

Valid labels are `{aur}`, `{pacman}` or `{total}`. Icons can optionally
be added before/after values using e.g. `{x:aur}` and/or `{aur:x}`.

Examples:
```
waybar-updates -f '{total} ({pacman}+{aur})'

waybar-updates -f '{ :total: updates}'

waybar-updates -f '{  :pacman:\n}{  :aur}'
```
Same labels as the main text format, with the addition of `{}` which
gets replaced with the generated list of updates. By default adds an
extra row to the top of the tooltip showing Pacman and AUR values.
Removes duplication in WIP stuff and moves text/tooltip/json generation
into a new `send_output` function so it's a little easier to parse.

Also removes the `function` from the rest of the functions since `usage`
doesn't have it so it makes more sense that the rest also don't get it.
@dshoreman dshoreman marked this pull request as draft August 7, 2024 19:57
@dshoreman
Copy link
Contributor Author

Seems some of the hackery is confusing shellcheck, I'll get those fixed up later tonight

@dshoreman dshoreman marked this pull request as ready for review August 7, 2024 20:51
@savely-krasovsky
Copy link
Owner

As far as I got, this will be a default for exisiting users who are not aware of changes?

formats[text]="{total}"
formats[tooltip]="\t\t {\t  :pacman}{\t  :aur}{\t  :dev}\n\n{}"

@savely-krasovsky
Copy link
Owner

Overall PR looks excellent, very accurate, a lot of small good looking style changes, very appreciate it!

@dshoreman
Copy link
Contributor Author

dshoreman commented Aug 7, 2024

As far as I got, this will be a default for exisiting users who are not aware of changes?

formats[text]="{total}"
formats[tooltip]="\t\t {\t  :pacman}{\t  :aur}{\t  :dev}\n\n{}"

Correct - so by default the text stays the same, but all (non-zero) counts are added to tooltip

I tried to get it somewhat centered but fonts, so YMMV

@savely-krasovsky savely-krasovsky merged commit 1ea5b21 into savely-krasovsky:master Aug 7, 2024
2 checks passed
@savely-krasovsky
Copy link
Owner

savely-krasovsky commented Aug 7, 2024

I will release it as part of v0.5.0 a little bit later, have some work to do in Windows...

@dshoreman
Copy link
Contributor Author

dshoreman commented Aug 7, 2024

The thought of Waybar on Windows didn't even cross my mind! Now I'm curious...

@savely-krasovsky
Copy link
Owner

@dshoreman unfortunately, by work I meant actual work! So I am loaded in Windows for now.

@dshoreman
Copy link
Contributor Author

Aha! Sorry, been a long day 😆

@savely-krasovsky
Copy link
Owner

Should be available in AUR!

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.

2 participants