import { Box, Text } from "ink" import * as theme from "../../theme.js" import { Icon } from "../Icon.js" import type { ToolRendererProps } from "./types.js" import { truncateText, sanitizeContent, getToolDisplayName, getToolIconName } from "./utils.js" const MAX_RESULT_LINES = 15 export function SearchTool({ toolData }: ToolRendererProps) { const iconName = getToolIconName(toolData.tool) const displayName = getToolDisplayName(toolData.tool) const regex = toolData.regex || "" const query = toolData.query || "" const filePattern = toolData.filePattern || "" const path = toolData.path || "" const content = toolData.content ? sanitizeContent(toolData.content) : "" // Parse search results if content looks like results. const resultLines = content.split("\n").filter((line) => line.trim()) const matchCount = resultLines.length const { text: previewContent, truncated, hiddenLines } = truncateText(content, MAX_RESULT_LINES) return ( {/* Header */} {" "} {displayName} {matchCount > 0 && ({matchCount} matches)} {/* Search parameters */} {/* Regex/Query */} {regex && ( regex: {regex} )} {query && ( query: {query} )} {/* Search scope */} {path && ( <> path: {path} )} {filePattern && ( <> pattern: {filePattern} )} {/* Results */} {previewContent && ( Results: {previewContent.split("\n").map((line, i) => { // Try to highlight file:line patterns const match = line.match(/^([^:]+):(\d+):(.*)$/) if (match) { const [, file, lineNum, context] = match return ( {file} : {lineNum} : {context} ) } return ( {line} ) })} {truncated && ( ... ({hiddenLines} more results) )} )} ) }