/** * What a bash `grep` command means in terms of the grep tool's own search. * * safeBash runs a lone `grep` through `_grep` instead of the grep program, * so the approval it asks for means exactly what the grep tool's approval * means. That is only honest when the search finds what grep would find * and the output looks the way grep prints it. This file holds both * halves, as pure functions with no file access: * * - `_grepPatternToRegex` translates a pattern, or refuses it when any * character could mean something different to grep and to JavaScript. * - `_renderGrepOutput` prints matches the way GNU grep does. * * See docs/dev/stdlib/safe-bash.md, "grep". */ import { type GrepResults } from "./shell.js"; export type GrepSyntax = "basic" | "extended" | "fixed"; /** The JavaScript regex source that matches exactly what grep would match * for `pattern`, or null when the pattern uses anything whose meaning * differs between grep and JavaScript. `wholeWord` is grep's -w, which * the tool carries out as `\b(?:pattern)\b`. A null sends the command to * the bash path, never to a guess. */ export declare function _grepPatternToRegex(pattern: string, syntax: GrepSyntax, wholeWord: boolean): string | null; /** What the command said about printing. The rules that turn this into * grep's output all live in `_renderGrepOutput`. The Agency type of the * same name in stdlib/safeBash/actions.agency must keep these fields. */ export type GrepRender = { /** `-n` was given. */ lineNumbers: boolean; /** `-H` gives "always", `-h` gives "never", neither gives "default". */ fileNames: "default" | "always" | "never"; /** The path as bash hands it to grep (`GrepTarget.argument`), or "" * when none was written. */ argument: string; /** The path names one file, not a directory. */ oneFile: boolean; }; /** grep's output for these matches: `name:line:text` lines, or names * alone for a files-only search, each ending in a newline. */ export declare function _renderGrepOutput(results: GrepResults, render: GrepRender): string; /** The line safeBash adds after a directory search, built from the list * the walk skips so the two cannot drift apart. */ export declare function _skippedDirsNote(): string;