~yerinalexey/rex

2c14faf0ac67d0b9fb95bcc62fd6c858ed3c6b26 — Alexey Yerin 5 months ago 4cc8c39
Add -input option to set default regex
1 files changed, 6 insertions(+), 3 deletions(-)

M main.go
M main.go => main.go +6 -3
@@ 33,6 33,9 @@ import (
type Options struct {
	// Show help message
	help bool

	// Default value for regex input
	input string
}

func fatalf(format string, v ...interface{}) {


@@ 106,6 109,7 @@ func main() {
	opts := Options{}

	// TODO: More flags
	flag.StringVar(&opts.input, "input", ".", "Default value for regex input")
	flag.BoolVar(&opts.help, "help", false, "Show this message")
	flag.Parse()



@@ 142,7 146,7 @@ func main() {
	regexInput := tview.NewInputField().
		SetLabel("Regex: ").
		SetFieldBackgroundColor(tview.Styles.PrimitiveBackgroundColor).
		SetText(".").
		SetText(opts.input).
		SetChangedFunc(func(text string) {
			exprChan <- text
		})


@@ 157,8 161,7 @@ func main() {
	go regexWorker(exprChan, data, matchesView)

	// Load initial expression
	// TODO: Do this in better way (maybe command line flag?)
	exprChan <- "."
	exprChan <- opts.input

	grid := tview.NewGrid().
		SetBorders(true).