From f6b1a6278f7cee8d74ba198ba937cc787143dcfc Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 17 May 2014 22:07:18 +0900 Subject: Add --reverse option (top-to-bottom layout) --- README.md | 1 + fzf | 26 +++++++++++++++++--------- fzf.gemspec | 2 +- test/test_fzf.rb | 11 ++++++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index ab2fe2bc..a642da58 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ usage: fzf [options] +c, --no-color Disable colors +2, --no-256 Disable 256-color --black Use black background + --reverse Reverse orientation Scripting -q, --query=STR Start the finder with the given query diff --git a/fzf b/fzf index bcdc0770..a0a0a0da 100755 --- a/fzf +++ b/fzf @@ -7,7 +7,7 @@ # / __/ / /_/ __/ # /_/ /___/_/ Fuzzy finder for your shell # -# Version: 0.8.3 (April 3, 2014) +# Version: 0.8.4 (May 17, 2014) # # Author: Junegunn Choi # URL: https://github.com/junegunn/fzf @@ -50,7 +50,7 @@ end class FZF C = Curses - attr_reader :rxflag, :sort, :nth, :color, :black, :ansi256, + attr_reader :rxflag, :sort, :nth, :color, :black, :ansi256, :reverse, :mouse, :multi, :query, :select1, :exit0, :filter, :extended class AtomicVar @@ -88,6 +88,7 @@ class FZF @filter = nil @nth = nil @delim = nil + @reverse = false argv = if opts = ENV['FZF_DEFAULT_OPTS'] @@ -114,6 +115,8 @@ class FZF when '--no-black' then @black = false when '--mouse' then @mouse = true when '--no-mouse' then @mouse = false + when '--reverse' then @reverse = true + when '--no-reverse' then @reverse = false when '+s', '--no-sort' then @sort = nil when '-1', '--select-1' then @select1 = true when '+1', '--no-select-1' then @select1 = false @@ -292,6 +295,7 @@ class FZF +c, --no-color Disable colors +2, --no-256 Disable 256-color --black Use black background + --reverse Reverse orientation Scripting -q, --query=STR Start the finder with the given query @@ -428,7 +432,11 @@ class FZF end def max_items; C.lines - 2; end - def cursor_y; C.lines - 1; end + + def cursor_y offset = 0 + @reverse ? (offset) : (C.lines - 1 - offset) + end + def cprint str, col C.attron(col) do addstr_safe str @@ -448,7 +456,7 @@ class FZF end def print_info msg = nil - C.setpos cursor_y - 1, 0 + C.setpos cursor_y(1), 0 C.clrtoeol prefix = if spinner = @spinner.first @@ -766,7 +774,7 @@ class FZF # Wipe if items.length < @plcount @plcount.downto(items.length) do |idx| - C.setpos cursor_y - idx - 2, 0 + C.setpos cursor_y(idx + 2), 0 C.clrtoeol end end @@ -781,7 +789,7 @@ class FZF } items.each_with_index do |item, idx| next unless wipe || cleanse.include?(idx) - row = cursor_y - idx - 2 + row = cursor_y(idx + 2) chosen = idx == vcursor selected = @selects.include?([*item][0]) line, offsets = convert_item item @@ -1000,8 +1008,8 @@ class FZF }, ctrl(:a) => proc { cursor = 0; nil }, ctrl(:e) => proc { cursor = input.length; nil }, - ctrl(:j) => proc { vselect { |v| v - 1 } }, - ctrl(:k) => proc { vselect { |v| v + 1 } }, + ctrl(:j) => proc { vselect { |v| v - (@reverse ? -1 : 1) } }, + ctrl(:k) => proc { vselect { |v| v + (@reverse ? -1 : 1) } }, ctrl(:w) => proc { pcursor = cursor backword.call @@ -1021,7 +1029,7 @@ class FZF when :stab then 1 when :sclick then 0 else -1 - end } + end * (@reverse ? -1 : 1) } end }, ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil }, diff --git a/fzf.gemspec b/fzf.gemspec index 3a00757c..0a6c74da 100644 --- a/fzf.gemspec +++ b/fzf.gemspec @@ -1,7 +1,7 @@ # coding: utf-8 Gem::Specification.new do |spec| spec.name = 'fzf' - spec.version = '0.8.3' + spec.version = '0.8.4' spec.authors = ['Junegunn Choi'] spec.email = ['junegunn.c@gmail.com'] spec.description = %q{Fuzzy finder for your shell} diff --git a/test/test_fzf.rb b/test/test_fzf.rb index d3beb092..d316151d 100644 --- a/test/test_fzf.rb +++ b/test/test_fzf.rb @@ -32,6 +32,7 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal false, fzf.exit0 assert_equal nil, fzf.filter assert_equal nil, fzf.extended + assert_equal false, fzf.reverse end def test_environment_variables @@ -43,7 +44,7 @@ class TestFZF < MiniTest::Unit::TestCase ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c +2 --select-1 -0 ' + - '--no-mouse -f "goodbye world" --black --nth=3,-1,2' + '--no-mouse -f "goodbye world" --black --nth=3,-1,2 --reverse' fzf = FZF.new [] assert_equal 10000, fzf.sort assert_equal ' hello world ', @@ -58,6 +59,7 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal false, fzf.mouse assert_equal true, fzf.select1 assert_equal true, fzf.exit0 + assert_equal true, fzf.reverse assert_equal [3, -1, 2], fzf.nth end @@ -65,7 +67,7 @@ class TestFZF < MiniTest::Unit::TestCase # Long opts fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello --select-1 --exit-0 --filter=howdy --extended-exact - --no-mouse --no-256 --nth=1] + --no-mouse --no-256 --nth=1 --reverse] assert_equal 2000, fzf.sort assert_equal true, fzf.multi assert_equal false, fzf.color @@ -79,12 +81,14 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal 'howdy', fzf.filter assert_equal :exact, fzf.extended assert_equal [1], fzf.nth + assert_equal true, fzf.reverse # Long opts (left-to-right) fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query=hello --filter a --filter b --no-256 --black --nth -1 --nth -2 --select-1 --exit-0 --no-select-1 --no-exit-0 - --no-sort -i --color --no-multi --256] + --no-sort -i --color --no-multi --256 + --reverse --no-reverse] assert_equal nil, fzf.sort assert_equal false, fzf.multi assert_equal true, fzf.color @@ -98,6 +102,7 @@ class TestFZF < MiniTest::Unit::TestCase assert_equal false, fzf.exit0 assert_equal nil, fzf.extended assert_equal [-2], fzf.nth + assert_equal false, fzf.reverse # Short opts fzf = FZF.new %w[-s2000 +c -m +i -qhello -x -fhowdy +2 -n3 -1 -0] -- cgit v1.2.3