File size: 1,543 Bytes
9332ccf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | /**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { Box, Text } from 'ink';
import { ThemedGradient } from './ThemedGradient.js';
import { theme } from '../semantic-colors.js';
import type { ReactNode } from 'react';
export function getFormattedBannerContent(
rawText: string,
isWarning: boolean,
subsequentLineColor: string,
): ReactNode {
const text = rawText.replace(/\\n/g, '\n');
const lines = text.split('\n');
return lines.map((line, index) => {
if (index === 0) {
if (isWarning) {
return (
<Text key={index} bold color={theme.status.warning}>
{line}
</Text>
);
}
return (
<ThemedGradient key={index}>
<Text bold>{line}</Text>
</ThemedGradient>
);
}
return (
<Text key={index} color={subsequentLineColor}>
{line}
</Text>
);
});
}
interface BannerProps {
bannerText: string;
isWarning: boolean;
width: number;
}
export const Banner = ({ bannerText, isWarning, width }: BannerProps) => {
const subsequentLineColor = theme.text.primary;
const formattedBannerContent = getFormattedBannerContent(
bannerText,
isWarning,
subsequentLineColor,
);
return (
<Box
flexDirection="column"
borderStyle="round"
borderColor={isWarning ? theme.status.warning : theme.border.default}
width={width}
paddingLeft={1}
paddingRight={1}
>
{formattedBannerContent}
</Box>
);
};
|