grefcore

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ColorRed   = lipgloss.Color("9")   // Bright red for highlights
	ColorGreen = lipgloss.Color("10")  // Bright green for replacements
	ColorCyan  = lipgloss.Color("6")   // Cyan for selection
	ColorGrey  = lipgloss.Color("240") // Dark grey for help and less important text
)

ANSI escape codes for coloring terminal output

Variables

This section is empty.

Functions

func InitModel

func InitModel(results []SearchResult, patternStr, replacement string, pattern *regexp.Regexp, mode AppMode) model

InitModel returns a new model with the initial state

func IsExcluded

func IsExcluded(path string, excludeList []string) bool

IsExcluded checks if a given file or directory path matches any pattern in the exclusion list. It handles directory suffixes (ending with /), file extensions (*.ext), and exact filename matches.

func ParseExcludeList

func ParseExcludeList(excludeStr string) []string

ParseExcludeList converts a comma-separated string of patterns into a slice.

func PerformReplacements added in v1.2.0

func PerformReplacements(allResults []SearchResult, selected map[int]struct{}, pattern *regexp.Regexp, replacementStr string) error

PerformReplacements coordinates the replacement process across multiple files. It groups results by file path to ensure each file is opened and written only once.

func ReplaceInFile

func ReplaceInFile(filePath string, resultsInFile []SearchResult, pattern *regexp.Regexp, replacementStr string) (err error)

ReplaceInFile streams the file line-by-line to a temporary file, applying replacements. This approach is memory-efficient and works on files of any size.

Types

type AppMode

type AppMode int

AppMode represents the different modes the application provides

const (
	Default AppMode = iota
	SearchOnly
)

type AppState

type AppState int

AppState represents the different UI states of the application

const (
	StateBrowse     AppState = iota // User is browsing search results
	StateConfirming                 // User is confirming replacements
	StateReplacing                  // Replacements are being performed
	StateDone                       // All replacements are done or user quit
)

type SearchResult

type SearchResult struct {
	FilePath  string // Full path to the file
	LineNum   int    // 1-based line number
	LineText  string // Full text of the line containing the match
	MatchText string // The specific text substring that triggered the regex
}

SearchResult holds information about a specific pattern match within a file.

func PerformSearchAdaptive

func PerformSearchAdaptive(rootPath string, pattern *regexp.Regexp, excludeList []string) ([]SearchResult, error)

PerformSearchAdaptive traverses a directory tree and searches for a regex pattern. It uses a pool of worker goroutines to process files in parallel and selects the optimal search strategy based on file size and regex complexity.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL