This commit is contained in:
2026-01-15 18:05:35 +01:00
parent 908b614d74
commit 2dd6774a69

22
main.go
View File

@@ -53,10 +53,10 @@ type LineMatch struct {
const (
reset = "\x1b[0m"
bold = "\x1b[1m"
red = "\x1b[31m"
green = "\x1b[32m"
yellow = "\x1b[33m"
//bold = "\x1b[1m"
//red = "\x1b[31m"
green = "\x1b[32m"
//yellow = "\x1b[33m"
)
func highlight(src string, start, end int, style ...string) string {
@@ -333,11 +333,23 @@ func processReader(r *os.File, pattern string, exp bool) []LineMatch {
func main() {
regexModePtr := flag.Bool("ex", false, "set if using g2eb expressions, leave for full string matching")
noHighlightPtr := flag.Bool("noh", false, "no hightlght")
filePtr := flag.String("f", "", "specify a file path to read file instead of stdin")
flag.Parse()
pattern := flag.Args()[0]
m := processReader(os.Stdin, pattern, *regexModePtr)
var in *os.File
if *filePtr != "" {
f, err := os.Open(*filePtr)
if err != nil {
_ = fmt.Errorf("Could not open file %s", *filePtr)
os.Exit(-1)
}
in = f
} else {
in = os.Stdin
}
m := processReader(in, pattern, *regexModePtr)
for _, lm := range m {
if *noHighlightPtr {