1
1
mirror of https://github.com/wader/fq.git synced 2024-12-26 15:02:28 +03:00

Merge pull request #145 from wader/interp-unbreak-options-complete

repl,interp: Make stdio work during completion
This commit is contained in:
Mattias Wadman 2022-02-11 20:29:39 +01:00 committed by GitHub
commit 04ba899334
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -560,12 +560,12 @@ func (i *Interp) makeStateFn(state *interface{}) func(c interface{}, a []interfa
func (i *Interp) makeStdioFn(name string, t Terminal) func(c interface{}, a []interface{}) gojq.Iter {
return func(c interface{}, a []interface{}) gojq.Iter {
if i.evalContext.isCompleting {
return gojq.NewIter("")
}
switch {
case len(a) == 1:
if i.evalContext.isCompleting {
return gojq.NewIter("")
}
r, ok := t.(io.Reader)
if !ok {
return gojq.NewIter(fmt.Errorf("%s is not readable", name))
@ -596,6 +596,10 @@ func (i *Interp) makeStdioFn(name string, t Terminal) func(c interface{}, a []in
"height": h,
})
default:
if i.evalContext.isCompleting {
return gojq.NewIter()
}
w, ok := t.(io.Writer)
if !ok {
return gojq.NewIter(fmt.Errorf("%v: it not writeable", c))

View File

@ -60,4 +60,8 @@ mp3> "abc" | tobitsrange.s\t
size
start
stop
mp3> options.c\t
color
colors
compact
mp3> ^D