From d044ee140e8e075d43281c80cf04998cffae3f3e Mon Sep 17 00:00:00 2001 From: j4rviscmd Date: Mon, 16 Mar 2026 21:25:01 +0900 Subject: [PATCH 1/2] feat: add display mode setting for usage/remaining tokens Add zaiUsage.displayMode configuration option that allows users to choose between displaying token usage (e.g. 75.3%) or remaining tokens (e.g. 24.7%) in the status bar. Changes: - package.json: Add displayMode enum property with "usage" and "remaining" options - src/extension.ts: Implement display percentage calculation based on displayMode setting - Add displayMode to configuration change listeners for dynamic updates - Update tooltip text to reflect current display mode --- package.json | 10 ++++++++++ src/extension.ts | 32 ++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 9b62d3f..398929d 100644 --- a/package.json +++ b/package.json @@ -71,6 +71,16 @@ "type": "number", "default": 10000, "description": "Priority of the z.ai Usage item in the status bar (higher = further left among right-aligned items). Change takes effect after reloading the window." + }, + "zaiUsage.displayMode": { + "type": "string", + "enum": ["usage", "remaining"], + "default": "usage", + "enumDescriptions": [ + "Display token usage (e.g. 75.3%)", + "Display remaining tokens (e.g. 24.7%)" + ], + "description": "Whether to display token usage or remaining tokens in the status bar." } } } diff --git a/src/extension.ts b/src/extension.ts index 96bfdb1..848b2d1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -380,11 +380,30 @@ export function activate(context: vscode.ExtensionContext): void { statusBarItem.command = undefined; const refreshSec = getRefreshInterval() / 1000; const resetStr = formatResetTime(usage.nextResetTime); + + // Get display mode setting (default: "usage") + const displayMode = vscode.workspace + .getConfiguration("zaiUsage") + .get("displayMode", "usage"); + + // Calculate display percentage based on display mode + const isRemaining = displayMode === "remaining"; + const displayPercentage = isRemaining + ? Math.round((100 - usage.percentage) * 10) / 10 + : usage.percentage; + const suffix = resetStr - ? `${usage.percentage}% ${resetStr}` - : `${usage.percentage}%`; + ? `${displayPercentage}% ${resetStr}` + : `${displayPercentage}%`; statusBarItem.text = getLabel(suffix); - statusBarItem.tooltip = `z.ai token usage: ${usage.percentage}%${resetStr ? ` — resets in ${resetStr.replace(/[()]/g, "")}` : ""} (auto-refreshes every ${refreshSec}s)`; + + // Build tooltip text + const resetTooltip = resetStr + ? ` — resets in ${resetStr.replace(/[()]/g, "")}` + : ""; + statusBarItem.tooltip = + `z.ai token ${displayMode}: ${displayPercentage}%${resetTooltip} ` + + `(auto-refreshes every ${refreshSec}s)`; } if (apiCalled) { @@ -462,8 +481,8 @@ export function activate(context: vscode.ExtensionContext): void { /** * Listens for workspace configuration changes and re-applies them immediately. * - * When `zaiUsage.refreshInterval` or `zaiUsage.useIcon` changes, the status bar - * is refreshed and the polling interval is restarted so the new settings take + * When `zaiUsage.refreshInterval`, `zaiUsage.useIcon`, or `zaiUsage.displayMode` changes, + * the status bar is refreshed and the polling interval is restarted so the new settings take * effect without requiring a window reload. * * When `zaiUsage.statusBarPriority` changes, the user is notified that a window @@ -473,7 +492,8 @@ export function activate(context: vscode.ExtensionContext): void { vscode.workspace.onDidChangeConfiguration((e) => { if ( e.affectsConfiguration("zaiUsage.refreshInterval") || - e.affectsConfiguration("zaiUsage.useIcon") + e.affectsConfiguration("zaiUsage.useIcon") || + e.affectsConfiguration("zaiUsage.displayMode") ) { updateStatusBar(); startInterval(); From 69df11f9ed1194936aa54c3fe7cf86c55700558d Mon Sep 17 00:00:00 2001 From: j4rviscmd Date: Mon, 16 Mar 2026 21:32:09 +0900 Subject: [PATCH 2/2] docs: update README with displayMode setting Add documentation for the new zaiUsage.displayMode configuration option: - Update Features section to mention remaining tokens display - Add displayMode to Settings table - Add remaining mode example to Status bar examples - Add note about displayMode configuration --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 29c33b7..ec90cfe 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ ## Features -- Shows token quota usage (e.g. `45% (2h30m)`) in the status bar +- Shows token quota usage (e.g. `45% (2h30m)`) or remaining tokens (e.g. `55% (2h30m)`) in the status bar - Displays time remaining until quota resets when available - Automatically refreshes at a configurable interval - Secure API key storage via VS Code Secret Storage @@ -26,10 +26,11 @@ | ------------------------------ | --------------- | | Authenticated, usage available | `⬡ 45% (2h30m)` | | Authenticated, no reset time | `⬡ 45%` | +| Authenticated, remaining mode | `⬡ 55% (2h30m)` | | API key not set | `⬡ Set API Key` | | Error / fetch failed | `⬡ -` | -> The `⬡` icon is the z.ai icon. Set `zaiUsage.useIcon: false` to display `z.ai:` as a text prefix instead. +> The `⬡` icon is the z.ai icon. Set `zaiUsage.useIcon: false` to display `z.ai:` as a text prefix instead. Set `zaiUsage.displayMode: "remaining"` to show remaining tokens instead of usage. ## Setup @@ -47,10 +48,11 @@ ## Settings -| Setting | Type | Default | Description | -| -------------------------- | --------- | ------- | -------------------------------------------------- | -| `zaiUsage.refreshInterval` | `number` | `60` | Data refresh interval in seconds | -| `zaiUsage.useIcon` | `boolean` | `true` | Use z.ai icon (`⬡`) instead of text prefix `z.ai:` | +| Setting | Type | Default | Description | +| -------------------------- | --------- | ------- | ------------------------------------------------------------------------------------ | +| `zaiUsage.refreshInterval` | `number` | `60` | Data refresh interval in seconds | +| `zaiUsage.useIcon` | `boolean` | `true` | Use z.ai icon (`⬡`) instead of text prefix `z.ai:` | +| `zaiUsage.displayMode` | `string` | `usage` | Display mode: `"usage"` (e.g. `75.3%`) or `"remaining"` (e.g. `24.7%`) in status bar | ## Requirements