Repository navigation
cpu_usage: apply thresholds to every displayed value - #563
Open
verpeteren wants to merge 3 commits into
Open
verpeteren wants to merge 3 commits into
verpeteren wants to merge 3 commits into
Conversation
No functional change. This prepares for applying the thresholds to each displayed value instead of to the whole line.
Color %usage and each %cpu<N> based on its own value instead of coloring the whole line based on the overall usage. The remaining text of the format is no longer colored. i3bar can only color a whole block, so this needs markup = "pango" there. Without it the whole block is still colored based on the overall usage.
Pad with blanks instead of a leading zero, so that the width of the output does not change when a value switches between 99% and 100%.
verpeteren
marked this pull request as ready for review
November 11, 2026 17:19
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
cpu_usagecurrently colors the whole line withcolor_degraded/color_badbased on the overall usage. With a format that shows many CPUs, that does not tell which CPU is busy, and a single busy CPU usually does not move the overall usage enough to color anything.This PR applies
degraded_thresholdandmax_thresholdto every displayed value on its own:%usageis colored based on the overall usage, each%cpu<N>based on the usage of that CPU.examples
config
screenshots
Commits
usage_color(): refactoring only, no functional change.%3dinstead of%02d, so the width of the output does not change when a value switches between 99% and 100%. This one is independent of the other two and can be dropped if it is not wanted.Behavior changes
format_above_threshold/format_above_degraded_thresholdare unchanged: they are still selected based on the overall usage.8%,42%,100%) instead of zero-padded to two (08%).Output formats
term,xmobarcolor()/endcolor()dzen2,lemonbarcolor()plus an explicit reset (^fg()/%{F-}), becauseendcolor()does not reset the color for these. This is kept local toprint_cpu_usage.c.i3barwithmarkup = "pango"<span foreground='…'>…</span>i3barwithout pango markupnoneBecause colored values are a lot longer than their visible width, the values are now written with
snprintfbounded by the buffer size. A value that does not fit is dropped.Open question (reason for the draft)
For
i3bar, per-value colors needmarkup = "pango"in thegeneralsection, which also changes how the formats of all other modules are parsed. Alternatives would be to set"markup": "pango"only on thecpu_usageblock (which breaks for bars that do not use a pango font), or to emit one block per value. I went with the opt-in because it cannot break existing setups, but I am happy to change it.Testing
ninja testpasses after each of the three commits.027-cpu-usage-colors(xmobaroutput) covers a degraded, a bad and an uncolored value. The expected outputs of010,011and022are updated for the three character padding.term,xmobar,dzen2,lemonbar,i3bar(with and without pango markup),noneand withcolors = false.%cpu<N>is Linux only, the%usagepath is shared.clang-format19; I did not haveclang-format-12(used by the CI) available.