Add --no-mouse option to replace FZF_MOUSE_ENABLED

This commit is contained in:
Junegunn Choi 2014-01-30 15:41:44 +09:00
parent f2b2c022be
commit c7e86ad4f1
3 changed files with 14 additions and 8 deletions

View File

@ -60,11 +60,11 @@ usage: fzf [options]
-i Case-insensitive match (default: smart-case match) -i Case-insensitive match (default: smart-case match)
+i Case-sensitive match +i Case-sensitive match
+c, --no-color Disable colors +c, --no-color Disable colors
--no-mouse Disable mouse
Environment variables Environment variables
FZF_DEFAULT_COMMAND Default command to use when input is tty FZF_DEFAULT_COMMAND Default command to use when input is tty
FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000") FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")
FZF_MOUSE_ENABLED Set to 0 to disable mouse
``` ```
fzf will launch curses-based finder, read the list from STDIN, and write the fzf will launch curses-based finder, read the list from STDIN, and write the

12
fzf
View File

@ -7,7 +7,7 @@
# / __/ / /_/ __/ # / __/ / /_/ __/
# /_/ /___/_/ Fuzzy finder for your shell # /_/ /___/_/ Fuzzy finder for your shell
# #
# Version: 0.7.0-devel (January 30, 2014) # Version: 0.7.0 (January 30, 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, :color, :multi, :query, :extended attr_reader :rxflag, :sort, :color, :mouse, :multi, :query, :extended
class AtomicVar class AtomicVar
def initialize value def initialize value
@ -81,6 +81,7 @@ class FZF
@color = true @color = true
@multi = false @multi = false
@extended = false @extended = false
@mouse = true
argv = argv =
if opts = ENV['FZF_DEFAULT_OPTS'] if opts = ENV['FZF_DEFAULT_OPTS']
@ -101,6 +102,7 @@ class FZF
when '+i' then @rxflag = 0 when '+i' then @rxflag = 0
when '-c', '--color' then @color = true when '-c', '--color' then @color = true
when '+c', '--no-color' then @color = false when '+c', '--no-color' then @color = false
when '--no-mouse' then @mouse = false
when '+s', '--no-sort' then @sort = nil when '+s', '--no-sort' then @sort = nil
when '-q', '--query' when '-q', '--query'
usage 1, 'query string required' unless query = argv.shift usage 1, 'query string required' unless query = argv.shift
@ -171,11 +173,11 @@ class FZF
-i Case-insensitive match (default: smart-case match) -i Case-insensitive match (default: smart-case match)
+i Case-sensitive match +i Case-sensitive match
+c, --no-color Disable colors +c, --no-color Disable colors
--no-mouse Disable mouse
Environment variables Environment variables
FZF_DEFAULT_COMMAND Default command to use when input is tty FZF_DEFAULT_COMMAND Default command to use when input is tty
FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000") FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")] + $/ + $/
FZF_MOUSE_ENABLED Set to 0 to disable mouse] + $/ + $/
exit x exit x
end end
@ -472,7 +474,7 @@ class FZF
def init_screen def init_screen
C.init_screen C.init_screen
unless ENV.fetch('FZF_MOUSE_ENABLED', '1') == '0' if @mouse
C.mouseinterval 0 C.mouseinterval 0
C.mousemask C::ALL_MOUSE_EVENTS C.mousemask C::ALL_MOUSE_EVENTS
end end

View File

@ -20,6 +20,7 @@ class TestFZF < MiniTest::Unit::TestCase
assert_equal false, fzf.multi assert_equal false, fzf.multi
assert_equal true, fzf.color assert_equal true, fzf.color
assert_equal nil, fzf.rxflag assert_equal nil, fzf.rxflag
assert_equal true, fzf.mouse
end end
def test_environment_variables def test_environment_variables
@ -28,7 +29,7 @@ class TestFZF < MiniTest::Unit::TestCase
fzf = FZF.new [] fzf = FZF.new []
assert_equal 20000, fzf.sort assert_equal 20000, fzf.sort
ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c' ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c --no-mouse'
fzf = FZF.new [] fzf = FZF.new []
assert_equal 10000, fzf.sort assert_equal 10000, fzf.sort
assert_equal ' hello world ', assert_equal ' hello world ',
@ -36,14 +37,16 @@ class TestFZF < MiniTest::Unit::TestCase
assert_equal true, fzf.extended assert_equal true, fzf.extended
assert_equal true, fzf.multi assert_equal true, fzf.multi
assert_equal false, fzf.color assert_equal false, fzf.color
assert_equal false, fzf.mouse
end end
def test_option_parser def test_option_parser
# Long opts # Long opts
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello --extended] fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello --extended --no-mouse]
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
assert_equal false, fzf.mouse
assert_equal 0, fzf.rxflag assert_equal 0, fzf.rxflag
assert_equal 'hello', fzf.query.get assert_equal 'hello', fzf.query.get
assert_equal true, fzf.extended assert_equal true, fzf.extended
@ -53,6 +56,7 @@ class TestFZF < MiniTest::Unit::TestCase
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
assert_equal true, fzf.mouse
assert_equal 1, fzf.rxflag assert_equal 1, fzf.rxflag
assert_equal 'hello', fzf.query.get assert_equal 'hello', fzf.query.get
assert_equal false, fzf.extended assert_equal false, fzf.extended