Skip to content

feat(quota): add {elapsed_bar} placeholder for time passed in the window - #146

Open
samhvw8 wants to merge 2 commits into
Haleclipse:masterfrom
samhvw8:feat/quota-left-bar
Open

samhvw8 wants to merge 2 commits into
Haleclipse:masterfrom
samhvw8:feat/quota-left-bar

Conversation

@samhvw8

@samhvw8 samhvw8 commented Nov 19, 2026 •

Copy link
Copy Markdown

What

Adds a {elapsed_bar} placeholder to the text templates of quota.5h and quota.7d (and the spend window). It draws the share of the window that has already passed as a small bar, so the reset countdown is readable at a glance:

◷ ▀▀▀▀▀▀▀▀▀▀▀▀ 5h 42% · ▰▰▰▱▱▱ resets in 1h53m at Fri 00:23 ⇣20%
◷ ▀▀▀▀▀▀▀▀▀▀▀▀ 7d 93% · ▰▰▰▱▱▱ resets in 3d1h at Mon 00:23 ⇡37%
  • {elapsed_bar} draws 5 cells; {elapsed_bar:N} draws N cells (1 to 64).
  • It reuses the item's bar glyphs and the glyph tier ([==---] in ASCII), so there is no second bar system.
  • When the reading has no elapsed value (no reset time), the field is empty, so an optional [ … ] group drops it. An invalid count (0, 65, abc) also renders as empty.
  • Opt-in: the built-in templates do not change, so existing configs render exactly as before.

Example:

{ metric = "quota.7d", cells = 12, format = "7d {pct}%[ · {elapsed_bar:6} resets in {left}][ at {reset}]" }

How

  • template::render_with takes a resolver for inline fields that render as styled pieces instead of plain text.
  • widgets::render resolves elapsed_bar / elapsed_bar:N from Reading::elapsed, through a bar_cells helper split out of bar().
  • README and README.zh describe the placeholder next to the pace bar paragraph.

Checks

  • cargo fmt -- --check, cargo clippy --all-targets -- -D warnings: clean.
  • cargo test: 205 unit + 2 snapshot tests pass. New tests cover 0%, 60% and 100% elapsed, a missing reset time, custom and invalid cell counts, ASCII and eighths glyphs, and that the default quota templates still equal the literal built-in strings.

Summary by Sourcery

Add opt-in elapsed-time bars to quota window templates without changing existing default output.

New Features:

  • Add configurable {elapsed_bar} and {elapsed_bar:N} placeholders to quota and spend-window templates to visualize elapsed window time.

Enhancements:

  • Support styled inline template fields while preserving existing built-in quota templates and bar glyph configurations.
  • Handle missing elapsed values and invalid cell counts by omitting the elapsed bar, including within optional template groups.

Documentation:

  • Document the elapsed-bar placeholders and configuration example in the English and Chinese READMEs.

Tests:

  • Add coverage for elapsed-bar progress, custom and invalid cell counts, missing reset times, glyph tiers, styling, and unchanged default templates.

@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

API

Extend template rendering with a resolver for inline fields that can produce styled pieces, while preserving the existing renderer as a no-extra-fields wrapper.

  • src/widgets/template.rs L50-56, L90-96, L105-120 (+1 small edits)

Implementation

Add elapsed-bar resolution to widget rendering and factor shared bar drawing into a helper so the inline bar uses the configured glyphs and tier.

  • src/widgets/mod.rs L158-198 (+3 small edits)

Register elapsed_bar as a supported field for quota windows and the spend window without changing built-in templates.

  • src/metrics/usage.rs L38-46, L107-116

Documentation

Document the elapsed-bar placeholder, its configurable cell count, and how it behaves when reset time is unavailable.

  • README.md L160-161
  • README.zh.md L160-161

Tests

Verify elapsed-bar rendering, missing and invalid fields, glyph variants, quota-field registration, and unchanged default templates.

  • src/metrics/usage.rs L451-507
  • src/widgets/mod.rs L458-606

Test that template rendering resolves extra styled fields and omits groups when a field is unavailable.

  • src/widgets/template.rs L201-219

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/metrics/usage.rs" line_range="452" />
<code_context>
+        let all = metrics();
+        let m5h = all.iter().find(|m| m.meta.id == "quota.5h").unwrap();
+        let m7d = all.iter().find(|m| m.meta.id == "quota.7d").unwrap();
+        assert_eq!(m5h.meta.templates, WINDOW_TEMPLATES);
+        assert!(m5h.meta.fields.contains(&"left_bar"));
+
</code_context>
<issue_to_address>
**Default template changes go unnoticed**

When `WINDOW_TEMPLATES` is changed along with the quota metadata, when `WINDOW_TEMPLATES` changes along with the quota metadata, `quota_windows_render_left_bar_and_keep_default_templates` compares `m5h.meta.templates` to that same production constant and passes, so changed built-in quota output goes undetected.

Compare the metric templates against a literal expected array of the unchanged defaults.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: src/metrics/usage.rs:452


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/metrics/usage.rs Resolved
@samhvw8 samhvw8 changed the title feat(quota): add {left_bar} placeholder for time passed in the window feat(quota): add {elapsed_bar} placeholder for time passed in the window Nov 19, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

@samhvw8

samhvw8 commented Nov 20, 2026

Copy link
Copy Markdown
Author

Hi @Haleclipse
can you take a look at this pr :D
have a nice day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant