Skip to content

Commit 63e90c3

Browse files
feat(statusline): Add visual burn rate indicators to statusline for improved accessibility (#516)
Co-authored-by: ryoppippi <[email protected]>
1 parent 8b8e12a commit 63e90c3

3 files changed

Lines changed: 107 additions & 6 deletions

File tree

‎config-schema.json‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,18 @@
716716
"markdownDescription": "Use cached pricing data for Claude models instead of fetching from API",
717717
"default": true
718718
},
719+
"visualBurnRate": {
720+
"type": "string",
721+
"enum": [
722+
"off",
723+
"emoji",
724+
"text",
725+
"emoji-text"
726+
],
727+
"description": "Controls the visualization of the burn rate status",
728+
"markdownDescription": "Controls the visualization of the burn rate status",
729+
"default": "off"
730+
},
719731
"cache": {
720732
"type": "boolean",
721733
"description": "Enable cache for status line output (default: true)",

‎docs/guide/statusline.md‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,22 @@ If you need the latest pricing data from LiteLLM API, you can explicitly enable
4444
}
4545
```
4646

47+
### With Visual Burn Rate (Optional)
48+
49+
You can enhance the burn rate display with visual indicators:
50+
51+
```json
52+
{
53+
"statusLine": {
54+
"type": "command",
55+
"command": "bun x ccusage statusline --visual-burn-rate emoji", // Add emoji indicators
56+
"padding": 0
57+
}
58+
}
59+
```
60+
61+
See [Visual Burn Rate](#visual-burn-rate) section for all available options.
62+
4763
## Output Format
4864

4965
The statusline displays a compact, single-line summary:
@@ -62,6 +78,7 @@ The statusline displays a compact, single-line summary:
6278
- Green text: Normal (< 2,000 tokens/min)
6379
- Yellow text: Moderate (2,000-5,000 tokens/min)
6480
- Red text: High (> 5,000 tokens/min)
81+
- Optional visual status indicators (see [Visual Burn Rate](#visual-burn-rate))
6582
- **Context Usage** (`🧠 25,000 (12%)`): Shows input tokens with percentage of context limit:
6683
- Green text: Low usage (< 50% by default)
6784
- Yellow text: Medium usage (50-80% by default)
@@ -126,6 +143,43 @@ export CCUSAGE_CONTEXT_LOW_THRESHOLD=90 # Would be >= MEDIUM (80), so bot
126143
export CCUSAGE_CONTEXT_MEDIUM_THRESHOLD=30 # Would be <= LOW (50), so both reset
127144
```
128145

146+
### Visual Burn Rate
147+
148+
You can enhance the burn rate display with visual status indicators using the `--visual-burn-rate` option:
149+
150+
```bash
151+
# Add to your settings.json command
152+
bun x ccusage statusline --visual-burn-rate emoji
153+
```
154+
155+
**Available options:**
156+
157+
- `off` (default): No visual indicators, only colored text
158+
- `emoji`: Add emoji indicators (🟢/⚠️/🚨)
159+
- `text`: Add text status in parentheses (Normal/Moderate/High)
160+
- `emoji-text`: Combine both emoji and text indicators
161+
162+
**Examples:**
163+
164+
```bash
165+
# Default (off)
166+
🔥 $0.12/hr
167+
168+
# With emoji
169+
🔥 $0.12/hr 🟢
170+
171+
# With text
172+
🔥 $0.12/hr (Normal)
173+
174+
# With both emoji and text
175+
🔥 $0.12/hr 🟢 (Normal)
176+
```
177+
178+
**Status Indicators:**
179+
- 🟢 Normal (Green)
180+
- ⚠️ Moderate (Yellow)
181+
- 🚨 High (Red)
182+
129183
## Troubleshooting
130184

131185
### No Output Displayed

‎src/commands/statusline.ts‎

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import type { Formatter } from 'picocolors/types';
12
import { mkdirSync } from 'node:fs';
23
import { tmpdir } from 'node:os';
34
import { join } from 'node:path';
@@ -68,6 +69,8 @@ type SemaphoreType = {
6869
pid?: number;
6970
};
7071

72+
const visualBurnRateChoices = ['off', 'emoji', 'text', 'emoji-text'] as const;
73+
7174
export const statuslineCommand = define({
7275
name: 'statusline',
7376
description: 'Display compact status line for Claude Code hooks with hybrid time+file caching (Beta)',
@@ -77,6 +80,15 @@ export const statuslineCommand = define({
7780
...sharedArgs.offline,
7881
default: true, // Default to offline mode for faster performance
7982
},
83+
visualBurnRate: {
84+
type: 'enum',
85+
choices: visualBurnRateChoices,
86+
description: 'Controls the visualization of the burn rate status',
87+
default: 'off',
88+
short: 'vb',
89+
negatable: false,
90+
toKebab: true,
91+
},
8092
cache: {
8193
type: 'boolean',
8294
description: 'Enable cache for status line output (default: true)',
@@ -279,17 +291,40 @@ export const statuslineCommand = define({
279291
const burnRate = calculateBurnRate(activeBlock);
280292
const burnRateInfo = burnRate != null
281293
? (() => {
294+
const renderEmojiStatus = ctx.values.visualBurnRate === 'emoji' || ctx.values.visualBurnRate === 'emoji-text';
295+
const renderTextStatus = ctx.values.visualBurnRate === 'text' || ctx.values.visualBurnRate === 'emoji-text';
282296
const costPerHour = burnRate.costPerHour;
283297
const costPerHourStr = `${formatCurrency(costPerHour)}/hr`;
284298

285-
// Apply color based on burn rate (tokens per minute non-cache)
286-
const coloredBurnRate = burnRate.tokensPerMinuteForIndicator < 2000
287-
? pc.green(costPerHourStr) // Normal
299+
type BurnStatus = 'normal' | 'moderate' | 'high';
300+
301+
const burnStatus: BurnStatus = burnRate.tokensPerMinuteForIndicator < 2000
302+
? 'normal'
288303
: burnRate.tokensPerMinuteForIndicator < 5000
289-
? pc.yellow(costPerHourStr) // Moderate
290-
: pc.red(costPerHourStr); // High
304+
? 'moderate'
305+
: 'high';
306+
307+
const burnStatusMappings: Record<BurnStatus, { emoji: string; textValue: string; coloredString: Formatter }> = {
308+
normal: { emoji: '🟢', textValue: 'Normal', coloredString: pc.green },
309+
moderate: { emoji: '⚠️', textValue: 'Moderate', coloredString: pc.yellow },
310+
high: { emoji: '🚨', textValue: 'High', coloredString: pc.red },
311+
};
312+
313+
const { emoji, textValue, coloredString } = burnStatusMappings[burnStatus];
314+
315+
const burnRateOutputSegments: string[] = [
316+
coloredString(costPerHourStr),
317+
];
318+
319+
if (renderEmojiStatus) {
320+
burnRateOutputSegments.push(emoji);
321+
}
322+
323+
if (renderTextStatus) {
324+
burnRateOutputSegments.push(coloredString(`(${textValue})`));
325+
}
291326

292-
return ` | 🔥 ${coloredBurnRate}`;
327+
return ` | 🔥 ${burnRateOutputSegments.join(' ')}`;
293328
})()
294329
: '';
295330

0 commit comments

Comments
 (0)