From 01768d7759b81a0f1483c751206f6afcae6fc505 Mon Sep 17 00:00:00 2001
From: Jacob Richman <jacob314@gmail.com>
Date: Fri, 30 May 2025 22:18:01 +0000
Subject: feat: add --show_memory_usage flag to display memory usage in status
 bar (#606)

---
 .../cli/src/ui/components/MemoryUsageDisplay.tsx   | 40 ++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 packages/cli/src/ui/components/MemoryUsageDisplay.tsx

(limited to 'packages/cli/src/ui/components/MemoryUsageDisplay.tsx')

diff --git a/packages/cli/src/ui/components/MemoryUsageDisplay.tsx b/packages/cli/src/ui/components/MemoryUsageDisplay.tsx
new file mode 100644
index 00000000..5d9a7c49
--- /dev/null
+++ b/packages/cli/src/ui/components/MemoryUsageDisplay.tsx
@@ -0,0 +1,40 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import React, { useEffect, useState } from 'react';
+import { Box, Text } from 'ink';
+import { Colors } from '../colors.js';
+import process from 'node:process';
+import { formatMemoryUsage } from '../utils/formatters.js';
+
+export const MemoryUsageDisplay: React.FC = () => {
+  const [memoryUsage, setMemoryUsage] = useState<string>('');
+  const [memoryUsageColor, setMemoryUsageColor] = useState<string>(
+    Colors.SubtleComment,
+  );
+
+  useEffect(() => {
+    const updateMemory = () => {
+      const usage = process.memoryUsage().rss;
+      setMemoryUsage(formatMemoryUsage(usage));
+      setMemoryUsageColor(
+        usage >= 2 * 1024 * 1024 * 1024
+          ? Colors.AccentRed
+          : Colors.SubtleComment,
+      );
+    };
+    const intervalId = setInterval(updateMemory, 2000);
+    updateMemory(); // Initial update
+    return () => clearInterval(intervalId);
+  }, []);
+
+  return (
+    <Box>
+      <Text color={Colors.SubtleComment}>| </Text>
+      <Text color={memoryUsageColor}>{memoryUsage}</Text>
+    </Box>
+  );
+};
-- 
cgit v1.2.3

