-
-
Notifications
You must be signed in to change notification settings - Fork 723
config_parser: Introduce stricter syntax conventions #1377
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
Conversation
b45e8da to
28bea57
Compare
|
I think this is ready for first review now. I know this is quite a big PR, so we should take our time reviewing it. I think I have already outlined the motivation behind this and what this PR does quite well, please say, if I need to provide any more info. With my configs, I see no difference between using this PR and master when displaying the bar.
|
NBonaparte
left a comment
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.
Did a cursory review of the code to get trivial stuff out of the way, will do a more in-depth review soon.
Should we have a style guide of some sort to prevent inconsistencies?
|
According to the I have now gone over the whole PR again and mainly improved the comments as well as fixed the I have tested the three things I listed above and now they all work as expected. |
|
Before we merge this there are two more things we need to confirm didn't change in this PR: Does It doesn't in this PR because key names have to be unique. If it did in the current version it would have weird behaviour because polybar doesn't preserve the order of the keys and if there are conflicts they would be resolved differently depending on the order. In any case it would be a nice to have. Maybe let Does It doesn't in this PR because it is not really treated as a key but more like an |
|
@patrick96 This still has to be reviewed, correct? I forgot about this because it wasn't assigned to me. |
|
Yeah this needs to be reviewed. I forgot to request a review again. I will also need to check the two things mentioned above, though there won't probably be any surprises there. |
7f377bd to
81dd405
Compare
659e6e5 to
caa363a
Compare
|
My findings: Does Does Does I'm pretty sure that I have now checked that the functionality didn't change with this PR (except for the syntax rules). Feel free to criticize. My C++ is still not that good. |
b92fcaa to
f5d2ff8
Compare
|
Merge conflicts are now fixed :) |
First step in the config_parser develoment. Only tests functions that are easily testable without many outside dependencies. Integration tests will follow.
|
Thanks 😊 If you want me to split this up into multiple smaller PRs so that we can review smaller chunks, let me know. |
NBonaparte
left a comment
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.
Overall functionality looks OK.
All the string arguments for the config_parser functions should be const string& instead of string since they're not being modified.
| config::make_type result = config::make(m_file, m_barname); | ||
|
|
||
| // Cast to non-const to set sections, included and xrm | ||
| config& m_conf = const_cast<config&>(result); |
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.
We keep getting away with this, we should probably fix this some 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.
Yes, terrible practice. Also in the cpu module 😄
I think I will change that in future PRs and make config something that is constructed just like a normal struct and after that is const in the entire program
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 have a suggestion for this.
How we have suppressed this in the cpu module.
Maybe we should make config::make private and modifies it to return a non-const ref and add friend class config_parser into the config class then we add a config::get or something like that which returns the singleton (const& version). What do you think of that?
In case we want to remove the singleton, we could also store the config into bar and so we can access it from bar into the modules.
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 think removing the singleton would be good. The singleton provides two things: it restricts a the class to a single instance and it gives easy access to it. We only need the easy access since technically there could be multiple config instances. So moving the config into an object the code already has access to (bar_settings or similar) is a good idea.
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 can do that once your PR is merged if you want.
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.
On second though, it may be beneficial to just pass the config to wherever it's needed since it's only really needed in the modules, controller.cpp, renderer.cpp, screen.cpp, and tray_manager.cpp. Though we could probably remove it from screen.cpp since it only needs access to the screenchange-reload setting.
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 that's also a possibility.
c42ac8c to
047c57c
Compare
Lomadriel
left a comment
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.
This new parser seems really nice.
My remarks are more about the code quality.
Misc remarks:
- Maybe
string filepath() const;andstring section() const;should return a const ref to let the caller decide if a copy is needed. - There are some missing
m_for some attributes in theconfig_parserclass.
Some of my comments might be excessive optimization but it may improve performance/code readability/code safety so it could be worth it! (and I like code :P, sorry :( )
|
Thanks! I'll try to address the issues. Keep 'em coming, you're definitely more experienced with C++ especially when it comes to move semantivs :) |
047c57c to
59ba3e6
Compare
Thanks a lot for the review. Once this is merged I think I'll try to refactor it again a little to more decouple things. |
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.
sectionactually constructs a string so we can't return a reference since it would be on the stack.
Oops didn't see that. sry
Other things that can't be include in the review:
utils/file.hpp(line 9) &utils/math.hpp(line 10) aren't used inconfig.cppcstring(line 2) isn't used instring.cpp
I missed things in my first review but we are pretty close to the end :D.
EDIT: I don't know why my review has been separated in two reviews 😞 but please also take a look at the review above.
EDIT 2: You new code doesn't seems to respect the clang-tidy maybe you should run it on your files ;)
I don't know which IDE/code editor you are using but maybe you should install a plugin to automatically run clang-format on the modified code.
8c52e63 to
198883e
Compare
|
Done! I ran all changed files through The only thing missing seems to be your suggestion about using a template parameter instead of |
|
Except for my suggestion about using a template parameter everything LGTM. EDIT: I also added a suggestion for removing the |
Lomadriel
left a comment
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.
LGTM
732dc6c to
198883e
Compare
Breaking Changes:
* The new config parser imposes some restrictions on which characters can be
used in section and key names. Users shouldn't be affected by this unless they
use one of the following characters in any section or key name: `"'=;#[](){}:.$\%`
Please consult [`man 5 polybar`](https://polybar.readthedocs.io/en/latest/man/polybar.5.html) for a full reference of the new config rules.
* `internal/temperature`: The first and last ramp element are now only used for
`base-temperature` and below and `warn-temperature` and above respectively.
This only slightly changes the ranges for which the different ramp levels are
responsible for.
(#2197)
Changelog
**Deprecations**
* `[settings]`: `throttle-input-for` has been removed. It wasn't a useful option
and could cause certain actions (e.g. click commands) to be ignored. (#2117)
* All action names used by modules to handle click and scroll events are
depercated (#1907). This change mainly affects users of the menu module.
Please read the [documentation](https://polybar.readthedocs.io/en/latest/user/actions.html) for instructions on how to migrate.
**New Config Options**
The `include-directory` key can be used the same as `include-file` and includes
all regular files in the given directory.
In labels:
* `label-NAME-minlen`, `label-NAME-alignment` can be used to pad labels with
spaces to the right (alignment set to `left`), left (alignment set to
`right`), and both sides (alignment set to `center`).
In `internal/backlight`:
* `enable-scroll` enables changing the brightness through scrolling.
In `internal/github`:
* `format-offline` is used when the module cannot connect to the server.
* `label-offline` can be used in `format-offline`.
* `api-url` can be used to connect to a custom github enterprise instance
In `internal/pulseaudio`:
* `click-right` and `click-middle` can be used to execute commands when
right/middle clicking.
* `%decibels%` token can be used in `label-volume` and `label-muted` to show the
volume in decibels.
**Changes To The Build System**
* Allow users to specify python executable when building. (polybar/xpp#27,
#2125)
* The i3ipcpp submodule no longer rebuilds jsoncpp and just uses whatever
version is available. (#2015, polybar/i3ipcpp#9)
**Features**
* New commandline argument: `-M` / `--list-all-monitors`.
Will display all available monitors (even cloned ones).
* New log level: `notice`.
Used as the default and is used for non-warning messages the user should
nevertheless be aware of. (#2027)
* config:
* New config parser (#1377)
* `include-directory` key (#2196), see #1946
* Add error message when an entire section is missing. (#2195)
* `-minlen` and `-alignment` properties for labels. (#1546)
* Make the `seperator` key in the bar section a label. (#1918)
* Better color validation. (#1290)
* timer modules: Schedule module updates to be aligned with the update interval.
For example, the date module now updates on the minute instead of in the
middle of a minute if the interval is set to 60 seconds. (#2123), see #2064
* `custom/menu`: Multiple menu modules per bar (#1907)
* `internal/backlight`: Support for changing the brightness through scrolling.
This may require additional changes to the system running polybar. (#1957)
* `internal/github`:
* `format-offline` for when the module cannot connect to the server (#1825),
see #1815
* Support for github enterprise instances. (#1841), see #1812
* `internal/network`: Support `Gbit/s` for `%linkspeed%` token. (#2055)
* `internal/pulseaudio`:
* `click-right` and `click-middle` keys (#1941)
* `%decibels%` token (#1894), see #1886
* `internal/xworkspaces`: Proper implementation for `label-occupied`. (#822),
see #874, #1444, #1033
**Fixes**
* Polybar not executing commands that produce output. (#1680), see #916
* Polybar froze until click commands finished executing (#2248)
* Polybar not properly working with mirrored monitors. (#1823), see #1192 and
#1794
* Unstable animation framerate (#1683), see #568
* Multiple modules of the same type caused click events not to be delivered to
the rigth one (#1907), see #1172
* config:
* Seemingly unrelated error messages when BOM character appears in config.
(#2166), see #2075
* Fall back to next possible config location if config file doesn't exist
(except if `--config` was used). (#2026), see #2016
* iconset: `fuzzy-match` chose first match, even if exact match was available.
(#2042), see #2041
* `custom/menu`: Spacing issue (#1656)
* `internal/alsa`: Volume didn't go over 100% (#2184), see #2173
* `internal/backlight`: Use amdgpu workaround for all devices starting with
`amdgpu_bl`. (#2122)
* `internal/battery`: Battery not marked as full if over `full-at` percent.
(#2019), see #1622
* `internal/cpu`: More accurate cpu load calculation. (#1955)
* `internal/github`: Outdated GitHub API authentication. (#2029), see #2002
* `internal/memory`: Use the correct size prefixes (#2211), see #2023
* `internal/network`:
* Wrong up- and downspeed values for non-integer intervals. (#2219)
* tun/tap interfaces didn't query their IP addresses. (#1990), see #1986
* Don't crash module if linkspeed cannot be queried. (#1772), see #1211
* `internal/temperature`:
* `format-warn` was not used if the temperature was *exactly*
`warn-temperature`. (#1897)
* `internal/xworkspaces`:
* Multi-monitor issue (#1929), see #1764, #1849
* Module sometimes showed too many workspaces (#1984), see #1983
* build:
* xpp submodule doesn't work with python 3.9 (polybar/xpp#26)
* CMake 3.17+ developer warnings (#2089, polybar/xpp#24, polybar/xpp#25)
* gtest compilation failure (#1993), see google/googletest#2678
* Compilation issue in GCC 6. (#1953)
Breaking Changes:
* The new config parser imposes some restrictions on which characters can be
used in section and key names. Users shouldn't be affected by, this unless
they use one of the following characters in any section or key name: `"'=;#[](){}:.$\%`
Please consult [`man 5 polybar`](https://polybar.readthedocs.io/en/latest/man/polybar.5.html) for a full reference of the new config rules.
* `internal/temperature`: The first and last ramp element are now only used for
`base-temperature` and below and `warn-temperature` and above respectively.
This only slightly changes the ranges for which the different ramp levels are
responsible for.
(#2197)
Changelog
**Deprecations**
* `[settings]`: `throttle-input-for` has been removed. It wasn't a useful option
and could cause certain actions (e.g. click commands) to be ignored. (#2117)
* All action names used by modules to handle click and scroll events are
deprecated (#1907). This change mainly affects users of the menu module.
Please read the [documentation](https://polybar.readthedocs.io/en/latest/user/actions.html) for instructions on how to migrate.
**New Config Options**
The `include-directory` key can be used the same as `include-file` and includes
all regular files in the given directory.
In labels:
* `label-NAME-minlen`, `label-NAME-alignment` can be used to pad labels with
spaces to the right (alignment set to `left`), left (alignment set to
`right`), and both sides (alignment set to `center`).
In `internal/backlight`:
* `enable-scroll` enables changing the brightness through scrolling.
In `internal/github`:
* `format-offline` is used when the module cannot connect to the server.
* `label-offline` can be used in `format-offline`.
* `api-url` can be used to connect to a custom github enterprise instance
In `internal/pulseaudio`:
* `click-right` and `click-middle` can be used to execute commands when
right/middle clicking.
* `%decibels%` token can be used in `label-volume` and `label-muted` to show the
volume in decibels.
**Changes To The Build System**
* Allow users to specify python executable when building. (polybar/xpp#27,
#2125)
* The i3ipcpp submodule no longer rebuilds jsoncpp and just uses whatever
version is available. (#2015, polybar/i3ipcpp#9)
**Features**
* New commandline argument: `-M` / `--list-all-monitors`.
Will display all available monitors (even cloned ones).
* New log level: `notice`.
Used as the default and is used for non-warning messages the user should
nevertheless be aware of. (#2027)
* config:
* New config parser (#1377)
* `include-directory` key (#2196), see #1946
* Add error message when an entire section is missing. (#2195)
* `-minlen` and `-alignment` properties for labels. (#1546)
* Make the `seperator` key in the bar section a label. (#1918)
* Better color validation. (#1290)
* timer modules: Schedule module updates to be aligned with the update interval.
For example, the date module now updates on the minute instead of in the
middle of a minute if the interval is set to 60 seconds. (#2123), see #2064
* `custom/menu`: Multiple menu modules per bar (#1907)
* `internal/backlight`: Support for changing the brightness through scrolling.
This may require additional changes to the system running polybar. (#1957)
* `internal/github`:
* `format-offline` for when the module cannot connect to the server (#1825),
see #1815
* Support for github enterprise instances. (#1841), see #1812
* `internal/network`: Support `Gbit/s` for `%linkspeed%` token. (#2055)
* `internal/pulseaudio`:
* `click-right` and `click-middle` keys (#1941)
* `%decibels%` token (#1894), see #1886
* `internal/xworkspaces`: Proper implementation for `label-occupied`. (#822),
see #874, #1444, #1033
**Fixes**
* Polybar not executing commands that produce output. (#1680), see #916
* Polybar froze until click commands finished executing (#2248)
* Polybar not properly working with mirrored monitors. (#1823), see #1192 and
#1794
* Unstable animation framerate (#1683), see #568
* Multiple modules of the same type caused click events not to be delivered to
the rigth one (#1907), see #1172
* config:
* Seemingly unrelated error messages when BOM character appears in config.
(#2166), see #2075
* Fall back to next possible config location if config file doesn't exist
(except if `--config` was used). (#2026), see #2016
* iconset: `fuzzy-match` chose first match, even if exact match was available.
(#2042), see #2041
* `custom/menu`: Spacing issue (#1656)
* `internal/alsa`: Volume didn't go over 100% (#2184), see #2173
* `internal/backlight`: Use amdgpu workaround for all devices starting with
`amdgpu_bl`. (#2122)
* `internal/battery`: Battery not marked as full if over `full-at` percent.
(#2019), see #1622
* `internal/cpu`: More accurate cpu load calculation. (#1955)
* `internal/github`: Outdated GitHub API authentication. (#2029), see #2002
* `internal/memory`: Use the correct size prefixes (#2211), see #2023
* `internal/network`:
* Wrong up- and downspeed values for non-integer intervals. (#2219)
* tun/tap interfaces didn't query their IP addresses. (#1990), see #1986
* Don't crash module if linkspeed cannot be queried. (#1772), see #1211
* `internal/temperature`:
* `format-warn` was not used if the temperature was *exactly*
`warn-temperature`. (#1897)
* `internal/xworkspaces`:
* Multi-monitor issue (#1929), see #1764, #1849
* Module sometimes showed too many workspaces (#1984), see #1983
* build:
* xpp submodule doesn't work with python 3.9 (polybar/xpp#26)
* CMake 3.17+ developer warnings (#2089, polybar/xpp#24, polybar/xpp#25)
* gtest compilation failure (#1993), see google/googletest#2678
* Compilation issue in GCC 6. (#1953)
This is the next step to merge #1237 in stages.
Currently there are barely any restrictions on how the config can be
written. This causes things like config files with DOS line endings to
not be parsed properly (#1366) because polybar splits by
\nand whenparsing section headers, it can't deal with the
\rat the end of theline and thus doesn't recognize any section headers.
With this PR we introduce some rules as to what characters are allowed
in section names and keys.
Note: When talking about spaces I refer to any character for which
isspace()returnstrue.The rules are as follows:
of there characters:
"'=;#[](){}:.$\%parsing
;or#and last for the whole line. Thewhole line will be ignored by the parser. You cannot start a comment at
the end of a line.
[HEADER_NAME]KEY_NAME{SPACES}={SPACES}VALUE_STRINGwhere{SPACES}represents anynumber of spaces.
VALUE_STRINGcan contain any characters. If it issurrounded with double quotes (
"), those quotes will be removed,this can be used to add spaces to the beginning or end of the value
This will introduce the following breaking changes because of how
underdefined the config syntax was before:
key = ""will get treated as an empty string instead of the literal string""errors.
self,root,BAR. Because they have a special meaning inside references and so a section[root]can never be referenced.This replaces the current parser implementation with a new more robust
one that will later be expanded to also check for dependency cycles and allow for values that contain references mixed with other strings.
This PR also now expands the config paths given over the command line so that
--config=~/.config/polybar/configresolves properly.EDIT:
Closes #1032
Closes #1694