Skip to content

Commit

Permalink
Don't clear output view on jq error
Browse files Browse the repository at this point in the history
  • Loading branch information
gpanders committed May 24, 2022
1 parent 1dadddf commit 8ea776c
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,12 @@ func (d *Document) ReadFrom(r io.Reader) (n int64, err error) {
// Filter the document with the given jq filter and options
func (d *Document) WriteTo(w io.Writer) (n int64, err error) {
opts := d.options
if tv, ok := w.(*tview.TextView); ok {
if _, ok := w.(*tview.TextView); ok {
// Writer is a TextView, so set options accordingly
opts.forceColor = true
opts.monochrome = false
opts.compact = false
opts.rawOutput = false
tv.Clear()
w = tview.ANSIWriter(tv)
}

args := append(opts.ToSlice(), d.filter)
Expand All @@ -148,6 +146,11 @@ func (d *Document) WriteTo(w io.Writer) (n int64, err error) {
return 0, err
}

if tv, ok := w.(*tview.TextView); ok {
w = tview.ANSIWriter(tv)
tv.Clear()
}

m, err := w.Write(out)
n = int64(m)
return n, err
Expand Down

0 comments on commit 8ea776c

Please sign in to comment.