feat(usage): budget-aware coloring for the Extra Usage widgets#468
Open
zachthedev wants to merge 2 commits into
Open
feat(usage): budget-aware coloring for the Extra Usage widgets#468zachthedev wants to merge 2 commits into
zachthedev wants to merge 2 commits into
Conversation
Adds an optional Widget.getDynamicColor(item, context) hook so a widget can override its foreground color from live data. The renderer prefers it over the configured color at both per-widget color sites (normal and powerline); the global overrideForegroundColor still wins, and widgets that do not implement the hook are unaffected. The Extra Usage widgets (used, remaining, utilization) opt in via a (b) toggle and the budgetColors metadata flag and shift green to yellow to red as the monthly budget nears exhaustion (warn at 75 percent, critical at 90 percent utilization). The three tiers default to plain green/yellow/red and are overridable via budgetColorOk/Warn/Crit hexes. Default behavior is unchanged. Refs sirmalloc#467.
A budget-color suite (threshold escalation, custom hex overrides, the opt-in toggle, the (b) keybind and editor modifier, and each Extra Usage widget getDynamicColor) plus the three keybind-assertion updates for the new bind.
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
Implements #467: optional budget-aware coloring for the three Extra Usage widgets
(
extra-usage-used,extra-usage-remaining,extra-usage-utilization), so the value visiblyshifts color as you approach your monthly spend limit instead of sitting in one static color.
Design
getDynamicColor(item, context): string | undefined(src/types/Widget.ts).A widget can override its own foreground color from live render data.
item.color ?? defaultColorat both per-widget color sites (the normalpath and the powerline path). The global
overrideForegroundColorstill takes precedence, so existingprecedence is unchanged, and any widget that does not implement the hook renders exactly as before.
warn threshold, yellow in the warn band, red at the critical threshold and above.
Opt-in and configuration
(b)udget colorskeybind in the editor (it sets abudgetColorsmetadata flag). With the flag off, the widget renders in its static configured colorexactly as today.
green/yellow/redand are each overridable per widgetvia metadata (
budgetColorOk/budgetColorWarn/budgetColorCrit), accepting the same colorformats as
item.color(named,ansi256:N,hex:RRGGBB).Default behavior unchanged
Without the opt-in flag, every widget renders exactly as it does now: the dynamic color resolves to
undefinedand the renderer falls through to the existingitem.color ?? defaultColor.Tests
budget-colorsuite: threshold escalation, custom hex overrides, the opt-in toggle, the keybindand editor modifier, and each widget's
getDynamicColor.(b)bind.Notes
Happy to split into two commits for review (interface + renderer hook, then the widget implementations)
if you would prefer to take it in pieces.
Closes #467