Skip to content

refactor(timers): route the timer bars through the shared progress helper - #543

Open
zachthedev wants to merge 1 commit into
sirmalloc:mainfrom
zachthedev:fix-timer-bar-rounding
Open

refactor(timers): route the timer bars through the shared progress helper#543
zachthedev wants to merge 1 commit into
sirmalloc:mainfrom
zachthedev:fix-timer-bar-rounding

Conversation

@zachthedev

Copy link
Copy Markdown
Contributor

shared/progress-bar.ts fills with Math.round. BlockTimer.ts,
BlockResetTimer.ts and WeeklyResetTimer.ts each carried a byte-identical
private makeTimerProgressBar that fills with Math.floor. Six other widgets
already use the shared helper, as do makeSliderBar and makeUsageProgressBar,
so floor was the only outlier in the repo.

The three copies are gone and all six call sites use the shared helper.

This changes rendered output. The bar shifts by one cell for roughly half of
all percentages, whenever the fill lands past the half-cell mark. BlockTimer's
own preview value is the clearest example: 73.9% of 32 cells is 23.648, so it
goes from 23 filled cells to 24. That widget already called the round-based
makeSliderBar for slider mode, so it was applying two rounding rules across its
own display modes.

Each of the three widgets gains a case pinning a value where floor and round
disagree (10% of 16, 73.9% of 32, 35% of 16). Putting Math.floor back in the
shared helper fails all three, so they are not retrofitted to current output.
Every pre-existing bar assertion is invariant under both rules, which is why none
of them needed touching.

The shared helper's cursor option stays inert here: all six timer call sites pass
no options, so cursorPos is -1 and the loop reproduces the old
'█'.repeat(filled) + '░'.repeat(width - filled) exactly. Bar length is still
exactly width, so truncation, powerline width math and flex separators see no
change.

Tested: bun run lint clean; bun test 1870 pass, plus the one
global-command-resolution failure main already has on this host.

…lper

BlockTimer, BlockResetTimer and WeeklyResetTimer each carried a private
makeTimerProgressBar that filled with Math.floor. The shared helper in
shared/progress-bar.ts fills with Math.round, as do makeSliderBar and
makeUsageProgressBar, so floor was the only outlier in the repo and
BlockTimer applied both rules across its own display modes.

The three copies are gone and all six call sites use the shared helper.

This shifts the rendered bar by one cell for roughly half of all
percentages, whenever the fill lands past the half-cell mark. BlockTimer's
own preview at 73.9% of 32 cells is 23.648, so it goes from 23 filled
cells to 24. Each widget gains a case pinning a value where the two
rounding rules disagree.
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