summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/PrepareLabel.tsx
diff options
context:
space:
mode:
authorAyesha Shafique <[email protected]>2025-08-04 00:53:24 +0500
committerGitHub <[email protected]>2025-08-03 19:53:24 +0000
commit072d8ba2899f2601dad6d4b0333fdcb80555a7dd (patch)
treea8333f75184889929b844c115c5fb93555abdf62 /packages/cli/src/ui/components/PrepareLabel.tsx
parent03ed37d0dc2b5e2077b53073517abaab3d24d9c2 (diff)
feat: Add reverse search capability for shell commands (#4793)
Diffstat (limited to 'packages/cli/src/ui/components/PrepareLabel.tsx')
-rw-r--r--packages/cli/src/ui/components/PrepareLabel.tsx48
1 files changed, 48 insertions, 0 deletions
diff --git a/packages/cli/src/ui/components/PrepareLabel.tsx b/packages/cli/src/ui/components/PrepareLabel.tsx
new file mode 100644
index 00000000..652a77a6
--- /dev/null
+++ b/packages/cli/src/ui/components/PrepareLabel.tsx
@@ -0,0 +1,48 @@
+/**
+ * @license
+ * Copyright 2025 Google LLC
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import React from 'react';
+import { Text } from 'ink';
+import { Colors } from '../colors.js';
+
+interface PrepareLabelProps {
+ label: string;
+ matchedIndex?: number;
+ userInput: string;
+ textColor: string;
+ highlightColor?: string;
+}
+
+export const PrepareLabel: React.FC<PrepareLabelProps> = ({
+ label,
+ matchedIndex,
+ userInput,
+ textColor,
+ highlightColor = Colors.AccentYellow,
+}) => {
+ if (
+ matchedIndex === undefined ||
+ matchedIndex < 0 ||
+ matchedIndex >= label.length ||
+ userInput.length === 0
+ ) {
+ return <Text color={textColor}>{label}</Text>;
+ }
+
+ const start = label.slice(0, matchedIndex);
+ const match = label.slice(matchedIndex, matchedIndex + userInput.length);
+ const end = label.slice(matchedIndex + userInput.length);
+
+ return (
+ <Text>
+ <Text color={textColor}>{start}</Text>
+ <Text color="black" bold backgroundColor={highlightColor}>
+ {match}
+ </Text>
+ <Text color={textColor}>{end}</Text>
+ </Text>
+ );
+};