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

71 lines
1.9 KiB
TypeScript
Raw Normal View History

/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
2025-04-15 21:41:08 -07:00
import 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-08-15 15:39:54 -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
}
2025-08-15 15:39:54 -07:00
const GradientText: React.FC<{ children: React.ReactNode }> = ({
children,
}) => {
const textElement = <Text color={theme.text.primary}>{children}</Text>;
if (theme.ui.gradient && theme.ui.gradient.length > 0) {
return <Gradient colors={theme.ui.gradient}>{textElement}</Gradient>;
}
return textElement;
};
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
>
2025-08-15 15:39:54 -07:00
<Box>
<GradientText>{displayTitle}</GradientText>
</Box>
2025-07-11 13:43:57 -07:00
{nightly && (
<Box width="100%" flexDirection="row" justifyContent="flex-end">
2025-08-15 15:39:54 -07:00
<Text color={theme.text.primary}>v{version}</Text>
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
);
};