| |
| |
| |
| |
| |
|
|
| import type React from 'react'; |
| import { useMemo } from 'react'; |
| import { Box, Text, useIsScreenReaderEnabled } from 'ink'; |
| import { useUIState } from '../../contexts/UIStateContext.js'; |
| import { theme } from '../../semantic-colors.js'; |
| import { interpolateColor, resolveColor } from '../../themes/color-utils.js'; |
| import { supportsTrueColor } from '@google/gemini-cli-core'; |
|
|
| export interface HalfLinePaddedBoxProps { |
| |
| |
| |
| backgroundBaseColor: string; |
|
|
| |
| |
| |
| backgroundOpacity: number; |
|
|
| |
| |
| |
| useBackgroundColor?: boolean; |
|
|
| children: React.ReactNode; |
| } |
|
|
| |
| |
| |
| |
| export const HalfLinePaddedBox: React.FC<HalfLinePaddedBoxProps> = (props) => { |
| const isScreenReaderEnabled = useIsScreenReaderEnabled(); |
| if (props.useBackgroundColor === false || isScreenReaderEnabled) { |
| return <>{props.children}</>; |
| } |
|
|
| return <HalfLinePaddedBoxInternal {...props} />; |
| }; |
|
|
| const HalfLinePaddedBoxInternal: React.FC<HalfLinePaddedBoxProps> = ({ |
| backgroundBaseColor, |
| backgroundOpacity, |
| children, |
| }) => { |
| const { terminalWidth } = useUIState(); |
| const terminalBg = theme.background.primary || 'black'; |
|
|
| const backgroundColor = useMemo(() => { |
| const resolvedBase = |
| resolveColor(backgroundBaseColor) || backgroundBaseColor; |
| const resolvedTerminalBg = resolveColor(terminalBg) || terminalBg; |
|
|
| return interpolateColor( |
| resolvedTerminalBg, |
| resolvedBase, |
| backgroundOpacity, |
| ); |
| }, [backgroundBaseColor, backgroundOpacity, terminalBg]); |
|
|
| if (!backgroundColor) { |
| return <>{children}</>; |
| } |
|
|
| const noTrueColor = !supportsTrueColor(); |
|
|
| if (noTrueColor) { |
| return ( |
| <Box width={terminalWidth} backgroundColor={backgroundColor} paddingY={1}> |
| {children} |
| </Box> |
| ); |
| } |
|
|
| return ( |
| <Box |
| width={terminalWidth} |
| flexDirection="column" |
| alignItems="stretch" |
| minHeight={1} |
| flexShrink={0} |
| > |
| <Box width={terminalWidth} flexDirection="row"> |
| <Text color={backgroundColor}>{'â–„'.repeat(terminalWidth)}</Text> |
| </Box> |
| <Box |
| width={terminalWidth} |
| flexDirection="column" |
| alignItems="stretch" |
| backgroundColor={backgroundColor} |
| > |
| {children} |
| </Box> |
| <Box width={terminalWidth} flexDirection="row"> |
| <Text color={backgroundColor}>{'â–€'.repeat(terminalWidth)}</Text> |
| </Box> |
| </Box> |
| ); |
| }; |
|
|