Skip to content

Commit 2330284

Browse files
fix: clarify usage time format — show 'resets in' instead of ambiguous elapsed/total (#244)
* fix: clarify usage time format — show 'resets in' instead of ambiguous elapsed/total Fixes #240 The format `(2h 43m / 5h)` was confusing because it mimics the common `(elapsed / total)` pattern, but actually showed time remaining until reset. Changed to `(resets in 2h 43m)` which is unambiguous. Before: `Usage █░░░░░░░░░ 7% (2h 43m / 5h)` After: `Usage █░░░░░░░░░ 7% (resets in 2h 43m)` * test: cover usage reset wording --------- Co-authored-by: d 🔹 <258577966+voidborne-d@users.noreply.github.com> Co-authored-by: Jarrod Watts <jarrod@cubelabs.xyz>
1 parent 618ae8d commit 2330284

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/render/lines/usage.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ export function renderUsageLine(ctx: RenderContext): string | null {
4949
const usageBarEnabled = display?.usageBarEnabled ?? true;
5050
const fiveHourPart = usageBarEnabled
5151
? (fiveHourReset
52-
? `${quotaBar(fiveHour ?? 0, getAdaptiveBarWidth(), colors)} ${fiveHourDisplay} (${fiveHourReset} / 5h)`
52+
? `${quotaBar(fiveHour ?? 0, getAdaptiveBarWidth(), colors)} ${fiveHourDisplay} (resets in ${fiveHourReset})`
5353
: `${quotaBar(fiveHour ?? 0, getAdaptiveBarWidth(), colors)} ${fiveHourDisplay}`)
5454
: (fiveHourReset
55-
? `5h: ${fiveHourDisplay} (${fiveHourReset})`
55+
? `5h: ${fiveHourDisplay} (resets in ${fiveHourReset})`
5656
: `5h: ${fiveHourDisplay}`);
5757

5858
const sevenDayThreshold = display?.sevenDayThreshold ?? 80;
@@ -64,10 +64,10 @@ export function renderUsageLine(ctx: RenderContext): string | null {
6464
const sevenDayReset = formatResetTime(ctx.usageData.sevenDayResetAt);
6565
const sevenDayPart = usageBarEnabled
6666
? (sevenDayReset
67-
? `${quotaBar(sevenDay, getAdaptiveBarWidth(), colors)} ${sevenDayDisplay} (${sevenDayReset} / 7d)`
67+
? `${quotaBar(sevenDay, getAdaptiveBarWidth(), colors)} ${sevenDayDisplay} (resets in ${sevenDayReset})`
6868
: `${quotaBar(sevenDay, getAdaptiveBarWidth(), colors)} ${sevenDayDisplay}`)
6969
: (sevenDayReset
70-
? `7d: ${sevenDayDisplay} (${sevenDayReset})`
70+
? `7d: ${sevenDayDisplay} (resets in ${sevenDayReset})`
7171
: `7d: ${sevenDayDisplay}`);
7272
return `${label} ${fiveHourPart} | ${sevenDayPart}${syncingSuffix}`;
7373
}

tests/render.test.js

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,7 @@ test('renderSessionLine shows 5hr reset countdown', () => {
686686
test('renderUsageLine shows reset countdown in days when >= 24 hours', () => {
687687
const ctx = baseContext();
688688
const resetTime = new Date(Date.now() + (151 * 3600000) + (59 * 60000)); // 6d 7h 59m from now
689+
ctx.config.display.usageBarEnabled = true;
689690
ctx.usageData = {
690691
planName: 'Pro',
691692
fiveHour: 45,
@@ -696,7 +697,7 @@ test('renderUsageLine shows reset countdown in days when >= 24 hours', () => {
696697
const line = renderUsageLine(ctx);
697698
assert.ok(line, 'should render usage line');
698699
const plain = stripAnsi(line);
699-
assert.ok(/\(\d+d( \d+h)?\)/.test(plain), `expected day/hour reset format, got: ${plain}`);
700+
assert.ok(plain.includes('(resets in 6d 7h)'), `expected bar-mode reset wording, got: ${plain}`);
700701
assert.ok(!plain.includes('151h'), `should avoid raw hour format for long durations: ${plain}`);
701702
});
702703

@@ -716,7 +717,27 @@ test('renderUsageLine shows 7d reset countdown in text-only mode', () => {
716717
const line = stripAnsi(renderUsageLine(ctx));
717718
assert.ok(line.includes('5h: 45%'), `should include 5h text-only usage: ${line}`);
718719
assert.ok(line.includes('7d: 85%'), `should include 7d text-only usage: ${line}`);
719-
assert.ok(line.includes('(1d 4h)'), `should include 7d reset countdown in text-only mode: ${line}`);
720+
assert.ok(line.includes('(resets in 1d 4h)'), `should include 7d reset countdown in text-only mode: ${line}`);
721+
});
722+
723+
test('renderUsageLine shows 7d reset countdown in bar mode when above threshold', () => {
724+
const ctx = baseContext();
725+
const resetTime = new Date(Date.now() + (28 * 60 * 60 * 1000)); // 1d 4h from now
726+
ctx.config.display.usageBarEnabled = true;
727+
ctx.config.display.sevenDayThreshold = 80;
728+
ctx.usageData = {
729+
planName: 'Pro',
730+
fiveHour: 45,
731+
sevenDay: 85,
732+
fiveHourResetAt: null,
733+
sevenDayResetAt: resetTime,
734+
};
735+
736+
const line = stripAnsi(renderUsageLine(ctx));
737+
assert.ok(line.includes('45%'), `should include 5h percentage in bar mode: ${line}`);
738+
assert.ok(line.includes('85%'), `should include 7d percentage: ${line}`);
739+
assert.ok(line.includes('(resets in 1d 4h)'), `should include 7d reset countdown in bar mode: ${line}`);
740+
assert.ok(line.includes('|'), `should render both usage windows above the threshold: ${line}`);
720741
});
721742

722743
test('renderSessionLine displays limit reached warning', () => {

0 commit comments

Comments
 (0)