summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-07-01 01:13:15 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-07-01 01:13:15 +0900
commit07ef2b051ccdc6917b9b65d157df3ebc8f3ff0de (patch)
treef33e2d3cba9e96d18e6d45bada5580a5fd0be0a2 /src
parent3fc795340d7787d1c64bfe755965d86370ca687b (diff)
Print [ERROR] on info line when the default command failed
With zero result. Related: https://github.com/junegunn/fzf.vim/issues/22#issuecomment-311869805
Diffstat (limited to 'src')
-rw-r--r--src/core.go2
-rw-r--r--src/reader.go20
-rw-r--r--src/terminal.go8
3 files changed, 19 insertions, 11 deletions
diff --git a/src/core.go b/src/core.go
index 6c3b321e..a528dbb6 100644
--- a/src/core.go
+++ b/src/core.go
@@ -228,7 +228,7 @@ func Run(opts *Options, revision string) {
case EvtReadNew, EvtReadFin:
reading = reading && evt == EvtReadNew
snapshot, count := chunkList.Snapshot()
- terminal.UpdateCount(count, !reading)
+ terminal.UpdateCount(count, !reading, value.(bool))
matcher.Reset(snapshot, terminal.Input(), false, !reading, sort)
case EvtSearchNew:
diff --git a/src/reader.go b/src/reader.go
index 7e8e2e01..1572e5de 100644
--- a/src/reader.go
+++ b/src/reader.go
@@ -17,16 +17,17 @@ type Reader struct {
// ReadSource reads data from the default command or from standard input
func (r *Reader) ReadSource() {
+ var success bool
if util.IsTty() {
cmd := os.Getenv("FZF_DEFAULT_COMMAND")
if len(cmd) == 0 {
cmd = defaultCommand
}
- r.readFromCommand(cmd)
+ success = r.readFromCommand(cmd)
} else {
- r.readFromStdin()
+ success = r.readFromStdin()
}
- r.eventBox.Set(EvtReadFin, nil)
+ r.eventBox.Set(EvtReadFin, success)
}
func (r *Reader) feed(src io.Reader) {
@@ -50,7 +51,7 @@ func (r *Reader) feed(src io.Reader) {
}
}
if r.pusher(bytea) {
- r.eventBox.Set(EvtReadNew, nil)
+ r.eventBox.Set(EvtReadNew, true)
}
}
if err != nil {
@@ -59,20 +60,21 @@ func (r *Reader) feed(src io.Reader) {
}
}
-func (r *Reader) readFromStdin() {
+func (r *Reader) readFromStdin() bool {
r.feed(os.Stdin)
+ return true
}
-func (r *Reader) readFromCommand(cmd string) {
+func (r *Reader) readFromCommand(cmd string) bool {
listCommand := util.ExecCommand(cmd)
out, err := listCommand.StdoutPipe()
if err != nil {
- return
+ return false
}
err = listCommand.Start()
if err != nil {
- return
+ return false
}
- defer listCommand.Wait()
r.feed(out)
+ return listCommand.Wait() == nil
}
diff --git a/src/terminal.go b/src/terminal.go
index fdd3caa4..d3c808d7 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -94,6 +94,7 @@ type Terminal struct {
count int
progress int
reading bool
+ success bool
jumping jumpMode
jumpLabels string
printer func(string)
@@ -372,6 +373,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
ansi: opts.Ansi,
tabstop: opts.Tabstop,
reading: true,
+ success: true,
jumping: jumpDisabled,
jumpLabels: opts.JumpLabels,
printer: opts.Printer,
@@ -401,10 +403,11 @@ func (t *Terminal) Input() []rune {
}
// UpdateCount updates the count information
-func (t *Terminal) UpdateCount(cnt int, final bool) {
+func (t *Terminal) UpdateCount(cnt int, final bool, success bool) {
t.mutex.Lock()
t.count = cnt
t.reading = !final
+ t.success = success
t.mutex.Unlock()
t.reqBox.Set(reqInfo, nil)
if final {
@@ -682,6 +685,9 @@ func (t *Terminal) printInfo() {
if t.progress > 0 && t.progress < 100 {
output += fmt.Sprintf(" (%d%%)", t.progress)
}
+ if !t.success && t.count == 0 {
+ output += " [ERROR]"
+ }
if pos+len(output) <= t.window.Width() {
t.window.CPrint(tui.ColInfo, 0, output)
}