~gpanders/ijq

6c5db72c230f2cd8408b286eb3040a6ffcf515df — Greg Anders a month ago a6ffb22
Read initial filter from file with -f flag
2 files changed, 16 insertions(+), 5 deletions(-)

M README.md
M main.go
M README.md => README.md +2 -2
@@ 63,10 63,10 @@ You can use this in a pipe, .e.g.
This will also print the current filter to stderr. This allows you to save the
filter for re-use with `jq` in the future:

    ijq file.json 2>filter.txt
    ijq file.json 2>filter.jq

    # Same output as above
    jq -f filter.txt file.json
    jq -f filter.jq file.json

Press `Tab` or `Shift-Tab` to cycle through the windows. The display windows
can be scrolled using Vim-like bindings, i.e. `hjkl` or the arrow keys.

M main.go => main.go +14 -3
@@ 129,7 129,7 @@ func main() {
	flag.BoolVar(&options.monochrome, "M", false, "don't colorize JSON")
	flag.BoolVar(&options.sortKeys, "S", false, "sort keys of objects on output")

	filter := flag.String("f", ".", "initial filter")
	filterFile := flag.String("f", "", "read initial filter from `filename`")
	version := flag.Bool("V", false, "print version and exit")

	flag.Parse()


@@ 154,6 154,17 @@ func main() {

	outputWriter := tview.ANSIWriter(outputView)

	filter := "."
	if *filterFile != "" {
		contents, err := ioutil.ReadFile(*filterFile)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", err)
			os.Exit(1)
		}

		filter = string(contents)
	}

	doc := Document{options: options}
	go func() {
		if flag.Arg(0) != "" {


@@ 168,7 179,7 @@ func main() {
			}
		}

		out, err := doc.Filter(*filter)
		out, err := doc.Filter(filter)
		if err != nil {
			fmt.Fprintf(os.Stderr, "%s\n", err)
			os.Exit(1)


@@ 180,7 191,7 @@ func main() {

	filterInput := tview.NewInputField()
	filterInput.
		SetText(*filter).
		SetText(filter).
		SetFieldBackgroundColor(0).
		SetFieldTextColor(7).
		SetChangedFunc(func(text string) {