mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-22 19:09:00 +00:00
Add --reverse option (top-to-bottom layout)
This commit is contained in:
parent
db58182483
commit
f6b1a6278f
@ -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
|
||||
|
26
fzf
26
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 },
|
||||
|
@ -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}
|
||||
|
@ -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]
|
||||
|
Loading…
Reference in New Issue
Block a user