diff --git a/custom_statusline.js b/custom_statusline.js index b971c2d..663cc69 100644 --- a/custom_statusline.js +++ b/custom_statusline.js @@ -74,20 +74,19 @@ process.stdin.on('end', () => { (data.model && data.model.id) || 'Claude'; + // --- Bar helper --- + const BAR_WIDTH = 8; + function makeBar(pct, color) { + const filled = Math.round((pct / 100) * BAR_WIDTH); + return `${color}` + '█'.repeat(filled) + `${DIM}` + '░'.repeat(BAR_WIDTH - filled) + `${color} ${pct}%${R}`; + } + // --- Context window usage --- const pct = Math.round( (data.context_window && data.context_window.used_percentage) || 0 ); - const barColor = pct >= 90 ? BAR_CRIT : pct >= 70 ? BAR_WARN : BAR_OK; - - const BAR_WIDTH = 10; - const filled = Math.round((pct / 100) * BAR_WIDTH); - const bar = - `${barColor}[` + - '='.repeat(filled) + - `${DIM}` + ' '.repeat(BAR_WIDTH - filled) + - `${barColor}] ${pct}%${R}`; + const bar = makeBar(pct, barColor); // --- 5h rate limit + cost --- const fiveHour = data.rate_limits && data.rate_limits.five_hour; @@ -99,13 +98,10 @@ process.stdin.on('end', () => { if (fiveHour) { const fivePct = Math.round(fiveHour.used_percentage); const fiveColor = fivePct >= 90 ? BAR_CRIT : fivePct >= 70 ? BAR_WARN : BAR_OK; - const fiveFilled = Math.round((fivePct / 100) * BAR_WIDTH); - const fiveBar = - `${fiveColor}[` + - '='.repeat(fiveFilled) + - `${DIM}` + ' '.repeat(BAR_WIDTH - fiveFilled) + - `${fiveColor}] ${fivePct}%${R}`; - parts.push(`5h ${fiveBar}`); + const resetDate = new Date(fiveHour.resets_at * 1000); + const hh = String(resetDate.getHours()).padStart(2, '0'); + const mm = String(resetDate.getMinutes()).padStart(2, '0'); + parts.push(`${hh}:${mm} ${makeBar(fivePct, fiveColor)}`); } if (totalCost) { parts.push(`${DIM}$${totalCost.toFixed(2)}${R}`);