Add --cycle option for cyclic scrolling
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #266
authored by Junegunn Choi · committed by Junegunn Choi · parent d54a4fa · Browse files · 3 files·+43 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+43 added−3 removed
- tests:+19 added−0 removed
- other:+24 added−3 removed
Provenance
- Commit
fe4e452- Tree
2e9fb52- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
d54a4fa
3 files changed+43 added−3 removed
modified:src/options.go+7 added
35 unmodified lines36 --no-mouse Disable mouse37 --color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors38 --black Use black background39 --reverse Reverse orientation40+ --cycle Enable cyclic scroll41 --no-hscroll Disable horizontal scroll42 --inline-info Display finder info inline with the query43 --prompt=STR Input prompt (default: '> ')44 --toggle-sort=KEY Key to toggle sort62 unmodified lines107 Mouse bool108 Theme *curses.ColorTheme109 Black bool110 Reverse bool111+ Cycle bool112 Hscroll bool113 InlineInfo bool114 Prompt string115 Query string33 unmodified lines149 Mouse: true,150 Theme: defaultTheme(),151 Black: false,152 Reverse: false,153+ Cycle: false,154 Hscroll: true,155 InlineInfo: false,156 Prompt: "> ",157 Query: "",481 unmodified lines639 case "--reverse":640 opts.Reverse = true641 case "--no-reverse":642 opts.Reverse = false643+ case "--cycle":644+ opts.Cycle = true645+ case "--no-cycle":646+ opts.Cycle = false647 case "--hscroll":648 opts.Hscroll = true649 case "--no-hscroll":650 opts.Hscroll = false110 unmodified linesmodified:src/terminal.go+17 added-3 removed
37 unmodified lines38 execmap map[int]string39 pressed int40 printQuery bool41 history *History42+ cycle bool43 count int44 progress int45 reading bool46 merger *Merger148 unmodified lines195 execmap: opts.Execmap,196 pressed: 0,197 printQuery: opts.PrintQuery,198 history: opts.History,199+ cycle: opts.Cycle,200 merger: EmptyMerger,201 selected: make(map[uint32]selectedItem),202 reqBox: util.NewEventBox(),203 eventBox: eventBox,742 unmodified lines946 }947 948 func (t *Terminal) vmove(o int) {949 if t.reverse {948- t.vset(t.cy - o)949- } else {950- t.vset(t.cy + o)950+ o *= -1951 }952+ dest := t.cy + o953+ if t.cycle {954+ max := t.merger.Length() - 1955+ if dest > max {956+ if t.cy == max {957+ dest = 0958+ }959+ } else if dest < 0 {960+ if t.cy == 0 {961+ dest = max962+ }963+ }964+ }965+ t.vset(dest)966 }967 968 func (t *Terminal) vset(o int) bool {969 t.cy = util.Constrain(o, 0, t.merger.Length()-1)9 unmodified linesmodified:test/test_go.rb+19 added
613 unmodified lines614 ensure615 File.unlink output rescue nil616 end617 618+ def test_cycle619+ tmux.send_keys "seq 8 | #{fzf :cycle}", :Enter620+ tmux.until { |lines| lines[-2].include? '8/8' }621+ tmux.send_keys :Down622+ tmux.until { |lines| lines[-10].start_with? '>' }623+ tmux.send_keys :Down624+ tmux.until { |lines| lines[-9].start_with? '>' }625+ tmux.send_keys :PgUp626+ tmux.until { |lines| lines[-10].start_with? '>' }627+ tmux.send_keys :PgUp628+ tmux.until { |lines| lines[-3].start_with? '>' }629+ tmux.send_keys :Up630+ tmux.until { |lines| lines[-4].start_with? '>' }631+ tmux.send_keys :PgDn632+ tmux.until { |lines| lines[-3].start_with? '>' }633+ tmux.send_keys :PgDn634+ tmux.until { |lines| lines[-10].start_with? '>' }635+ end636+637 private638 def writelines path, lines639 File.unlink path while File.exists? path640 File.open(path, 'w') { |f| f << lines.join($/) }209 unmodified lines