diff --git a/main.go b/main.go index e750517..872da57 100644 --- a/main.go +++ b/main.go @@ -17,14 +17,17 @@ func main() { versionOption := flag.Bool("version", false, "Version of gee") appendOption := flag.Bool("append", false, "Append mode for files") chunkedLineOption := flag.Int("chunked", 0, "Chuked files from line (e.g output / output_1 / output_2)") - withLineOption := flag.Bool("with-line", false, "With line number") - withTimeOption := flag.Bool("with-time", false, "With timestamp") + withLineOption := flag.Bool("with-line", false, "With line number (colorize blue)") + withTimeOption := flag.Bool("with-time", false, "With timestamp (colorize blue)") prefixOption := flag.String("prefix", "", "Prefix string") suffixOption := flag.String("suffix", "", "Suffix string") rmnlOption := flag.Bool("rmnl", false, "Remove newline(\\r\\n)") distributeOption := flag.Bool("distribute", false, "Distribution to files") + colorOption := flag.Bool("uncolor", false, "Uncolorize stdout") regexOption := flag.String("regex", "", "Match with Regular Expression (like grep)") regexvOption := flag.String("regexv", "", "Unmatch with Regular Expression (like grep -v)") + findOption := flag.String("find", "", "Find string in line (colorize red)") + replaceOption := flag.String("replace", "", "Replace string in line with '-find' option") // Custom usage flag.Usage = func() { @@ -66,6 +69,9 @@ func main() { Distribute: *distributeOption, Regex: *regexOption, RegexV: *regexvOption, + Replace: *replaceOption, + Find: *findOption, + Color: !*colorOption, } // Running gee app diff --git a/pkg/gee/gee.go b/pkg/gee/gee.go index 7c96eed..31db8fe 100644 --- a/pkg/gee/gee.go +++ b/pkg/gee/gee.go @@ -43,19 +43,14 @@ func Gee(options model.Options) { regexBool = RegexV(options.RegexV, l) } if regexBool { - line := "" - if options.WithLine { - l = "[" + strconv.Itoa(stdLine) + "] " + l - } - if options.WithTimestamp { - l = "[" + GetNowTime() + "] " + l - } + linec, line := StringProc(l, stdLine, options) // Prefix and Suffix - line = options.Prefix + l + options.Suffix + line = options.Prefix + line + options.Suffix + linec = options.Prefix + linec + options.Suffix // Print to Stdout - StdPrint(line, options) + StdPrint(linec, options) // Write to files if (stdLine > options.ChunkedLine) && (options.ChunkedLine != 0) { diff --git a/pkg/gee/string.go b/pkg/gee/string.go new file mode 100644 index 0000000..8b269bc --- /dev/null +++ b/pkg/gee/string.go @@ -0,0 +1,33 @@ +package gee + +import ( + "strconv" + "strings" + + "github.com/hahwul/gee/pkg/model" + "github.com/logrusorgru/aurora" +) + +// StringProc is string +func StringProc(l string, stdLine int, options model.Options) (string, string) { + result := l + resultPlain := l + au := aurora.NewAurora(options.Color) + if options.Find != "" { + if options.Replace != "" { + result = strings.Replace(result, options.Find, au.BrightRed(options.Replace).String(), -1) + resultPlain = strings.Replace(resultPlain, options.Find, options.Replace, -1) + } else { + result = strings.Replace(result, options.Find, au.BrightRed(options.Find).String(), -1) + } + } + if options.WithLine { + result = au.BrightBlue("["+strconv.Itoa(stdLine)+"] ").String() + result + resultPlain = "[" + strconv.Itoa(stdLine) + "] " + resultPlain + } + if options.WithTimestamp { + result = au.BrightBlue("["+GetNowTime()+"] ").String() + result + resultPlain = "[" + GetNowTime() + "] " + resultPlain + } + return result, resultPlain +} diff --git a/pkg/model/options.go b/pkg/model/options.go index 77bd2bf..4dfd784 100644 --- a/pkg/model/options.go +++ b/pkg/model/options.go @@ -16,4 +16,7 @@ type Options struct { RegexV string Split string Distribute bool + Replace string + Find string + Color bool }