@naarang/glancebar 1.0.3 → 1.0.5
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.
- package/README.md +10 -1
- package/package.json +1 -1
- package/src/cli.ts +105 -2
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ A customizable statusline for [Claude Code](https://claude.com/product/claude-co
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
10
|
- **Session info** - Project name, git branch, model, cost, lines changed, and context usage
|
|
11
|
+
- **System stats** - CPU and memory usage (optional)
|
|
11
12
|
- **Calendar events** - Upcoming events from multiple Google accounts
|
|
12
13
|
- **Meeting warnings** - Red alert when a meeting is 5 minutes away
|
|
13
14
|
- **Health reminders** - Water, stretch, and eye break reminders
|
|
@@ -144,6 +145,10 @@ glancebar config --water-reminder true
|
|
|
144
145
|
glancebar config --stretch-reminder true
|
|
145
146
|
glancebar config --eye-reminder true
|
|
146
147
|
|
|
148
|
+
# Enable/disable system stats
|
|
149
|
+
glancebar config --cpu-usage true
|
|
150
|
+
glancebar config --memory-usage true
|
|
151
|
+
|
|
147
152
|
# Reset to defaults
|
|
148
153
|
glancebar config --reset
|
|
149
154
|
```
|
|
@@ -165,6 +170,8 @@ glancebar | main* | Opus | $0.12 | +156 -23 | 9.7k/200k (5%) | In 15m: Team Stan
|
|
|
165
170
|
| Cost | Green | `$0.01`, `$0.1234` |
|
|
166
171
|
| Lines changed | Green/Red | `+156 -23` |
|
|
167
172
|
| Context usage | Green/Yellow/Red | `9.7k/200k (5%)` |
|
|
173
|
+
| CPU usage | Green/Yellow/Red | `CPU 12%` |
|
|
174
|
+
| Memory usage | Green/Yellow/Red | `Mem 8.2/16.0GB` |
|
|
168
175
|
|
|
169
176
|
Context usage color changes based on percentage:
|
|
170
177
|
- **Green**: < 50%
|
|
@@ -181,7 +188,7 @@ Context usage color changes based on percentage:
|
|
|
181
188
|
| Later | `HH:MM AM/PM: Title (account)` | `2:30 PM: Meeting (work)` |
|
|
182
189
|
| No events | `No upcoming events` | |
|
|
183
190
|
|
|
184
|
-
### Health Reminders (~
|
|
191
|
+
### Health Reminders (~5% chance)
|
|
185
192
|
|
|
186
193
|
| Type | Color | Example |
|
|
187
194
|
|------|-------|---------|
|
|
@@ -212,6 +219,8 @@ All configuration is stored in `~/.glancebar/`:
|
|
|
212
219
|
| `waterReminderEnabled` | true | Enable random water break reminders |
|
|
213
220
|
| `stretchReminderEnabled` | true | Enable random stretch/posture reminders |
|
|
214
221
|
| `eyeReminderEnabled` | true | Enable random eye break reminders (20-20-20 rule) |
|
|
222
|
+
| `showCpuUsage` | false | Show CPU usage percentage |
|
|
223
|
+
| `showMemoryUsage` | false | Show memory usage |
|
|
215
224
|
|
|
216
225
|
## Building from Source
|
|
217
226
|
|
package/package.json
CHANGED
package/src/cli.ts
CHANGED
|
@@ -18,6 +18,8 @@ interface Config {
|
|
|
18
18
|
waterReminderEnabled: boolean;
|
|
19
19
|
stretchReminderEnabled: boolean;
|
|
20
20
|
eyeReminderEnabled: boolean;
|
|
21
|
+
showCpuUsage: boolean;
|
|
22
|
+
showMemoryUsage: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
const COLORS: Record<string, string> = {
|
|
@@ -51,6 +53,8 @@ const DEFAULT_CONFIG: Config = {
|
|
|
51
53
|
waterReminderEnabled: true,
|
|
52
54
|
stretchReminderEnabled: true,
|
|
53
55
|
eyeReminderEnabled: true,
|
|
56
|
+
showCpuUsage: false,
|
|
57
|
+
showMemoryUsage: false,
|
|
54
58
|
};
|
|
55
59
|
|
|
56
60
|
const WATER_REMINDERS = [
|
|
@@ -448,6 +452,61 @@ function getMeetingWarning(event: CalendarEvent | null): string | null {
|
|
|
448
452
|
return null;
|
|
449
453
|
}
|
|
450
454
|
|
|
455
|
+
// ============================================================================
|
|
456
|
+
// System Stats
|
|
457
|
+
// ============================================================================
|
|
458
|
+
|
|
459
|
+
function getCpuUsage(): string | null {
|
|
460
|
+
try {
|
|
461
|
+
const os = require("os");
|
|
462
|
+
const cpus = os.cpus();
|
|
463
|
+
|
|
464
|
+
let totalIdle = 0;
|
|
465
|
+
let totalTick = 0;
|
|
466
|
+
|
|
467
|
+
for (const cpu of cpus) {
|
|
468
|
+
for (const type in cpu.times) {
|
|
469
|
+
totalTick += cpu.times[type as keyof typeof cpu.times];
|
|
470
|
+
}
|
|
471
|
+
totalIdle += cpu.times.idle;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
const usage = Math.round(100 - (totalIdle / totalTick) * 100);
|
|
475
|
+
|
|
476
|
+
// Color based on usage
|
|
477
|
+
let color = COLORS.green;
|
|
478
|
+
if (usage >= 80) color = COLORS.red;
|
|
479
|
+
else if (usage >= 50) color = COLORS.yellow;
|
|
480
|
+
|
|
481
|
+
return `${color}CPU ${usage}%${COLORS.reset}`;
|
|
482
|
+
} catch {
|
|
483
|
+
return null;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
function getMemoryUsage(): string | null {
|
|
488
|
+
try {
|
|
489
|
+
const os = require("os");
|
|
490
|
+
const totalMem = os.totalmem();
|
|
491
|
+
const freeMem = os.freemem();
|
|
492
|
+
const usedMem = totalMem - freeMem;
|
|
493
|
+
const usagePercent = Math.round((usedMem / totalMem) * 100);
|
|
494
|
+
|
|
495
|
+
// Format used memory
|
|
496
|
+
const usedGB = (usedMem / (1024 * 1024 * 1024)).toFixed(1);
|
|
497
|
+
const totalGB = (totalMem / (1024 * 1024 * 1024)).toFixed(1);
|
|
498
|
+
|
|
499
|
+
// Color based on usage
|
|
500
|
+
let color = COLORS.green;
|
|
501
|
+
if (usagePercent >= 80) color = COLORS.red;
|
|
502
|
+
else if (usagePercent >= 50) color = COLORS.yellow;
|
|
503
|
+
|
|
504
|
+
return `${color}Mem ${usedGB}/${totalGB}GB${COLORS.reset}`;
|
|
505
|
+
} catch {
|
|
506
|
+
return null;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
|
|
451
510
|
function formatTime(date: Date): string {
|
|
452
511
|
const hours = date.getHours();
|
|
453
512
|
const minutes = date.getMinutes();
|
|
@@ -480,6 +539,8 @@ Usage:
|
|
|
480
539
|
glancebar config --water-reminder <true|false> Enable/disable water reminders (default: true)
|
|
481
540
|
glancebar config --stretch-reminder <true|false> Enable/disable stretch reminders (default: true)
|
|
482
541
|
glancebar config --eye-reminder <true|false> Enable/disable eye break reminders (default: true)
|
|
542
|
+
glancebar config --cpu-usage <true|false> Show CPU usage (default: false)
|
|
543
|
+
glancebar config --memory-usage <true|false> Show memory usage (default: false)
|
|
483
544
|
glancebar config --reset Reset to default configuration
|
|
484
545
|
glancebar setup Show setup instructions
|
|
485
546
|
|
|
@@ -749,6 +810,34 @@ function handleConfig(args: string[]) {
|
|
|
749
810
|
return;
|
|
750
811
|
}
|
|
751
812
|
|
|
813
|
+
// Handle --cpu-usage
|
|
814
|
+
const cpuUsageIndex = args.indexOf("--cpu-usage");
|
|
815
|
+
if (cpuUsageIndex !== -1) {
|
|
816
|
+
const value = args[cpuUsageIndex + 1]?.toLowerCase();
|
|
817
|
+
if (value !== "true" && value !== "false") {
|
|
818
|
+
console.error("Error: --cpu-usage must be 'true' or 'false'");
|
|
819
|
+
process.exit(1);
|
|
820
|
+
}
|
|
821
|
+
config.showCpuUsage = value === "true";
|
|
822
|
+
saveConfig(config);
|
|
823
|
+
console.log(`CPU usage display ${value === "true" ? "enabled" : "disabled"}`);
|
|
824
|
+
return;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
// Handle --memory-usage
|
|
828
|
+
const memoryUsageIndex = args.indexOf("--memory-usage");
|
|
829
|
+
if (memoryUsageIndex !== -1) {
|
|
830
|
+
const value = args[memoryUsageIndex + 1]?.toLowerCase();
|
|
831
|
+
if (value !== "true" && value !== "false") {
|
|
832
|
+
console.error("Error: --memory-usage must be 'true' or 'false'");
|
|
833
|
+
process.exit(1);
|
|
834
|
+
}
|
|
835
|
+
config.showMemoryUsage = value === "true";
|
|
836
|
+
saveConfig(config);
|
|
837
|
+
console.log(`Memory usage display ${value === "true" ? "enabled" : "disabled"}`);
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
|
|
752
841
|
// Show current config
|
|
753
842
|
console.log(`
|
|
754
843
|
Glancebar Configuration
|
|
@@ -766,6 +855,10 @@ Reminders:
|
|
|
766
855
|
Water reminder: ${config.waterReminderEnabled ? "enabled" : "disabled"}
|
|
767
856
|
Stretch reminder: ${config.stretchReminderEnabled ? "enabled" : "disabled"}
|
|
768
857
|
Eye break reminder: ${config.eyeReminderEnabled ? "enabled" : "disabled"}
|
|
858
|
+
|
|
859
|
+
System Stats:
|
|
860
|
+
CPU usage: ${config.showCpuUsage ? "enabled" : "disabled"}
|
|
861
|
+
Memory usage: ${config.showMemoryUsage ? "enabled" : "disabled"}
|
|
769
862
|
`);
|
|
770
863
|
}
|
|
771
864
|
|
|
@@ -795,8 +888,8 @@ function getRandomReminder(config: Config): string | null {
|
|
|
795
888
|
|
|
796
889
|
if (enabledReminders.length === 0) return null;
|
|
797
890
|
|
|
798
|
-
// ~
|
|
799
|
-
if (Math.random() >= 0.
|
|
891
|
+
// ~5% chance to show any reminder (reduced from 30% to be less intrusive)
|
|
892
|
+
if (Math.random() >= 0.05) return null;
|
|
800
893
|
|
|
801
894
|
// Pick a random reminder type from enabled ones
|
|
802
895
|
const randomPicker = enabledReminders[Math.floor(Math.random() * enabledReminders.length)];
|
|
@@ -949,6 +1042,16 @@ async function outputStatusline() {
|
|
|
949
1042
|
}
|
|
950
1043
|
}
|
|
951
1044
|
|
|
1045
|
+
// Add system stats if enabled
|
|
1046
|
+
if (config.showCpuUsage) {
|
|
1047
|
+
const cpu = getCpuUsage();
|
|
1048
|
+
if (cpu) parts.push(cpu);
|
|
1049
|
+
}
|
|
1050
|
+
if (config.showMemoryUsage) {
|
|
1051
|
+
const mem = getMemoryUsage();
|
|
1052
|
+
if (mem) parts.push(mem);
|
|
1053
|
+
}
|
|
1054
|
+
|
|
952
1055
|
// Check for health reminder (water, stretch, eye break)
|
|
953
1056
|
const reminder = getRandomReminder(config);
|
|
954
1057
|
if (reminder) {
|