Skip to content
Myr

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

4 files+25 added−11 removed

modified:src/core.go+1 added-1 removed
226 unmodified lines
227228 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)233234 case EvtSearchNew:235 switch val := value.(type) {
57 unmodified lines
modified:src/reader.go+11 added-9 removed
15 unmodified lines
16}1718// ReadSource reads data from the default command or from standard input19func (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}3233func (r *Reader) feed(src io.Reader) {34 delim := byte('\n')
15 unmodified lines
50 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}6262func (r *Reader) readFromStdin() {63func (r *Reader) readFromStdin() bool {64 r.feed(os.Stdin)65 return true66}6766func (r *Reader) readFromCommand(cmd string) {68func (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 lines
93 pwindow tui.Window94 count int95 progress int96 reading bool97 success bool98 jumping jumpMode99 jumpLabels string100 printer func(string)101 merger *Merger
270 unmodified lines
372 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 lines
402 return copySlice(t.input)403}404405// UpdateCount updates the count information404func (t *Terminal) UpdateCount(cnt int, final bool) {406func (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 lines
684 }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 lines
modified:test/test_go.rb+6 added
258 unmodified lines
259 tmux.send_keys :Enter260 assert_equal 'hello', readonce.chomp261 end262263 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 end268269 def test_key_bindings270 tmux.send_keys "#{FZF} -q 'foo bar foo-bar'", :Enter271 tmux.until { |lines| lines.last =~ /^>/ }272
1355 unmodified lines