diff --git a/custom_statusline.js b/custom_statusline.js index e6c5291..b971c2d 100644 --- a/custom_statusline.js +++ b/custom_statusline.js @@ -6,6 +6,8 @@ 'use strict'; const { execSync } = require('child_process'); +const fs = require('fs'); +const path = require('path'); const os = require('os'); const R = '\x1b[0m'; @@ -25,6 +27,10 @@ process.stdin.on('end', () => { let data = {}; try { if (input.trim()) data = JSON.parse(input); } catch (_) {} + try { + fs.writeFileSync(path.join(os.tmpdir(), 'statusline_data.json'), JSON.stringify(data, null, 2)); + } catch (_) {} + // --- Directory --- const cwd = (data.workspace && data.workspace.current_dir) || @@ -83,11 +89,36 @@ process.stdin.on('end', () => { `${DIM}` + ' '.repeat(BAR_WIDTH - filled) + `${barColor}] ${pct}%${R}`; + // --- 5h rate limit + cost --- + const fiveHour = data.rate_limits && data.rate_limits.five_hour; + const totalCost = data.cost && data.cost.total_cost_usd; + + let usageSegment = null; + if (fiveHour || totalCost) { + const parts = []; + 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}`); + } + if (totalCost) { + parts.push(`${DIM}$${totalCost.toFixed(2)}${R}`); + } + usageSegment = parts.join(' '); + } + // --- Assemble --- const segments = [`${CYAN}${displayDir}${R}`]; if (gitBranch !== null) segments.push(`${GREEN}${gitBranch}${R}`); segments.push(`${MAGENTA}${model}${R}`); segments.push(bar); + if (usageSegment !== null) segments.push(usageSegment); process.stdout.write(segments.join(SEP) + '\n'); });