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
feat(script): add formatting for script failure #2596
feat(script): add formatting for script failure #2596
Conversation
Codecov Report
@@ Coverage Diff @@
## master #2596 +/- ##
==========================================
+ Coverage 11.78% 11.93% +0.14%
==========================================
Files 153 153
Lines 11265 11297 +32
==========================================
+ Hits 1328 1348 +20
- Misses 9937 9949 +12
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
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.
Works very nicely, thanks a lot! 😃
I mainly have some "cosmetic" nitpicks, otherwise everything looks great.
Please also add an entry in the changelog in the Added
section: https://github.com/polybar/polybar/blob/master/CONTRIBUTING.md#changelog
include/adapters/script_runner.hpp
Outdated
@@ -12,8 +12,8 @@ POLYBAR_NS | |||
class script_runner { | |||
public: | |||
using interval = std::chrono::duration<double>; | |||
script_runner(std::function<void(void)> on_update, const string& exec, const string& exec_if, bool tail, | |||
interval interval, const vector<pair<string, string>>& env); | |||
script_runner(std::function<void(void)> on_update, string exec, string exec_if, bool tail, interval interval, |
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.
I don't agree with using rvalues here. You don't gain anything since you still have a copy (now it happens when calling the constructor instead of during the constructor).
Even when using rvalue references, from a performance standpoint, the script_runner
is only executed when the module starts up and the two strings are generally no more than 100 bytes.
Unless you there is a good reason for this, I'd rather keep using const references.
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.
Well, i think it's kind of a personal preference. Passing an argument by-value offers clearer function interface by explicitly stating that argument will be copied when passed to the function. Const reference, on the other hand, only suggests, that it will and doesn't really specify the nature of interaction with the argument.
Performance-wise, when copy of the argument is desired inside a function, passing by value and then moving is better than passing by const reference, since if rvalue is passed, binding to const reference will always copy instead of just moving. Although, as you noted, it doesn't really matter in this case.
void f1(std::string s);
void f2(const std::string s);
auto s = std::string();
f1(std::move(s)); // move
f2(std::move(s)); // copy
The reason I made this change is because I tend to generally follow this principle, mostly because of clearer interface, than performance reasons. Didn't think much there, just an automatic reaction. I'll roll this one back to const references.
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.
Thanks for the explanation :)
I guess it really is a personal preferences. I would rather not expose the fact that a copy is made in the interface because if the copy becomes unnecessary in the future, it changes the interface and you may have to update all users.
6852db9
to
45ed0c1
Compare
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, just one minor change, then we can merge this :)
d149962
to
6c97a30
Compare
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.
Perfect!
Thanks a lot! Made it just in time for the 3.6 release ;) |
What type of PR is this? (check all applicable)
Description
The behavior is not changed unless the feature is used. Old configuration files should work the same way.
This PR adds formatting for script failure (when exited with non-zero exit status):
Falls back to
format
, ifformat-fail
isn't specified.The feature is disabled for
tail=true
scripts, since they either run indefinitely (so exit status doesn't have a change to be used) or stop for aninterval
that should be relatively short compared to the lifetime of a script. In both scenarios, exit status is received too late for it to be useful so there's no way to implement meaningful formatting for those scripts.Related Issues & Documents
Closes #2588
Documentation (check all applicable)
The following should be added to Modules/script/Additional Formatting: