Files
gemini-cli/packages/cli/src/ui/components/Header.tsx
T

79 lines
1.9 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import type React from 'react';
2025-06-05 00:00:34 -07:00
import { Box, Text } from 'ink';
2025-04-19 12:38:09 -04:00
import Gradient from 'ink-gradient';
2025-09-10 10:57:07 -07:00
import { theme } from '../semantic-colors.js';
import { shortAsciiLogo, longAsciiLogo, tinyAsciiLogo } from './AsciiArt.js';
2025-06-13 00:59:45 -07:00
import { getAsciiArtWidth } from '../utils/textUtils.js';
import { useTerminalSize } from '../hooks/useTerminalSize.js';
2025-06-05 18:14:02 -07:00
interface HeaderProps {
2025-06-13 00:59:45 -07:00
customAsciiArt?: string; // For user-defined ASCII art
2025-07-11 13:43:57 -07:00
version: string;
nightly: boolean;
2025-06-05 18:14:02 -07:00
}
const ThemedGradient: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const gradient = theme.ui.gradient;
if (gradient && gradient.length >= 2) {
return (
<Gradient colors={gradient}>
<Text>{children}</Text>
</Gradient>
);
}
if (gradient && gradient.length === 1) {
return <Text color={gradient[0]}>{children}</Text>;
}
return <Text>{children}</Text>;
};
2025-06-13 00:59:45 -07:00
export const Header: React.FC<HeaderProps> = ({
customAsciiArt,
2025-07-11 13:43:57 -07:00
version,
nightly,
2025-06-13 00:59:45 -07:00
}) => {
const { columns: terminalWidth } = useTerminalSize();
2025-06-13 00:59:45 -07:00
let displayTitle;
const widthOfLongLogo = getAsciiArtWidth(longAsciiLogo);
const widthOfShortLogo = getAsciiArtWidth(shortAsciiLogo);
2025-06-13 00:59:45 -07:00
if (customAsciiArt) {
displayTitle = customAsciiArt;
} else if (terminalWidth >= widthOfLongLogo) {
displayTitle = longAsciiLogo;
} else if (terminalWidth >= widthOfShortLogo) {
displayTitle = shortAsciiLogo;
2025-06-13 00:59:45 -07:00
} else {
displayTitle = tinyAsciiLogo;
2025-06-13 00:59:45 -07:00
}
2025-06-23 23:43:17 +00:00
const artWidth = getAsciiArtWidth(displayTitle);
2025-06-13 00:59:45 -07:00
return (
2025-06-23 23:43:17 +00:00
<Box
alignItems="flex-start"
width={artWidth}
flexShrink={0}
2025-07-11 13:43:57 -07:00
flexDirection="column"
2025-06-23 23:43:17 +00:00
>
<ThemedGradient>{displayTitle}</ThemedGradient>
2025-07-11 13:43:57 -07:00
{nightly && (
<Box width="100%" flexDirection="row" justifyContent="flex-end">
<ThemedGradient>v{version}</ThemedGradient>
2025-07-11 13:43:57 -07:00
</Box>
)}
2025-06-23 23:43:17 +00:00
</Box>
2025-06-13 00:59:45 -07:00
);
};