added pattern highlighting support

This commit is contained in:
2022-10-10 20:14:51 +02:00
parent 34e2b8d855
commit f890596b4c
11 changed files with 74 additions and 8 deletions

View File

@@ -20,6 +20,8 @@ package lib
import (
"errors"
"fmt"
"github.com/gookit/color"
"os"
"regexp"
"strconv"
"strings"
@@ -130,3 +132,21 @@ func trimRow(row []string) []string {
return fixedrow
}
func colorizeData(output string) string {
if len(Pattern) > 0 && !NoColor && color.IsConsole(os.Stdout) {
r := regexp.MustCompile("(" + Pattern + ")")
return r.ReplaceAllString(output, "<bg="+MatchBG+";fg="+MatchFG+">$1</>")
} else {
return output
}
}
func isTerminal(f *os.File) bool {
o, _ := f.Stat()
if (o.Mode() & os.ModeCharDevice) == os.ModeCharDevice {
return true
} else {
return false
}
}