Skip to content
This repository has been archived by the owner on Nov 26, 2023. It is now read-only.

Commit

Permalink
keep the previous output when there's an error.
Browse files Browse the repository at this point in the history
so that we don't just see errors 99% of the time.
closes #20
  • Loading branch information
fiatjaf committed Aug 21, 2020
1 parent 0e02ccd commit f348448
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
17 changes: 12 additions & 5 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ func (e *Engine) Run() *EngineResult {
defer termbox.Close()
termbox.SetInputMode(termbox.InputAlt)

var contents []string
var contents []string = []string{""}

for {
e.candidates = []string{}
e.autocomplete = ""
contents = e.getContents()
contents = e.getContents(contents)
e.makeCandidates()
e.setCandidateData()

Expand Down Expand Up @@ -180,9 +180,16 @@ func (e *Engine) Run() *EngineResult {
}
}

func (e *Engine) getContents() []string {
cc, _ := jqrun(e.query.StringGet(), e.json, e.args)
return strings.Split(cc, "\n")
func (e *Engine) getContents(prevContents []string) []string {
cc, err := jqrun(e.query.StringGet(), e.json, e.args)
if err == nil {
return strings.Split("\n"+cc, "\n")
} else {
return append(
strings.Split(cc[0:strings.Index(cc, "\n")], "\n"),
prevContents[1:]...,
)
}
}

var complicatedKeyRegex = regexp.MustCompile(`\d|\W`)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.14
require (
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1
github.com/stretchr/testify v1.6.1
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1 h1:lh3PyZvY+B9nFliSGTn5uFuqQQJGuNrD0MLCokv09ag=
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit f348448

Please sign in to comment.