mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2025-01-09 17:53:56 +00:00
Add option to disable 256-color output (related #18)
This commit is contained in:
parent
bbf4567dd8
commit
457a240457
@ -58,6 +58,7 @@ usage: fzf [options]
|
||||
-i Case-insensitive match (default: smart-case match)
|
||||
+i Case-sensitive match
|
||||
+c, --no-color Disable colors
|
||||
+2, --no-256 Disable 256-color
|
||||
--no-mouse Disable mouse
|
||||
|
||||
Environment variables
|
||||
|
9
fzf
9
fzf
@ -50,7 +50,7 @@ end
|
||||
|
||||
class FZF
|
||||
C = Curses
|
||||
attr_reader :rxflag, :sort, :color, :mouse, :multi, :query, :filter, :extended
|
||||
attr_reader :rxflag, :sort, :color, :ansi256, :mouse, :multi, :query, :filter, :extended
|
||||
|
||||
class AtomicVar
|
||||
def initialize value
|
||||
@ -77,6 +77,7 @@ class FZF
|
||||
@rxflag = nil
|
||||
@sort = ENV.fetch('FZF_DEFAULT_SORT', 1000).to_i
|
||||
@color = true
|
||||
@ansi256 = true
|
||||
@multi = false
|
||||
@mouse = true
|
||||
@extended = nil
|
||||
@ -101,6 +102,9 @@ class FZF
|
||||
when '+i' then @rxflag = 0
|
||||
when '-c', '--color' then @color = true
|
||||
when '+c', '--no-color' then @color = false
|
||||
when '-2', '--256' then @ansi256 = true
|
||||
when '+2', '--no-256' then @ansi256 = false
|
||||
when '--mouse' then @mouse = true
|
||||
when '--no-mouse' then @mouse = false
|
||||
when '+s', '--no-sort' then @sort = nil
|
||||
when '-q', '--query'
|
||||
@ -206,6 +210,7 @@ class FZF
|
||||
-i Case-insensitive match (default: smart-case match)
|
||||
+i Case-sensitive match
|
||||
+c, --no-color Disable colors
|
||||
+2, --no-256 Disable 256-color
|
||||
--no-mouse Disable mouse
|
||||
|
||||
Environment variables
|
||||
@ -522,7 +527,7 @@ class FZF
|
||||
C.noecho
|
||||
|
||||
if @color
|
||||
if ENV['TERM'].to_s =~ /256/
|
||||
if @ansi256 && ENV['TERM'].to_s =~ /256/
|
||||
C.init_pair 1, 110, dbg
|
||||
C.init_pair 2, 108, dbg
|
||||
C.init_pair 3, 254, 236
|
||||
|
@ -28,7 +28,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
||||
fzf = FZF.new []
|
||||
assert_equal 20000, fzf.sort
|
||||
|
||||
ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c --no-mouse -f "goodbye world"'
|
||||
ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c +2 --no-mouse -f "goodbye world"'
|
||||
fzf = FZF.new []
|
||||
assert_equal 10000, fzf.sort
|
||||
assert_equal ' hello world ',
|
||||
@ -38,16 +38,18 @@ class TestFZF < MiniTest::Unit::TestCase
|
||||
assert_equal :fuzzy, fzf.extended
|
||||
assert_equal true, fzf.multi
|
||||
assert_equal false, fzf.color
|
||||
assert_equal false, fzf.ansi256
|
||||
assert_equal false, fzf.mouse
|
||||
end
|
||||
|
||||
def test_option_parser
|
||||
# Long opts
|
||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello
|
||||
--filter=howdy --extended-exact --no-mouse]
|
||||
--filter=howdy --extended-exact --no-mouse --no-256]
|
||||
assert_equal 2000, fzf.sort
|
||||
assert_equal true, fzf.multi
|
||||
assert_equal false, fzf.color
|
||||
assert_equal false, fzf.ansi256
|
||||
assert_equal false, fzf.mouse
|
||||
assert_equal 0, fzf.rxflag
|
||||
assert_equal 'hello', fzf.query.get
|
||||
@ -55,11 +57,12 @@ class TestFZF < MiniTest::Unit::TestCase
|
||||
assert_equal :exact, fzf.extended
|
||||
|
||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello
|
||||
--filter a --filter b
|
||||
--no-sort -i --color --no-multi]
|
||||
--filter a --filter b --no-256
|
||||
--no-sort -i --color --no-multi --256]
|
||||
assert_equal nil, fzf.sort
|
||||
assert_equal false, fzf.multi
|
||||
assert_equal true, fzf.color
|
||||
assert_equal true, fzf.ansi256
|
||||
assert_equal true, fzf.mouse
|
||||
assert_equal 1, fzf.rxflag
|
||||
assert_equal 'b', fzf.filter
|
||||
@ -67,21 +70,23 @@ class TestFZF < MiniTest::Unit::TestCase
|
||||
assert_equal nil, fzf.extended
|
||||
|
||||
# Short opts
|
||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fhowdy]
|
||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fhowdy +2]
|
||||
assert_equal 2000, fzf.sort
|
||||
assert_equal true, fzf.multi
|
||||
assert_equal false, fzf.color
|
||||
assert_equal false, fzf.ansi256
|
||||
assert_equal 0, fzf.rxflag
|
||||
assert_equal 'hello', fzf.query.get
|
||||
assert_equal 'howdy', fzf.filter
|
||||
assert_equal :fuzzy, fzf.extended
|
||||
|
||||
# Left-to-right
|
||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fgoodbye
|
||||
-s 3000 -c +m -i -q world +x -fworld]
|
||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fgoodbye +2
|
||||
-s 3000 -c +m -i -q world +x -fworld -2]
|
||||
assert_equal 3000, fzf.sort
|
||||
assert_equal false, fzf.multi
|
||||
assert_equal true, fzf.color
|
||||
assert_equal true, fzf.ansi256
|
||||
assert_equal 1, fzf.rxflag
|
||||
assert_equal 'world', fzf.query.get
|
||||
assert_equal 'world', fzf.filter
|
||||
|
Loading…
Reference in New Issue
Block a user