/** * @license * Copyright 2025 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import { Box, Text } from 'ink'; export interface Suggestion { label: string; value: string; } interface SuggestionsDisplayProps { suggestions: Suggestion[]; 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.label} ); })} {endIndex < suggestions.length && } {suggestions.length > MAX_SUGGESTIONS_TO_SHOW && ( ({activeIndex + 1}/{suggestions.length}) )} ); }