Documentation
¶
Index ¶
- Constants
- func ApplyColorSpec(scheme *ColorScheme, spec string) error
- func ColorNameToCode(name string, isBg bool) string
- func Colorize(text, color string) string
- func FormatByteOffset(offset int64, scheme ColorScheme, useColor bool) string
- func FormatColumn(col int, scheme ColorScheme, useColor bool) string
- func FormatLineNumber(lineNum int, scheme ColorScheme, useColor bool) string
- func FormatPath(path string, scheme ColorScheme, useColor bool) string
- func FormatSeparator(sep string, scheme ColorScheme, useColor bool) string
- func HighlightLiteralMatches(line, pattern string, caseInsensitive bool, scheme ColorScheme, useColor bool) string
- func HighlightMatches(line string, re *regexp.Regexp, scheme ColorScheme, useColor bool) string
- func ParseColorSpec(spec string) (component, attr, value string, err error)
- func Run(w io.Writer, pattern string, paths []string, opts Options) error
- func ShouldUseColor(mode ColorMode) bool
- type ByteOffset
- type ColorMode
- type ColorScheme
- type FileResult
- type Formatter
- func (f *Formatter) PrintContextSeparator()
- func (f *Formatter) PrintCount(path string, count int)
- func (f *Formatter) PrintFileHeader(path string)
- func (f *Formatter) PrintFilesWithMatch(path string)
- func (f *Formatter) PrintMatch(path string, lineNum, column int, byteOffset int64, line string, ...)
- type FormatterOptions
- type Gitignore
- type GitignoreSet
- type Match
- type MatchResult
- type Options
- type OutputFormat
- type Pattern
- type Result
- type Stats
- type StreamBegin
- type StreamContext
- type StreamEnd
- type StreamLines
- type StreamMatch
- type StreamMessage
- type StreamSummary
Constants ¶
const ( Reset = "\033[0m" Bold = "\033[1m" Underline = "\033[4m" FgBlack = "\033[30m" FgRed = "\033[31m" FgGreen = "\033[32m" FgYellow = "\033[33m" FgBlue = "\033[34m" FgMagenta = "\033[35m" FgCyan = "\033[36m" FgWhite = "\033[37m" FgBrightBlack = "\033[90m" FgBrightRed = "\033[91m" FgBrightGreen = "\033[92m" FgBrightYellow = "\033[93m" FgBrightBlue = "\033[94m" FgBrightMagenta = "\033[95m" FgBrightCyan = "\033[96m" FgBrightWhite = "\033[97m" BgBlack = "\033[40m" BgRed = "\033[41m" BgGreen = "\033[42m" BgYellow = "\033[43m" BgBlue = "\033[44m" BgMagenta = "\033[45m" BgCyan = "\033[46m" BgWhite = "\033[47m" )
ANSI color codes for terminal output.
Variables ¶
This section is empty.
Functions ¶
func ApplyColorSpec ¶
func ApplyColorSpec(scheme *ColorScheme, spec string) error
ApplyColorSpec applies a color specification to a scheme
func ColorNameToCode ¶
ColorNameToCode converts a color name to ANSI code
func FormatByteOffset ¶
func FormatByteOffset(offset int64, scheme ColorScheme, useColor bool) string
FormatByteOffset formats a byte offset with colors (uses same color as line number)
func FormatColumn ¶
func FormatColumn(col int, scheme ColorScheme, useColor bool) string
FormatColumn formats a column number with colors
func FormatLineNumber ¶
func FormatLineNumber(lineNum int, scheme ColorScheme, useColor bool) string
FormatLineNumber formats a line number with colors
func FormatPath ¶
func FormatPath(path string, scheme ColorScheme, useColor bool) string
FormatPath formats a file path with colors
func FormatSeparator ¶
func FormatSeparator(sep string, scheme ColorScheme, useColor bool) string
FormatSeparator formats a separator with colors
func HighlightLiteralMatches ¶
func HighlightLiteralMatches(line, pattern string, caseInsensitive bool, scheme ColorScheme, useColor bool) string
HighlightLiteralMatches highlights all literal string matches in the line
func HighlightMatches ¶
HighlightMatches highlights all regex matches in the line
func ParseColorSpec ¶
ParseColorSpec parses a ripgrep-style color specification like "path:fg:magenta"
func ShouldUseColor ¶
ShouldUseColor determines if colors should be used based on mode and terminal
Types ¶
type ByteOffset ¶
type ByteOffset struct {
// contains filtered or unexported fields
}
ByteOffset calculates the byte offset of a match in a file
func NewByteOffset ¶
func NewByteOffset() *ByteOffset
NewByteOffset creates a new byte offset tracker
func (*ByteOffset) AddLine ¶
func (b *ByteOffset) AddLine(line string)
AddLine adds a line's length to the running offset
func (*ByteOffset) GetMatchOffset ¶
func (b *ByteOffset) GetMatchOffset(column int) int64
GetMatchOffset returns the absolute byte offset of a match
type ColorMode ¶
type ColorMode int
ColorMode represents when to use colors
func ParseColorMode ¶
ParseColorMode parses a color mode string
type ColorScheme ¶
type ColorScheme struct {
Path string // Color for file paths
Line string // Color for line numbers
Column string // Color for column numbers
Match string // Color for matched text
MatchBg string // Background color for matched text
Separator string // Color for separators
Context string // Color for context lines
}
ColorScheme defines the colors used for output
func DefaultScheme ¶
func DefaultScheme() ColorScheme
DefaultScheme returns the default color scheme matching ripgrep
func NoColorScheme ¶
func NoColorScheme() ColorScheme
NoColorScheme returns a scheme with no colors (for --color=never)
type FileResult ¶
type FileResult struct {
Path string `json:"path"`
Matches []Match `json:"matches"`
Count int `json:"count"`
}
FileResult represents matches in a single file
type Formatter ¶
type Formatter struct {
// contains filtered or unexported fields
}
Formatter handles output formatting with color support
func NewFormatter ¶
func NewFormatter(w io.Writer, opts FormatterOptions) *Formatter
NewFormatter creates a new output formatter
func (*Formatter) PrintContextSeparator ¶
func (f *Formatter) PrintContextSeparator()
PrintContextSeparator prints the context separator ("--")
func (*Formatter) PrintCount ¶
PrintCount prints the count for a file (for -c mode)
func (*Formatter) PrintFileHeader ¶
PrintFileHeader prints a file header (only used in heading mode)
func (*Formatter) PrintFilesWithMatch ¶
PrintFilesWithMatch prints just the filename (for -l mode)
type FormatterOptions ¶
type FormatterOptions struct {
UseColor bool
Scheme ColorScheme
Format OutputFormat
ShowLineNumber bool
ShowColumn bool
ShowByteOffset bool
OnlyMatching bool
Trim bool
Replace string
Regex *regexp.Regexp
Pattern string
CaseInsensitive bool
UseLiteral bool
}
FormatterOptions configures the formatter
type GitignoreSet ¶
type GitignoreSet = pkgrg.GitignoreSet
GitignoreSet is an alias for the pkg type
func NewGitignoreSet ¶
func NewGitignoreSet(searchDir string) *GitignoreSet
NewGitignoreSet creates a new GitignoreSet loading patterns from multiple sources
type Match ¶
type Match struct {
Path string `json:"path"`
LineNumber int `json:"line_number"`
Column int `json:"column,omitempty"`
ByteOffset int64 `json:"byte_offset,omitempty"`
Line string `json:"line"`
Match string `json:"match,omitempty"`
}
Match represents a single match result
type MatchResult ¶
type MatchResult = pkgrg.MatchResult
MatchResult indicates the result of matching a path against gitignore patterns
type Options ¶
type Options struct {
IgnoreCase bool // -i: case insensitive search
SmartCase bool // -S: smart case (case insensitive if pattern is lowercase)
WordRegexp bool // -w: match whole words only
LineNumber bool // -n: show line numbers (default true)
Count bool // -c: only show count of matches
FilesWithMatch bool // -l: only show file names with matches
InvertMatch bool // -v: show non-matching lines
Context int // -C: lines of context (before and after)
Before int // -B: lines before match
After int // -A: lines after match
Types []string // -t: file types to include
TypesNot []string // -T: file types to exclude
Glob []string // -g: glob patterns to include
Hidden bool // --hidden: search hidden files
NoIgnore bool // --no-ignore: don't respect gitignore
MaxCount int // -m: max matches per file
MaxDepth int // --max-depth: max directory depth
FollowSymlinks bool // -L: follow symlinks
JSON bool // --json: JSON output
JSONStream bool // --json-stream: streaming NDJSON output
NoHeading bool // --no-heading: no file name headings
OnlyMatching bool // -o: only show matching part
Quiet bool // -q: quiet mode, exit on first match
Fixed bool // -F: treat pattern as literal string
Threads int // --threads: number of worker threads (0 = auto)
// New options for ripgrep compatibility
Color string // --color: when to use colors (auto, always, never)
Colors []string // --colors: custom color specifications
Replace string // -r/--replace: replacement string for matches
Multiline bool // -U/--multiline: enable multiline matching
Trim bool // --trim: trim leading/trailing whitespace
ShowColumn bool // --column: show column numbers
ByteOffset bool // -b/--byte-offset: show byte offset (not implemented)
Stats bool // --stats: show search statistics
Passthru bool // --passthru: show all lines, highlighting matches
}
Options configures the rg command behavior
type OutputFormat ¶
type OutputFormat int
OutputFormat represents the output format type
const ( FormatDefault OutputFormat = iota // Default ripgrep-style output FormatNoHeading // No file name headings (all on one line) FormatJSON // Full JSON output FormatJSONStream // Streaming NDJSON output )
type Result ¶
type Result struct {
Files []FileResult `json:"files"`
TotalFiles int `json:"total_files"`
TotalMatch int `json:"total_matches"`
}
Result represents the complete search result
type Stats ¶
Stats tracks search statistics
func (*Stats) PrintStats ¶
PrintStats prints search statistics
type StreamBegin ¶
type StreamBegin struct {
Path string `json:"path"`
}
StreamBegin is sent at the start of searching a file
type StreamContext ¶
type StreamContext struct {
Path string `json:"path"`
LineNumber int `json:"line_number"`
Lines StreamLines `json:"lines"`
}
StreamContext is sent for context lines
type StreamLines ¶
type StreamLines struct {
Text string `json:"text"`
}
StreamLines holds line text for streaming output
type StreamMatch ¶
type StreamMatch struct {
Path string `json:"path"`
LineNumber int `json:"line_number"`
Column int `json:"column,omitempty"`
Lines StreamLines `json:"lines"`
Match string `json:"match,omitempty"`
}
StreamMatch is sent for each match
type StreamMessage ¶
type StreamMessage struct {
Type string `json:"type"` // "begin", "match", "context", "end", "summary"
Data any `json:"data"`
}
StreamMessage represents a message in NDJSON streaming output
type StreamSummary ¶
type StreamSummary struct {
TotalFiles int `json:"total_files"`
TotalMatches int `json:"total_matches"`
}
StreamSummary is sent at the end of all searching