Add --reverse option (top-to-bottom layout)
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 db58182 · Browse files · 4 files·+27 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+27 added−13 removed
- tests:+8 added−3 removed
- other:+19 added−10 removed
Provenance
- Commit
f6b1a62- Tree
9ba2c66- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
db58182
4 files changed+27 added−13 removed
modified:test/test_fzf.rb+8 added-3 removed
30 unmodified lines31 assert_equal false, fzf.select132 assert_equal false, fzf.exit033 assert_equal nil, fzf.filter34 assert_equal nil, fzf.extended35+ assert_equal false, fzf.reverse36 end37 38 def test_environment_variables39 # Deprecated3 unmodified lines43 assert_equal nil, fzf.nth44 45 ENV['FZF_DEFAULT_OPTS'] =46 '-x -m -s 10000 -q " hello world " +c +2 --select-1 -0 ' +46- '--no-mouse -f "goodbye world" --black --nth=3,-1,2'47+ '--no-mouse -f "goodbye world" --black --nth=3,-1,2 --reverse'48 fzf = FZF.new []49 assert_equal 10000, fzf.sort50 assert_equal ' hello world ',51 fzf.query.get6 unmodified lines58 assert_equal true, fzf.black59 assert_equal false, fzf.mouse60 assert_equal true, fzf.select161 assert_equal true, fzf.exit062+ assert_equal true, fzf.reverse63 assert_equal [3, -1, 2], fzf.nth64 end65 66 def test_option_parser67 # Long opts68 fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello --select-169 --exit-0 --filter=howdy --extended-exact68- --no-mouse --no-256 --nth=1]70+ --no-mouse --no-256 --nth=1 --reverse]71 assert_equal 2000, fzf.sort72 assert_equal true, fzf.multi73 assert_equal false, fzf.color74 assert_equal false, fzf.ansi2565 unmodified lines80 assert_equal true, fzf.exit081 assert_equal 'howdy', fzf.filter82 assert_equal :exact, fzf.extended83 assert_equal [1], fzf.nth84+ assert_equal true, fzf.reverse85 86 # Long opts (left-to-right)87 fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query=hello88 --filter a --filter b --no-256 --black --nth -1 --nth -289 --select-1 --exit-0 --no-select-1 --no-exit-087- --no-sort -i --color --no-multi --256]90+ --no-sort -i --color --no-multi --25691+ --reverse --no-reverse]92 assert_equal nil, fzf.sort93 assert_equal false, fzf.multi94 assert_equal true, fzf.color95 assert_equal true, fzf.ansi2565 unmodified lines101 assert_equal false, fzf.select1102 assert_equal false, fzf.exit0103 assert_equal nil, fzf.extended104 assert_equal [-2], fzf.nth105+ assert_equal false, fzf.reverse106 107 # Short opts108 fzf = FZF.new %w[-s2000 +c -m +i -qhello -x -fhowdy +2 -n3 -1 -0]109 assert_equal 2000, fzf.sort561 unmodified linesmodified:fzf+17 added-9 removed
5 unmodified lines6 # / /_/_ / / /_7 # / __/ / /_/ __/8 # /_/ /___/_/ Fuzzy finder for your shell9 #10-# Version: 0.8.3 (April 3, 2014)10+# Version: 0.8.4 (May 17, 2014)11 #12 # Author: Junegunn Choi13 # URL: https://github.com/junegunn/fzf14 # License: MIT34 unmodified lines49 end50 51 class FZF52 C = Curses53- attr_reader :rxflag, :sort, :nth, :color, :black, :ansi256,53+ attr_reader :rxflag, :sort, :nth, :color, :black, :ansi256, :reverse,54 :mouse, :multi, :query, :select1, :exit0, :filter, :extended55 56 class AtomicVar57 def initialize value29 unmodified lines87 @exit0 = false88 @filter = nil89 @nth = nil90 @delim = nil91+ @reverse = false92 93 argv =94 if opts = ENV['FZF_DEFAULT_OPTS']95 require 'shellwords'18 unmodified lines114 when '--black' then @black = true115 when '--no-black' then @black = false116 when '--mouse' then @mouse = true117 when '--no-mouse' then @mouse = false118+ when '--reverse' then @reverse = true119+ when '--no-reverse' then @reverse = false120 when '+s', '--no-sort' then @sort = nil121 when '-1', '--select-1' then @select1 = true122 when '+1', '--no-select-1' then @select1 = false123 when '-0', '--exit-0' then @exit0 = true170 unmodified lines294 --no-mouse Disable mouse295 +c, --no-color Disable colors296 +2, --no-256 Disable 256-color297 --black Use black background298+ --reverse Reverse orientation299 300 Scripting301 -q, --query=STR Start the finder with the given query302 -1, --select-1 Automatically select the only match128 unmodified lines431 end432 end433 434 def max_items; C.lines - 2; end431- def cursor_y; C.lines - 1; end435+436+ def cursor_y offset = 0437+ @reverse ? (offset) : (C.lines - 1 - offset)438+ end439+440 def cprint str, col441 C.attron(col) do442 addstr_safe str443 end if str11 unmodified lines455 end456 end457 458 def print_info msg = nil451- C.setpos cursor_y - 1, 0459+ C.setpos cursor_y(1), 0460 C.clrtoeol461 prefix =462 if spinner = @spinner.first463 cprint spinner, color(:spinner, true)309 unmodified lines773 774 # Wipe775 if items.length < @plcount776 @plcount.downto(items.length) do |idx|769- C.setpos cursor_y - idx - 2, 0777+ C.setpos cursor_y(idx + 2), 0778 C.clrtoeol779 end780 end781 @plcount = items.length6 unmodified lines788 Set.new789 }790 items.each_with_index do |item, idx|791 next unless wipe || cleanse.include?(idx)784- row = cursor_y - idx - 2792+ row = cursor_y(idx + 2)793 chosen = idx == vcursor794 selected = @selects.include?([*item][0])795 line, offsets = convert_item item796 tokens = format line, maxc, offsets210 unmodified lines1007 cursor = 01008 },1009 ctrl(:a) => proc { cursor = 0; nil },1010 ctrl(:e) => proc { cursor = input.length; nil },1003- ctrl(:j) => proc { vselect { |v| v - 1 } },1004- ctrl(:k) => proc { vselect { |v| v + 1 } },1011+ ctrl(:j) => proc { vselect { |v| v - (@reverse ? -1 : 1) } },1012+ ctrl(:k) => proc { vselect { |v| v + (@reverse ? -1 : 1) } },1013 ctrl(:w) => proc {1014 pcursor = cursor1015 backword.call1016 yanked = input[cursor...pcursor] if pcursor > cursor11 unmodified lines1028 vselect { |v| v + case o1029 when :stab then 11030 when :sclick then 01031 else -11024- end }1032+ end * (@reverse ? -1 : 1) }1033 end1034 },1035 ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil },1036 ctrl(:f) => proc { cursor = [input.length, cursor + 1].min; nil },253 unmodified linesmodified:fzf.gemspec+1 added-1 removed
1 # coding: utf-82 Gem::Specification.new do |spec|3 spec.name = 'fzf'4- spec.version = '0.8.3'4+ spec.version = '0.8.4'5 spec.authors = ['Junegunn Choi']6 spec.email = ['junegunn.c@gmail.com']7 spec.description = %q{Fuzzy finder for your shell}8 spec.summary = %q{Fuzzy finder for your shell}9 unmodified linesmodified:README.md+1 added
77 unmodified lines78 --no-mouse Disable mouse79 +c, --no-color Disable colors80 +2, --no-256 Disable 256-color81 --black Use black background82+ --reverse Reverse orientation83 84 Scripting85 -q, --query=STR Start the finder with the given query86 -1, --select-1 Automatically select the only match443 unmodified lines