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
fix(builder): Respect label-ellipsis option #1198
Conversation
8c18e50
to
e7bb4ce
Compare
Adds failing tests for the bug described in polybar#1194
ae6b9f2
to
32e9aab
Compare
Codecov Report
@@ Coverage Diff @@
## master #1198 +/- ##
==========================================
- Coverage 57.9% 5.57% -52.34%
==========================================
Files 24 163 +139
Lines 734 9532 +8798
==========================================
+ Hits 425 531 +106
- Misses 309 9001 +8692
Continue to review full report at Codecov.
|
Hold off on merging this, I think we should just log a warning and disable ellipsis, if the maxlen < 3 |
I think this is ready for review now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if we used an ellipsis character ("…") instead of three periods?
This will be what I implement next, in a separate PR, a config option to define the ellipsis. |
Configurable ellipsis = #1195 |
I tested this patch as a user, I didn't find any issue. Beware that it changes behaviour (that's intended, and I requested this change in #1195): |
The behavior change is quite minor and one could argue that it was a bug that with a maxlen of 4 the actual maxlen was 7. I don't think this warrants more than a note in the commit message gonna ammend right now. |
This slightly changes the existing behavior of maxlen. Before with a maxlen of 4 'abcde' used to yield 'abcd...' now it yields 'a...'
The check of the maxlen and ellipsis condition was also moved to the label creation, this way get_label_text doesn't need to care about the restrictions placed on maxlen and ellipsis
src/drawtypes/label.cpp
Outdated
bool ellipsis = conf.get(section, name + "-ellipsis", true); | ||
|
||
if(ellipsis && maxlen > 0 && maxlen < 3) { | ||
logger::make().err(sstream() << "Label " << section << "." << name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we throw an application_error
or some other type of error to avoid creating a new logger?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logger::make
uses the singleton pattern, so only the first call to logger::make()
will create a new instance, all others always return the same instance. I used it directly because I didn't want to add the m_log
field just for that.. Btw. I really don't like the use of a singleton for the logger but that is a discussion for another time.
If we threw an application_error
here, wouldn't it be caught in the controller and would disable the whole module? I was debating, if we wanted invalid maxlen be a fatal error, would you prefer that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think that would be much neater.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, gonna revert back to throwing an error when I have the time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
This now makes label-maxlen < len(ellipsis) (= 3) a fatal error disabling the whole module that uses the offending label
Breaking Changes: * `0 < label-NAME-maxlen < 3` will now throw an exception and disable the containing module, if ellipsis is enabled for that label. (#1198) Changelog: Deprecations: * `internal/volume` is now called `internal/alsa` (#967) * temperature: The `%temperature%` is deprecated in favor of `%temperature-c%`(#897) * mpd: `icon-repeatone` is deprecated in favor of `icon-single` (#1295), see #1279 Features: * feat(mpd): Add support for icon-consume (#861) * feat(bspwm): Add workspace separator (#942) * feat(i3): Add workspace separator (#938), see #929 * feat(build): Make polybar build on FreeBSD (#931, polybar/xpp#8), see #239 * feat(volume): Add pulseaudio backend (#779) * feat(script): Add %pid% token for tail commands (#934) * feat(temp): Add temperature tokens without unit (#897) * feat(memory): Add memory used/free ramp (#1038), see #1037 * feat(memory): Add swap tokens (#1018) * feat(net): Add unknown-as-up option (#1077), see #457 * feat(config): Support fractional size and offset (#972), see #953 * feat(xwindow): Add label-empty (#1136) * feat(battery): Add animation-discharging (analog to animation-charging) (#1190) * feat(config): Support pixel offset for bar size and offset values (#1224) * feat(mpd): Add `%album-artist%` token (#1263) * feat(net): Add local_ip6 token (#1239), see #1234 * feat(net): Add nl80211 support (#1009), see #277 Fixes: * fix(mpd): Wrong elapsed time when after standby (#921), see #915 * fix(config): Wrong min, maxlen when using the same token multiple times (#974), see #971 * fix(battery): use power_now correctly (#958), see #928 * fix(mpd): Crash when mpd isn't running (#983), see #979 * fix(xworkspaces): Respect 'enable-scroll' (#1002) * fix(xbacklight): Respect 'enable-scroll' (#1014) * fix(build): support xcb-proto >=1.13 (polybar/xpp#11), see #973 * fix(mpd): Respect MPD_HOST env variable (#1025), see #1007 * fix(i3): Reconnect i3 IPC socket on restart/error (#1099), see #762 * fix(cursor): Occasional crash on mouseover (#1124), see #1117 * fix(net): Mark 'not connected' on querying failure (#1171), see #1163 * fix(gcc): Fix -Wstringop-truncation warning (#1216, polybar/i3ipcpp#7), see #1215 * fix(builder): Don't truncate colors with same channels (#1217), see #1183 * fix(bspwm): Consistent behavior when scrolling through multiple desktops (#986), see #981 * fix(builder): Respect label-ellipsis option (#1198), see #1194
As described in #1194 polybar never actually checks the m_ellipsis flag
in labels.
Right now, I have only refactored the builder to determine the actual
label text inside a function and added failing tests for that bug and
the general expected behaviour of get_label_text. This is why the
tests in the current build will fail.
This will probably decrease test coverage quite drastically, as codecov
doesn't track builder.cpp yet, so this basically adds a bunch of not
covered lines that codecov is now tracking
Also @NBonaparte, do you think the builder should throw an exception,
if the maxlen is less than the length of the ellipsis and ellipsis is
enabled, because it would be impossible to follow both the label-maxlen
and the label-ellipsis directive?
EDIT1: Seems like the new test doesn't build on travis, and for some reason the travis build doesn't fail when this happens.
EDIT2: I have fixed the compilation error, now the test should fail for the right reasons
EDIT3: Fixes #1194