Files
oh-my-opencode/src/tools/grep/result-formatter.ts
T
YeonGyu-Kim df03300211 refactor: wave 1 - extract leaf modules, rename catch-all files, split index.ts hooks
- Split 25+ index.ts files into hook.ts + extracted modules
- Rename all catch-all utils.ts/helpers.ts to domain-specific names
- Split src/tools/lsp/ into ~15 focused modules
- Split src/tools/delegate-task/ into ~18 focused modules
- Separate shared types from implementation
- 155 files changed, 60+ new files created
- All typecheck clean, 61 tests pass
2026-02-08 13:57:26 +09:00

54 lines
1.4 KiB
TypeScript

import type { GrepResult, GrepMatch, CountResult } from "./types"
export function formatGrepResult(result: GrepResult): string {
if (result.error) {
return `Error: ${result.error}`
}
if (result.matches.length === 0) {
return "No matches found"
}
const lines: string[] = []
lines.push(`Found ${result.totalMatches} match(es) in ${result.filesSearched} file(s)`)
if (result.truncated) {
lines.push("[Output truncated due to size limit]")
}
lines.push("")
const byFile = new Map<string, GrepMatch[]>()
for (const match of result.matches) {
const existing = byFile.get(match.file) || []
existing.push(match)
byFile.set(match.file, existing)
}
for (const [file, matches] of byFile) {
lines.push(file)
for (const match of matches) {
lines.push(` ${match.line}: ${match.text.trim()}`)
}
lines.push("")
}
return lines.join("\n")
}
export function formatCountResult(results: CountResult[]): string {
if (results.length === 0) {
return "No matches found"
}
const total = results.reduce((sum, r) => sum + r.count, 0)
const lines: string[] = [`Found ${total} match(es) in ${results.length} file(s):`, ""]
const sorted = [...results].sort((a, b) => b.count - a.count)
for (const { file, count } of sorted) {
lines.push(` ${count.toString().padStart(6)}: ${file}`)
}
return lines.join("\n")
}