From e0de69f3846ecf9de40bb2e02546235d9db53393 Mon Sep 17 00:00:00 2001 From: Allen Hutchison Date: Tue, 29 Apr 2025 08:29:09 -0700 Subject: First four independent files for @ commands. (#205) --- .../cli/src/ui/components/SuggestionsDisplay.tsx | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 packages/cli/src/ui/components/SuggestionsDisplay.tsx (limited to 'packages/cli/src/ui/components') diff --git a/packages/cli/src/ui/components/SuggestionsDisplay.tsx b/packages/cli/src/ui/components/SuggestionsDisplay.tsx new file mode 100644 index 00000000..a9d24003 --- /dev/null +++ b/packages/cli/src/ui/components/SuggestionsDisplay.tsx @@ -0,0 +1,77 @@ +/** + * @license + * Copyright 2025 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import React from 'react'; +import { Box, Text } from 'ink'; + +interface SuggestionsDisplayProps { + suggestions: string[]; + activeIndex: number; + isLoading: boolean; + width: number; + scrollOffset: number; +} + +export const MAX_SUGGESTIONS_TO_SHOW = 8; + +export function SuggestionsDisplay({ + suggestions, + activeIndex, + isLoading, + width, + scrollOffset, +}: SuggestionsDisplayProps) { + if (isLoading) { + return ( + + Loading suggestions... + + ); + } + + if (suggestions.length === 0) { + return null; // Don't render anything if there are no suggestions + } + + // Calculate the visible slice based on scrollOffset + const startIndex = scrollOffset; + const endIndex = Math.min( + scrollOffset + MAX_SUGGESTIONS_TO_SHOW, + suggestions.length, + ); + const visibleSuggestions = suggestions.slice(startIndex, endIndex); + + return ( + + {scrollOffset > 0 && } + + {visibleSuggestions.map((suggestion, index) => { + const originalIndex = startIndex + index; + const isActive = originalIndex === activeIndex; + return ( + + {suggestion} + + ); + })} + {endIndex < suggestions.length && } + {suggestions.length > MAX_SUGGESTIONS_TO_SHOW && ( + + ({activeIndex + 1}/{suggestions.length}) + + )} + + ); +} -- cgit v1.2.3