| 1 | import { Text } from "ink"; |
| 2 | import React, { useMemo } from "react"; |
| 3 | |
| 4 | import { useTerminalSize } from "../hooks/useTerminalSize.js"; |
| 5 | import { getResponsiveRepoText } from "../hooks/useTUIChatHooks.js"; |
| 6 | |
| 7 | interface ResponsiveRepoDisplayProps { |
| 8 | remoteUrl?: string; |
| 9 | reservedWidth?: number; // Width reserved for other elements in the same row |
| 10 | } |
| 11 | |
| 12 | export const ResponsiveRepoDisplay: React.FC<ResponsiveRepoDisplayProps> = ({ |
| 13 | remoteUrl, |
| 14 | }) => { |
| 15 | const { columns } = useTerminalSize(); |
| 16 | |
| 17 | const repoText = useMemo(() => { |
| 18 | // Calculate available width for repo display |
| 19 | // Reserve space for margins, mode indicator, context percentage, and other UI elements |
| 20 | const availableWidth = Math.floor(columns / 2); |
| 21 | |
| 22 | return getResponsiveRepoText(remoteUrl, availableWidth); |
| 23 | }, [remoteUrl, columns]); |
| 24 | |
| 25 | // Don't render if no text to show |
| 26 | if (!repoText) { |
| 27 | return null; |
| 28 | } |
| 29 | |
| 30 | return ( |
| 31 | <Text color="dim" wrap="truncate-start"> |
| 32 | {repoText} |
| 33 | </Text> |
| 34 | ); |
| 35 | }; |