-f file
This commit is contained in:
22
main.go
22
main.go
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user