Skip to content
Myr

Print selected items in the order they are selected

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent 0a83705 · Browse files · 2 files+48 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+48 added−9 removed

  • tests:+13 added−0 removed
  • other:+35 added−9 removed

2 files+48 added−9 removed

modified:src/terminal.go+35 added-9 removed
28 unmodified lines
29 count int30 progress int31 reading bool32 merger *Merger33 selected map[*string]*string33 selected map[*string]selectedItem34 reqBox *util.EventBox35 eventBox *util.EventBox36 mutex sync.Mutex37 initFunc func()38 suppress bool39}4041type selectedItem struct {42 at time.Time43 text *string44}4546type ByTimeOrder []selectedItem4748func (a ByTimeOrder) Len() int {49 return len(a)50}5152func (a ByTimeOrder) Swap(i, j int) {53 a[i], a[j] = a[j], a[i]54}5556func (a ByTimeOrder) Less(i, j int) bool {57 return a[i].at.Before(a[j].at)58}5960var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}6162const (63 reqPrompt util.EventType = iota
24 unmodified lines
88 input: input,89 multi: opts.Multi,90 printQuery: opts.PrintQuery,91 merger: EmptyMerger,73 selected: make(map[*string]*string),92 selected: make(map[*string]selectedItem),93 reqBox: util.NewEventBox(),94 eventBox: eventBox,95 mutex: sync.Mutex{},96 suppress: true,
60 unmodified lines
157 if cnt > 0 && cnt > t.cy {158 fmt.Println(t.merger.Get(t.listIndex(t.cy)).AsString())159 }160 } else {142 for ptr, orig := range t.selected {143 if orig != nil {144 fmt.Println(*orig)145 } else {146 fmt.Println(*ptr)147 }161 sels := make([]selectedItem, 0, len(t.selected))162 for _, sel := range t.selected {163 sels = append(sels, sel)164 }165 sort.Sort(ByTimeOrder(sels))166 for _, sel := range sels {167 fmt.Println(*sel.text)168 }169 }170}171172func displayWidth(runes []rune) int {
290 unmodified lines
463 idx := t.listIndex(t.cy)464 if idx < t.merger.Length() {465 item := t.merger.Get(idx)466 if _, found := t.selected[item.text]; !found {447 t.selected[item.text] = item.origText467 var strptr *string468 if item.origText != nil {469 strptr = item.origText470 } else {471 strptr = item.text472 }473 t.selected[item.text] = selectedItem{time.Now(), strptr}474 } else {475 delete(t.selected, item.text)476 }477 req(reqInfo)
177 unmodified lines
modified:test/test_go.rb+13 added
187 unmodified lines
188 tmux.send_keys "C-M"189 tmux.until { |lines| lines.last !~ /^>/ }190 tmux.close191 end192193 def test_fzf_multi_order194 tmux.send_keys "seq 1 10 | fzf --multi > #{tempname}", :Enter195 tmux.until { |lines| lines.last =~ /^>/ }196197 tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2198 'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6199 :PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7200 tmux.until { |lines| lines[-2].include? '(6)' }201 tmux.send_keys "C-M"202 assert_equal %w[3 2 5 6 8 7], File.read(tempname).split($/)203 tmux.close204 end205end206