mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 21:05:09 +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
|
+c, --no-color Disable colors
|
||||||
+2, --no-256 Disable 256-color
|
+2, --no-256 Disable 256-color
|
||||||
--black Use black background
|
--black Use black background
|
||||||
|
--reverse Reverse orientation
|
||||||
|
|
||||||
Scripting
|
Scripting
|
||||||
-q, --query=STR Start the finder with the given query
|
-q, --query=STR Start the finder with the given query
|
||||||
|
26
fzf
26
fzf
@ -7,7 +7,7 @@
|
|||||||
# / __/ / /_/ __/
|
# / __/ / /_/ __/
|
||||||
# /_/ /___/_/ Fuzzy finder for your shell
|
# /_/ /___/_/ Fuzzy finder for your shell
|
||||||
#
|
#
|
||||||
# Version: 0.8.3 (April 3, 2014)
|
# Version: 0.8.4 (May 17, 2014)
|
||||||
#
|
#
|
||||||
# Author: Junegunn Choi
|
# Author: Junegunn Choi
|
||||||
# URL: https://github.com/junegunn/fzf
|
# URL: https://github.com/junegunn/fzf
|
||||||
@ -50,7 +50,7 @@ end
|
|||||||
|
|
||||||
class FZF
|
class FZF
|
||||||
C = Curses
|
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
|
:mouse, :multi, :query, :select1, :exit0, :filter, :extended
|
||||||
|
|
||||||
class AtomicVar
|
class AtomicVar
|
||||||
@ -88,6 +88,7 @@ class FZF
|
|||||||
@filter = nil
|
@filter = nil
|
||||||
@nth = nil
|
@nth = nil
|
||||||
@delim = nil
|
@delim = nil
|
||||||
|
@reverse = false
|
||||||
|
|
||||||
argv =
|
argv =
|
||||||
if opts = ENV['FZF_DEFAULT_OPTS']
|
if opts = ENV['FZF_DEFAULT_OPTS']
|
||||||
@ -114,6 +115,8 @@ class FZF
|
|||||||
when '--no-black' then @black = false
|
when '--no-black' then @black = false
|
||||||
when '--mouse' then @mouse = true
|
when '--mouse' then @mouse = true
|
||||||
when '--no-mouse' then @mouse = false
|
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 '+s', '--no-sort' then @sort = nil
|
||||||
when '-1', '--select-1' then @select1 = true
|
when '-1', '--select-1' then @select1 = true
|
||||||
when '+1', '--no-select-1' then @select1 = false
|
when '+1', '--no-select-1' then @select1 = false
|
||||||
@ -292,6 +295,7 @@ class FZF
|
|||||||
+c, --no-color Disable colors
|
+c, --no-color Disable colors
|
||||||
+2, --no-256 Disable 256-color
|
+2, --no-256 Disable 256-color
|
||||||
--black Use black background
|
--black Use black background
|
||||||
|
--reverse Reverse orientation
|
||||||
|
|
||||||
Scripting
|
Scripting
|
||||||
-q, --query=STR Start the finder with the given query
|
-q, --query=STR Start the finder with the given query
|
||||||
@ -428,7 +432,11 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
def max_items; C.lines - 2; 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
|
def cprint str, col
|
||||||
C.attron(col) do
|
C.attron(col) do
|
||||||
addstr_safe str
|
addstr_safe str
|
||||||
@ -448,7 +456,7 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
def print_info msg = nil
|
def print_info msg = nil
|
||||||
C.setpos cursor_y - 1, 0
|
C.setpos cursor_y(1), 0
|
||||||
C.clrtoeol
|
C.clrtoeol
|
||||||
prefix =
|
prefix =
|
||||||
if spinner = @spinner.first
|
if spinner = @spinner.first
|
||||||
@ -766,7 +774,7 @@ class FZF
|
|||||||
# Wipe
|
# Wipe
|
||||||
if items.length < @plcount
|
if items.length < @plcount
|
||||||
@plcount.downto(items.length) do |idx|
|
@plcount.downto(items.length) do |idx|
|
||||||
C.setpos cursor_y - idx - 2, 0
|
C.setpos cursor_y(idx + 2), 0
|
||||||
C.clrtoeol
|
C.clrtoeol
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -781,7 +789,7 @@ class FZF
|
|||||||
}
|
}
|
||||||
items.each_with_index do |item, idx|
|
items.each_with_index do |item, idx|
|
||||||
next unless wipe || cleanse.include?(idx)
|
next unless wipe || cleanse.include?(idx)
|
||||||
row = cursor_y - idx - 2
|
row = cursor_y(idx + 2)
|
||||||
chosen = idx == vcursor
|
chosen = idx == vcursor
|
||||||
selected = @selects.include?([*item][0])
|
selected = @selects.include?([*item][0])
|
||||||
line, offsets = convert_item item
|
line, offsets = convert_item item
|
||||||
@ -1000,8 +1008,8 @@ class FZF
|
|||||||
},
|
},
|
||||||
ctrl(:a) => proc { cursor = 0; nil },
|
ctrl(:a) => proc { cursor = 0; nil },
|
||||||
ctrl(:e) => proc { cursor = input.length; nil },
|
ctrl(:e) => proc { cursor = input.length; nil },
|
||||||
ctrl(:j) => proc { vselect { |v| v - 1 } },
|
ctrl(:j) => proc { vselect { |v| v - (@reverse ? -1 : 1) } },
|
||||||
ctrl(:k) => proc { vselect { |v| v + 1 } },
|
ctrl(:k) => proc { vselect { |v| v + (@reverse ? -1 : 1) } },
|
||||||
ctrl(:w) => proc {
|
ctrl(:w) => proc {
|
||||||
pcursor = cursor
|
pcursor = cursor
|
||||||
backword.call
|
backword.call
|
||||||
@ -1021,7 +1029,7 @@ class FZF
|
|||||||
when :stab then 1
|
when :stab then 1
|
||||||
when :sclick then 0
|
when :sclick then 0
|
||||||
else -1
|
else -1
|
||||||
end }
|
end * (@reverse ? -1 : 1) }
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil },
|
ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil },
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.name = 'fzf'
|
spec.name = 'fzf'
|
||||||
spec.version = '0.8.3'
|
spec.version = '0.8.4'
|
||||||
spec.authors = ['Junegunn Choi']
|
spec.authors = ['Junegunn Choi']
|
||||||
spec.email = ['junegunn.c@gmail.com']
|
spec.email = ['junegunn.c@gmail.com']
|
||||||
spec.description = %q{Fuzzy finder for your shell}
|
spec.description = %q{Fuzzy finder for your shell}
|
||||||
|
@ -32,6 +32,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal false, fzf.exit0
|
assert_equal false, fzf.exit0
|
||||||
assert_equal nil, fzf.filter
|
assert_equal nil, fzf.filter
|
||||||
assert_equal nil, fzf.extended
|
assert_equal nil, fzf.extended
|
||||||
|
assert_equal false, fzf.reverse
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_environment_variables
|
def test_environment_variables
|
||||||
@ -43,7 +44,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
|
|
||||||
ENV['FZF_DEFAULT_OPTS'] =
|
ENV['FZF_DEFAULT_OPTS'] =
|
||||||
'-x -m -s 10000 -q " hello world " +c +2 --select-1 -0 ' +
|
'-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 []
|
fzf = FZF.new []
|
||||||
assert_equal 10000, fzf.sort
|
assert_equal 10000, fzf.sort
|
||||||
assert_equal ' hello world ',
|
assert_equal ' hello world ',
|
||||||
@ -58,6 +59,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal false, fzf.mouse
|
assert_equal false, fzf.mouse
|
||||||
assert_equal true, fzf.select1
|
assert_equal true, fzf.select1
|
||||||
assert_equal true, fzf.exit0
|
assert_equal true, fzf.exit0
|
||||||
|
assert_equal true, fzf.reverse
|
||||||
assert_equal [3, -1, 2], fzf.nth
|
assert_equal [3, -1, 2], fzf.nth
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -65,7 +67,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
# Long opts
|
# Long opts
|
||||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello --select-1
|
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello --select-1
|
||||||
--exit-0 --filter=howdy --extended-exact
|
--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 2000, fzf.sort
|
||||||
assert_equal true, fzf.multi
|
assert_equal true, fzf.multi
|
||||||
assert_equal false, fzf.color
|
assert_equal false, fzf.color
|
||||||
@ -79,12 +81,14 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal 'howdy', fzf.filter
|
assert_equal 'howdy', fzf.filter
|
||||||
assert_equal :exact, fzf.extended
|
assert_equal :exact, fzf.extended
|
||||||
assert_equal [1], fzf.nth
|
assert_equal [1], fzf.nth
|
||||||
|
assert_equal true, fzf.reverse
|
||||||
|
|
||||||
# Long opts (left-to-right)
|
# Long opts (left-to-right)
|
||||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query=hello
|
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query=hello
|
||||||
--filter a --filter b --no-256 --black --nth -1 --nth -2
|
--filter a --filter b --no-256 --black --nth -1 --nth -2
|
||||||
--select-1 --exit-0 --no-select-1 --no-exit-0
|
--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 nil, fzf.sort
|
||||||
assert_equal false, fzf.multi
|
assert_equal false, fzf.multi
|
||||||
assert_equal true, fzf.color
|
assert_equal true, fzf.color
|
||||||
@ -98,6 +102,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal false, fzf.exit0
|
assert_equal false, fzf.exit0
|
||||||
assert_equal nil, fzf.extended
|
assert_equal nil, fzf.extended
|
||||||
assert_equal [-2], fzf.nth
|
assert_equal [-2], fzf.nth
|
||||||
|
assert_equal false, fzf.reverse
|
||||||
|
|
||||||
# Short opts
|
# Short opts
|
||||||
fzf = FZF.new %w[-s2000 +c -m +i -qhello -x -fhowdy +2 -n3 -1 -0]
|
fzf = FZF.new %w[-s2000 +c -m +i -qhello -x -fhowdy +2 -n3 -1 -0]
|
||||||
|
Loading…
Reference in New Issue
Block a user