import { Hunk } from 'diff' import { Box, Text } from 'ink' import * as React from 'react' import { intersperse } from '../utils/array' import { StructuredDiff } from './StructuredDiff' import { getTheme } from '../utils/theme' import { getCwd } from '../utils/state' import { relative } from 'path' import { useTerminalSize } from '../hooks/useTerminalSize' type Props = { filePath: string structuredPatch: Hunk[] verbose: boolean } export function FileEditToolUpdatedMessage({ filePath, structuredPatch, verbose, }: Props): React.ReactNode { const { columns } = useTerminalSize() const numAdditions = structuredPatch.reduce( (count, hunk) => count + hunk.lines.filter(_ => _.startsWith('+')).length, 0, ) const numRemovals = structuredPatch.reduce( (count, hunk) => count + hunk.lines.filter(_ => _.startsWith('-')).length, 0, ) return ( {' '}⎿ Updated{' '} {verbose ? filePath : relative(getCwd(), filePath)} {numAdditions > 0 || numRemovals > 0 ? ' with ' : ''} {numAdditions > 0 ? ( <> {numAdditions}{' '} {numAdditions > 1 ? 'additions' : 'addition'} ) : null} {numAdditions > 0 && numRemovals > 0 ? ' and ' : null} {numRemovals > 0 ? ( <> {numRemovals}{' '} {numRemovals > 1 ? 'removals' : 'removal'} ) : null} {intersperse( structuredPatch.map(_ => ( )), i => ( ... ), )} ) }