Print [ERROR] on info line when the default command failed
Before adoption: this commit came in with the history the project adopted, so no landing records it.
With zero result.
authored by Junegunn Choi · committed by Junegunn Choi · parent 3fc7953 · Browse files · 4 files·+25 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Related: https://github.com/junegunn/fzf.vim/issues/22#issuecomment-311869805
Diff stats
4 files+25 added−11 removed
- tests:+6 added−0 removed
- other:+19 added−11 removed
Provenance
- Commit
07ef2b0- Tree
f33e2d3- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
3fc7953
4 files changed+25 added−11 removed
modified:src/core.go+1 added-1 removed
226 unmodified lines227 228 case EvtReadNew, EvtReadFin:229 reading = reading && evt == EvtReadNew230 snapshot, count := chunkList.Snapshot()231- terminal.UpdateCount(count, !reading)231+ terminal.UpdateCount(count, !reading, value.(bool))232 matcher.Reset(snapshot, terminal.Input(), false, !reading, sort)233 234 case EvtSearchNew:235 switch val := value.(type) {57 unmodified linesmodified:src/reader.go+11 added-9 removed
15 unmodified lines16 }17 18 // ReadSource reads data from the default command or from standard input19 func (r *Reader) ReadSource() {20+ var success bool21 if util.IsTty() {22 cmd := os.Getenv("FZF_DEFAULT_COMMAND")23 if len(cmd) == 0 {24 cmd = defaultCommand25 }25- r.readFromCommand(cmd)26+ success = r.readFromCommand(cmd)27 } else {27- r.readFromStdin()28+ success = r.readFromStdin()29 }29- r.eventBox.Set(EvtReadFin, nil)30+ r.eventBox.Set(EvtReadFin, success)31 }32 33 func (r *Reader) feed(src io.Reader) {34 delim := byte('\n')15 unmodified lines50 bytea = bytea[:byteaLen-1]51 }52 }53 if r.pusher(bytea) {53- r.eventBox.Set(EvtReadNew, nil)54+ r.eventBox.Set(EvtReadNew, true)55 }56 }57 if err != nil {58 break59 }60 }61 }62 62-func (r *Reader) readFromStdin() {63+func (r *Reader) readFromStdin() bool {64 r.feed(os.Stdin)65+ return true66 }67 66-func (r *Reader) readFromCommand(cmd string) {68+func (r *Reader) readFromCommand(cmd string) bool {69 listCommand := util.ExecCommand(cmd)70 out, err := listCommand.StdoutPipe()71 if err != nil {70- return72+ return false73 }74 err = listCommand.Start()75 if err != nil {74- return76+ return false77 }76- defer listCommand.Wait()78 r.feed(out)79+ return listCommand.Wait() == nil80 }modified:src/terminal.go+7 added-1 removed
92 unmodified lines93 pwindow tui.Window94 count int95 progress int96 reading bool97+ success bool98 jumping jumpMode99 jumpLabels string100 printer func(string)101 merger *Merger270 unmodified lines372 header0: header,373 ansi: opts.Ansi,374 tabstop: opts.Tabstop,375 reading: true,376+ success: true,377 jumping: jumpDisabled,378 jumpLabels: opts.JumpLabels,379 printer: opts.Printer,380 merger: EmptyMerger,21 unmodified lines402 return copySlice(t.input)403 }404 405 // UpdateCount updates the count information404-func (t *Terminal) UpdateCount(cnt int, final bool) {406+func (t *Terminal) UpdateCount(cnt int, final bool, success bool) {407 t.mutex.Lock()408 t.count = cnt409 t.reading = !final410+ t.success = success411 t.mutex.Unlock()412 t.reqBox.Set(reqInfo, nil)413 if final {414 t.reqBox.Set(reqRefresh, nil)269 unmodified lines684 }685 if t.progress > 0 && t.progress < 100 {686 output += fmt.Sprintf(" (%d%%)", t.progress)687 }688+ if !t.success && t.count == 0 {689+ output += " [ERROR]"690+ }691 if pos+len(output) <= t.window.Width() {692 t.window.CPrint(tui.ColInfo, 0, output)693 }694 }1144 unmodified linesmodified:test/test_go.rb+6 added
258 unmodified lines259 tmux.send_keys :Enter260 assert_equal 'hello', readonce.chomp261 end262 263+ def test_fzf_default_command_failure264+ tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', 'FZF_DEFAULT_COMMAND=false'), :Enter265+ tmux.until { |lines| lines[-2].include?('ERROR') }266+ tmux.send_keys :Enter267+ end268+269 def test_key_bindings270 tmux.send_keys "#{FZF} -q 'foo bar foo-bar'", :Enter271 tmux.until { |lines| lines.last =~ /^>/ }272 1355 unmodified lines