Skip to content
Myr

Add option to disable 256-color output (related #18)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parent bbf4567 · Browse files · 3 files+20 added−9 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+20 added−9 removed

  • tests:+12 added−7 removed
  • other:+8 added−2 removed

3 files+20 added−9 removed

modified:test/test_fzf.rb+12 added-7 removed
26 unmodified lines
27 ENV['FZF_DEFAULT_SORT'] = '20000'28 fzf = FZF.new []29 assert_equal 20000, fzf.sort3031 ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c --no-mouse -f "goodbye world"'31 ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c +2 --no-mouse -f "goodbye world"'32 fzf = FZF.new []33 assert_equal 10000, fzf.sort34 assert_equal ' hello world ',35 fzf.query.get
1 unmodified line
37 fzf.filter38 assert_equal :fuzzy, fzf.extended39 assert_equal true, fzf.multi40 assert_equal false, fzf.color41 assert_equal false, fzf.ansi25642 assert_equal false, fzf.mouse43 end4445 def test_option_parser46 # Long opts47 fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello47 --filter=howdy --extended-exact --no-mouse]48 --filter=howdy --extended-exact --no-mouse --no-256]49 assert_equal 2000, fzf.sort50 assert_equal true, fzf.multi51 assert_equal false, fzf.color52 assert_equal false, fzf.ansi25653 assert_equal false, fzf.mouse54 assert_equal 0, fzf.rxflag55 assert_equal 'hello', fzf.query.get56 assert_equal 'howdy', fzf.filter57 assert_equal :exact, fzf.extended5859 fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello58 --filter a --filter b59 --no-sort -i --color --no-multi]60 --filter a --filter b --no-25661 --no-sort -i --color --no-multi --256]62 assert_equal nil, fzf.sort63 assert_equal false, fzf.multi64 assert_equal true, fzf.color65 assert_equal true, fzf.ansi25666 assert_equal true, fzf.mouse67 assert_equal 1, fzf.rxflag68 assert_equal 'b', fzf.filter69 assert_equal 'hello', fzf.query.get70 assert_equal nil, fzf.extended7172 # Short opts70 fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fhowdy]73 fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fhowdy +2]74 assert_equal 2000, fzf.sort75 assert_equal true, fzf.multi76 assert_equal false, fzf.color77 assert_equal false, fzf.ansi25678 assert_equal 0, fzf.rxflag79 assert_equal 'hello', fzf.query.get80 assert_equal 'howdy', fzf.filter81 assert_equal :fuzzy, fzf.extended8283 # Left-to-right80 fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fgoodbye81 -s 3000 -c +m -i -q world +x -fworld]84 fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fgoodbye +285 -s 3000 -c +m -i -q world +x -fworld -2]86 assert_equal 3000, fzf.sort87 assert_equal false, fzf.multi88 assert_equal true, fzf.color89 assert_equal true, fzf.ansi25690 assert_equal 1, fzf.rxflag91 assert_equal 'world', fzf.query.get92 assert_equal 'world', fzf.filter93 assert_equal nil, fzf.extended
383 unmodified lines
modified:fzf+7 added-2 removed
48 unmodified lines
49end5051class FZF52 C = Curses53 attr_reader :rxflag, :sort, :color, :mouse, :multi, :query, :filter, :extended53 attr_reader :rxflag, :sort, :color, :ansi256, :mouse, :multi, :query, :filter, :extended5455 class AtomicVar56 def initialize value57 @value = value
18 unmodified lines
76 def initialize argv, source = $stdin77 @rxflag = nil78 @sort = ENV.fetch('FZF_DEFAULT_SORT', 1000).to_i79 @color = true80 @ansi256 = true81 @multi = false82 @mouse = true83 @extended = nil84 @filter = nil
16 unmodified lines
101 when '-i' then @rxflag = Regexp::IGNORECASE102 when '+i' then @rxflag = 0103 when '-c', '--color' then @color = true104 when '+c', '--no-color' then @color = false105 when '-2', '--256' then @ansi256 = true106 when '+2', '--no-256' then @ansi256 = false107 when '--mouse' then @mouse = true108 when '--no-mouse' then @mouse = false109 when '+s', '--no-sort' then @sort = nil110 when '-q', '--query'111 usage 1, 'query string required' unless query = argv.shift
97 unmodified lines
209 +s, --no-sort Do not sort the result. Keep the sequence unchanged.210 -i Case-insensitive match (default: smart-case match)211 +i Case-sensitive match212 +c, --no-color Disable colors213 +2, --no-256 Disable 256-color214 --no-mouse Disable mouse215216 Environment variables217 FZF_DEFAULT_COMMAND Default command to use when input is tty
308 unmodified lines
526 C.raw527 C.noecho528529 if @color525 if ENV['TERM'].to_s =~ /256/530 if @ansi256 && ENV['TERM'].to_s =~ /256/531 C.init_pair 1, 110, dbg532 C.init_pair 2, 108, dbg533 C.init_pair 3, 254, 236534 C.init_pair 4, 151, 236
582 unmodified lines
modified:README.md+1 added
56 unmodified lines
57 +s, --no-sort Do not sort the result. Keep the sequence unchanged.58 -i Case-insensitive match (default: smart-case match)59 +i Case-sensitive match60 +c, --no-color Disable colors61 +2, --no-256 Disable 256-color62 --no-mouse Disable mouse6364 Environment variables65 FZF_DEFAULT_COMMAND Default command to use when input is tty
280 unmodified lines