@naarang/glancebar 1.0.9 → 1.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/cli.ts +170 -23
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naarang/glancebar",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "A customizable statusline for Claude Code - display calendar events, tasks, and more at a glance",
5
5
  "author": "Vishal Dubey",
6
6
  "license": "MIT",
package/src/cli.ts CHANGED
@@ -34,6 +34,11 @@ interface Config {
34
34
  showUsageLimits: boolean;
35
35
  show5HourLimit: boolean;
36
36
  show7DayLimit: boolean;
37
+ show7DaySonnetLimit: boolean;
38
+ show5HourResets: boolean;
39
+ show7DayResets: boolean;
40
+ show7DaySonnetResets: boolean;
41
+ resetsTimeFormat: "relative" | "absolute";
37
42
  usageLimitsCacheTTL: number; // In seconds, default 300 (5 min)
38
43
  }
39
44
 
@@ -62,6 +67,10 @@ interface UsageLimits {
62
67
  utilization: number; // Percentage (0-100)
63
68
  resets_at: string; // ISO timestamp
64
69
  };
70
+ seven_day_sonnet: {
71
+ utilization: number; // Percentage (0-100)
72
+ resets_at: string; // ISO timestamp
73
+ } | null; // null if not available in API response
65
74
  }
66
75
 
67
76
  interface UsageLimitsCache {
@@ -110,6 +119,11 @@ const DEFAULT_CONFIG: Config = {
110
119
  showUsageLimits: true,
111
120
  show5HourLimit: true,
112
121
  show7DayLimit: true,
122
+ show7DaySonnetLimit: true,
123
+ show5HourResets: false,
124
+ show7DayResets: false,
125
+ show7DaySonnetResets: false,
126
+ resetsTimeFormat: "relative",
113
127
  usageLimitsCacheTTL: 120, // 2 minutes
114
128
  };
115
129
 
@@ -229,19 +243,24 @@ async function fetchUsageLimitsFromAPI(): Promise<UsageLimits | null> {
229
243
 
230
244
  const data = await response.json();
231
245
 
232
- if (!data.five_hour || !data.seven_day) {
246
+ // Validate at least one limit exists
247
+ if (!data.five_hour && !data.seven_day && !data.seven_day_sonnet) {
233
248
  return null;
234
249
  }
235
250
 
236
251
  return {
237
- five_hour: {
252
+ five_hour: data.five_hour ? {
238
253
  utilization: data.five_hour.utilization || 0,
239
254
  resets_at: data.five_hour.resets_at || "",
240
- },
241
- seven_day: {
255
+ } : { utilization: 0, resets_at: "" },
256
+ seven_day: data.seven_day ? {
242
257
  utilization: data.seven_day.utilization || 0,
243
258
  resets_at: data.seven_day.resets_at || "",
244
- },
259
+ } : { utilization: 0, resets_at: "" },
260
+ seven_day_sonnet: data.seven_day_sonnet ? {
261
+ utilization: data.seven_day_sonnet.utilization || 0,
262
+ resets_at: data.seven_day_sonnet.resets_at || "",
263
+ } : null,
245
264
  };
246
265
  } catch {
247
266
  return null;
@@ -275,23 +294,71 @@ async function getUsageLimits(config: Config): Promise<UsageLimits | null> {
275
294
  return cache.data || null;
276
295
  }
277
296
 
297
+ // Helper function to format reset time
298
+ function formatResetTime(isoTimestamp: string, format: "relative" | "absolute"): string {
299
+ const resetDate = new Date(isoTimestamp);
300
+ const now = new Date();
301
+
302
+ if (format === "absolute") {
303
+ // Format as "Jan 30, 2:59 PM"
304
+ const dateStr = resetDate.toLocaleDateString([], { month: 'short', day: 'numeric' });
305
+ const timeStr = resetDate.toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' });
306
+ return `${dateStr}, ${timeStr}`;
307
+ } else {
308
+ // Relative: "in 2h 15m" or "in 4d 10h"
309
+ const diffMs = resetDate.getTime() - now.getTime();
310
+ if (diffMs <= 0) return "now";
311
+
312
+ const diffMinutes = Math.floor(diffMs / 60000);
313
+ const hours = Math.floor(diffMinutes / 60);
314
+ const minutes = diffMinutes % 60;
315
+
316
+ // If over 24 hours, show days
317
+ if (hours >= 24) {
318
+ const days = Math.floor(hours / 24);
319
+ const remainingHours = hours % 24;
320
+ if (remainingHours === 0) return `in ${days}d`;
321
+ return `in ${days}d ${remainingHours}h`;
322
+ }
323
+
324
+ if (hours === 0) return `in ${minutes}m`;
325
+ if (minutes === 0) return `in ${hours}h`;
326
+ return `in ${hours}h${minutes}m`;
327
+ }
328
+ }
329
+
278
330
  function formatUsageLimits(usageLimits: UsageLimits, config: Config): string | null {
279
331
  const parts: string[] = [];
280
332
 
281
- if (config.show5HourLimit) {
282
- const util = usageLimits.five_hour.utilization;
333
+ // Helper to format a single limit
334
+ const formatLimit = (label: string, utilization: number, resetsAt: string, showResets: boolean) => {
283
335
  let color = COLORS.green;
284
- if (util >= 80) color = COLORS.red;
285
- else if (util >= 50) color = COLORS.yellow;
286
- parts.push(`${color}5h: ${util.toFixed(0)}%${COLORS.reset}`);
336
+ if (utilization >= 80) color = COLORS.red;
337
+ else if (utilization >= 50) color = COLORS.yellow;
338
+
339
+ let text = `${label}: ${utilization.toFixed(0)}%`;
340
+ if (showResets && resetsAt) {
341
+ text += ` (${formatResetTime(resetsAt, config.resetsTimeFormat)})`;
342
+ }
343
+ return `${color}${text}${COLORS.reset}`;
344
+ };
345
+
346
+ // 5-hour limit
347
+ if (config.show5HourLimit) {
348
+ parts.push(formatLimit("5h", usageLimits.five_hour.utilization,
349
+ usageLimits.five_hour.resets_at, config.show5HourResets));
287
350
  }
288
351
 
352
+ // 7-day limit
289
353
  if (config.show7DayLimit) {
290
- const util = usageLimits.seven_day.utilization;
291
- let color = COLORS.green;
292
- if (util >= 80) color = COLORS.red;
293
- else if (util >= 50) color = COLORS.yellow;
294
- parts.push(`${color}7d: ${util.toFixed(0)}%${COLORS.reset}`);
354
+ parts.push(formatLimit("7d", usageLimits.seven_day.utilization,
355
+ usageLimits.seven_day.resets_at, config.show7DayResets));
356
+ }
357
+
358
+ // 7-day sonnet limit
359
+ if (config.show7DaySonnetLimit && usageLimits.seven_day_sonnet) {
360
+ parts.push(formatLimit("7d-sonnet", usageLimits.seven_day_sonnet.utilization,
361
+ usageLimits.seven_day_sonnet.resets_at, config.show7DaySonnetResets));
295
362
  }
296
363
 
297
364
  return parts.length > 0 ? parts.join(" | ") : null;
@@ -1196,10 +1263,15 @@ Usage:
1196
1263
  glancebar config --memory-usage <true|false> Show memory usage (default: false)
1197
1264
  glancebar config --zoho-tasks <true|false> Show Zoho tasks (default: true)
1198
1265
  glancebar config --max-tasks <number> Max tasks to show (default: 3)
1199
- glancebar config --show-usage-limits <true|false> Show usage limits from API (default: true)
1200
- glancebar config --show-5hour-limit <true|false> Show 5-hour window utilization (default: true)
1201
- glancebar config --show-7day-limit <true|false> Show 7-day window utilization (default: true)
1202
- glancebar config --usage-cache-ttl <seconds> API cache TTL in seconds (default: 120)
1266
+ glancebar config --show-usage-limits <true|false> Show usage limits from API (default: true)
1267
+ glancebar config --show-5hour-limit <true|false> Show 5-hour window utilization (default: true)
1268
+ glancebar config --show-7day-limit <true|false> Show 7-day window utilization (default: true)
1269
+ glancebar config --show-7day-sonnet-limit <true|false> Show 7-day Sonnet limit (default: true)
1270
+ glancebar config --show-5hour-resets <true|false> Show 5-hour reset time (default: false)
1271
+ glancebar config --show-7day-resets <true|false> Show 7-day reset time (default: false)
1272
+ glancebar config --show-7day-sonnet-resets <true|false> Show 7-day Sonnet reset time (default: false)
1273
+ glancebar config --resets-time-format <relative|absolute> Reset time display format (default: relative)
1274
+ glancebar config --usage-cache-ttl <seconds> API cache TTL in seconds (default: 120)
1203
1275
  glancebar config --reset Reset to default configuration
1204
1276
  glancebar setup Show setup instructions
1205
1277
  glancebar --version Show version
@@ -1722,6 +1794,76 @@ function handleConfig(args: string[]) {
1722
1794
  return;
1723
1795
  }
1724
1796
 
1797
+ // Handle --show-7day-sonnet-limit
1798
+ const show7DaySonnetIndex = args.indexOf("--show-7day-sonnet-limit");
1799
+ if (show7DaySonnetIndex !== -1) {
1800
+ const value = args[show7DaySonnetIndex + 1]?.toLowerCase();
1801
+ if (value !== "true" && value !== "false") {
1802
+ console.error("Error: --show-7day-sonnet-limit must be 'true' or 'false'");
1803
+ process.exit(1);
1804
+ }
1805
+ config.show7DaySonnetLimit = value === "true";
1806
+ saveConfig(config);
1807
+ console.log(`7-day Sonnet limit display ${value === "true" ? "enabled" : "disabled"}`);
1808
+ return;
1809
+ }
1810
+
1811
+ // Handle --show-5hour-resets
1812
+ const show5HourResetsIndex = args.indexOf("--show-5hour-resets");
1813
+ if (show5HourResetsIndex !== -1) {
1814
+ const value = args[show5HourResetsIndex + 1]?.toLowerCase();
1815
+ if (value !== "true" && value !== "false") {
1816
+ console.error("Error: --show-5hour-resets must be 'true' or 'false'");
1817
+ process.exit(1);
1818
+ }
1819
+ config.show5HourResets = value === "true";
1820
+ saveConfig(config);
1821
+ console.log(`5-hour reset time display ${value === "true" ? "enabled" : "disabled"}`);
1822
+ return;
1823
+ }
1824
+
1825
+ // Handle --show-7day-resets
1826
+ const show7DayResetsIndex = args.indexOf("--show-7day-resets");
1827
+ if (show7DayResetsIndex !== -1) {
1828
+ const value = args[show7DayResetsIndex + 1]?.toLowerCase();
1829
+ if (value !== "true" && value !== "false") {
1830
+ console.error("Error: --show-7day-resets must be 'true' or 'false'");
1831
+ process.exit(1);
1832
+ }
1833
+ config.show7DayResets = value === "true";
1834
+ saveConfig(config);
1835
+ console.log(`7-day reset time display ${value === "true" ? "enabled" : "disabled"}`);
1836
+ return;
1837
+ }
1838
+
1839
+ // Handle --show-7day-sonnet-resets
1840
+ const show7DaySonnetResetsIndex = args.indexOf("--show-7day-sonnet-resets");
1841
+ if (show7DaySonnetResetsIndex !== -1) {
1842
+ const value = args[show7DaySonnetResetsIndex + 1]?.toLowerCase();
1843
+ if (value !== "true" && value !== "false") {
1844
+ console.error("Error: --show-7day-sonnet-resets must be 'true' or 'false'");
1845
+ process.exit(1);
1846
+ }
1847
+ config.show7DaySonnetResets = value === "true";
1848
+ saveConfig(config);
1849
+ console.log(`7-day Sonnet reset time display ${value === "true" ? "enabled" : "disabled"}`);
1850
+ return;
1851
+ }
1852
+
1853
+ // Handle --resets-time-format
1854
+ const resetsTimeFormatIndex = args.indexOf("--resets-time-format");
1855
+ if (resetsTimeFormatIndex !== -1) {
1856
+ const value = args[resetsTimeFormatIndex + 1]?.toLowerCase();
1857
+ if (value !== "relative" && value !== "absolute") {
1858
+ console.error("Error: --resets-time-format must be 'relative' or 'absolute'");
1859
+ process.exit(1);
1860
+ }
1861
+ config.resetsTimeFormat = value as "relative" | "absolute";
1862
+ saveConfig(config);
1863
+ console.log(`Resets time format set to ${value}`);
1864
+ return;
1865
+ }
1866
+
1725
1867
  // Handle --usage-cache-ttl
1726
1868
  const cacheTTLIndex = args.indexOf("--usage-cache-ttl");
1727
1869
  if (cacheTTLIndex !== -1) {
@@ -1772,10 +1914,15 @@ Zoho Tasks:
1772
1914
  Max tasks to show: ${config.maxTasksToShow}
1773
1915
 
1774
1916
  Usage Limits:
1775
- Show usage limits: ${config.showUsageLimits ? "enabled" : "disabled"}
1776
- Show 5-hour limit: ${config.show5HourLimit ? "enabled" : "disabled"}
1777
- Show 7-day limit: ${config.show7DayLimit ? "enabled" : "disabled"}
1778
- Cache TTL: ${config.usageLimitsCacheTTL} seconds
1917
+ Show usage limits: ${config.showUsageLimits ? "enabled" : "disabled"}
1918
+ Show 5-hour limit: ${config.show5HourLimit ? "enabled" : "disabled"}
1919
+ Show 7-day limit: ${config.show7DayLimit ? "enabled" : "disabled"}
1920
+ Show 7-day Sonnet limit: ${config.show7DaySonnetLimit ? "enabled" : "disabled"}
1921
+ Show 5-hour resets: ${config.show5HourResets ? "enabled" : "disabled"}
1922
+ Show 7-day resets: ${config.show7DayResets ? "enabled" : "disabled"}
1923
+ Show 7-day Sonnet resets: ${config.show7DaySonnetResets ? "enabled" : "disabled"}
1924
+ Resets time format: ${config.resetsTimeFormat}
1925
+ Cache TTL: ${config.usageLimitsCacheTTL} seconds
1779
1926
  `);
1780
1927
  }
1781
1928