Alexays / Waybar

Highly customizable Wayland bar for Sway and Wlroots based compositors. :v: :tada:
MIT License
6.65k stars 709 forks source link

Limit length of modules #486

Closed 4e554c4c closed 1 year ago

4e554c4c commented 5 years ago

Hi,

I can't figure out how to limit the length of text of a module or if this is possible.

For example, if I have the mpd module enabled and a song with a long name occurs, it will take up the entire bar.

I tried reading the documentation for fmt, and it appears to be quite easy to specify a minimum length for text, but not a maximum.

If possible I would like to hide the text with an ellipsis if it became long enough to run into other modules.

ghost commented 5 years ago

+1 from me as well CPU usage is the big offender for me. It constantly jumping from single digit to double digit (1% vs 20% usage) constantly makes everything resize by a bit. It's kinda annoying.

cafehaine commented 5 years ago

with cpu {usage:3}% has a constant width, it's only a problem with text formatting like network interface and music

ghost commented 5 years ago

@cafehaine: ooooooooh thx <3

edit: hmm, strange. It still resizes, even though I have "cpu": { "format": "{usage:3}% ", .... }

cafehaine commented 5 years ago

Are you sure you are using a monospaced font ?

ghost commented 5 years ago

@cafehaine: ohh, indeed. RTFM to me >.< I didn't think it would use a zero width character to reserve space.

ghost commented 5 years ago

Although I just noticed with {bandwidthUpBits} and {bandwidthDownBits}. Having your traffic shown causes quite a bit of dancing.

4e554c4c commented 5 years ago

is this a problem with waybar specifically or is it something which should be upstreamed to fmt?

i feel like there's a case for both.

Alexays commented 5 years ago

You can use the max-length params in your module config

4e554c4c commented 5 years ago

This works great for me! thanks.

before I close, for the mpd module, if i specify the max-length param then it hides the entire format.

Can I configure it so that, e.g. the song name is max a certain length and then the progress is still shown?

Alexays commented 5 years ago

@4e554c4c I'll look on it to apply max-length only on the song name

ghost commented 5 years ago

@Alexays Could similar be done to the network module? No matter how I lay it out, Network traffic dances around a bit when changing from 0b/s to 1200kb/s and so on...

ghost commented 4 years ago

The same for memory, using {avail}GB Currently showing 2.03677GB free, would be nice to be able to trim it to 2.0GB.

mendelmaleh commented 4 years ago

It seems like the fmt library used supports trimming strings with the float precision argument, ie: {:.4} to set field to max 4 chars, I'm using this for trimming the network interface name and its working so far. From the fmt docs:

The precision is a decimal number indicating how many digits should be displayed after the decimal point for a floating-point value formatted with 'f' and 'F', or before and after the decimal point for a floating-point value formatted with 'g' or 'G'. For non-number types the field indicates the maximum field size - in other words, how many characters will be used from the field content. The precision is not allowed for integer, character, Boolean, and pointer values.

dschrempf commented 4 years ago

I can only underline that the bandwidth cannot be displayed properly without having an option to define a fixed width.

tsujp commented 4 years ago

Adding fixed-width for network would be nice, even when using monospace it constantly changes as it goes from say 0b/s (4 chars) then to 100b/s (6 chars) then to 2.1kb/s (7 chars) for instance.

layus commented 4 years ago

1/ I have defined a new formatter for long/large numbers like bandwidth and disk usage. See https://github.com/Alexays/Waybar/pull/472#issue-320672419. That should definitely find its place in the wiki. Maybe in the How can I prevent modules from changing size? section ?

2/ There is an unfortunate "feature" (I see it as a bug) of font rendering with cairo: It always uses the whitespace characters from the last (fallback) font in used. That is why emojis and strange unicode characters found only in non-monospace fallback fonts will make the modules to changes size, even if their content has a fixed number of characters. To see if this is your problem, remove any strange glyphs, the problem should disappear.

To work around cairo, you can use explicit font selection as in the snippet below. This will prevent font awesome to be used outside the <span>, and use the correct monospace whitespace for the spaces preceding the percentage.

    "backlight": {
        "format": "{icon} {percent:>3}%",
        "format-icons": ["<span font=\"Font Awesome 5 Free\"></span>", "<span font=\"Font Awesome 5 Free\"></span>"],
        ...
    },

Anyone cares to test this and update the wiki ?