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
Provenance
- Commit
457a240- Tree
7c310f6- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
bbf4567
3 files changed+20 added−9 removed
modified:test/test_fzf.rb+12 added-7 removed
26 unmodified lines27 ENV['FZF_DEFAULT_SORT'] = '20000'28 fzf = FZF.new []29 assert_equal 20000, fzf.sort30 31- 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.get1 unmodified line37 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 end44 45 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.extended58 59 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.extended71 72 # 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.extended82 83 # 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.extended383 unmodified linesmodified:fzf+7 added-2 removed
48 unmodified lines49 end50 51 class FZF52 C = Curses53- attr_reader :rxflag, :sort, :color, :mouse, :multi, :query, :filter, :extended53+ attr_reader :rxflag, :sort, :color, :ansi256, :mouse, :multi, :query, :filter, :extended54 55 class AtomicVar56 def initialize value57 @value = value18 unmodified lines76 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 = nil16 unmodified lines101 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.shift97 unmodified lines209 +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 mouse215 216 Environment variables217 FZF_DEFAULT_COMMAND Default command to use when input is tty308 unmodified lines526 C.raw527 C.noecho528 529 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, 236582 unmodified linesmodified:README.md+1 added
56 unmodified lines57 +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 mouse63 64 Environment variables65 FZF_DEFAULT_COMMAND Default command to use when input is tty280 unmodified lines