Add --no-color (+c) option

This commit is contained in:
Junegunn Choi 2013-11-03 11:45:14 +09:00
parent c326e363eb
commit 8e305edcf2
2 changed files with 44 additions and 25 deletions

View File

@ -73,6 +73,7 @@ usage: fzf [options]
-s, --sort=MAX Maximum number of matched items to sort. Default: 500 -s, --sort=MAX Maximum number of matched items to sort. Default: 500
+s, --no-sort Keep the sequence unchanged. +s, --no-sort Keep the sequence unchanged.
+i Case-sensitive match +i Case-sensitive match
+c, --no-color Disable colors
``` ```
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

30
fzf
View File

@ -40,7 +40,8 @@ def usage x
-s, --sort=MAX Maximum number of matched items to sort. Default: 500. -s, --sort=MAX Maximum number of matched items to sort. Default: 500.
+s, --no-sort Do not sort the result. Keep the sequence unchanged. +s, --no-sort Do not sort the result. Keep the sequence unchanged.
+i Case-sensitive match] +i Case-sensitive match
+c, --no-color Disable colors]
exit x exit x
end end
@ -50,6 +51,7 @@ $stdout.reopen($stderr)
usage 0 unless (%w[--help -h] & ARGV).empty? usage 0 unless (%w[--help -h] & ARGV).empty?
@rxflag = ARGV.delete('+i') ? 0 : Regexp::IGNORECASE @rxflag = ARGV.delete('+i') ? 0 : Regexp::IGNORECASE
@sort = (ARGV.delete('+s') || ARGV.delete('--no-sort')) ? nil : 500 @sort = (ARGV.delete('+s') || ARGV.delete('--no-sort')) ? nil : 500
@color = (ARGV.delete('+c') || ARGV.delete('--no-color')).nil?
rest = ARGV.join ' ' rest = ARGV.join ' '
if sort = rest.match(/(-s|--sort=?) ?([0-9]+)/) if sort = rest.match(/(-s|--sort=?) ?([0-9]+)/)
usage 1 unless @sort usage 1 unless @sort
@ -132,7 +134,7 @@ when /darwin/
ret << c ret << c
end end
end end
return [ret, omap[b] || 0, omap[e] || (omap.last || 0 + 1)] return [ret, omap[b] || 0, omap[e] || ((omap.last || 0) + 1)]
end end
end end
@ -260,7 +262,9 @@ dbg =
end end
C.raw C.raw
C.noecho C.noecho
if C.can_change_color?
if @color
if C.can_change_color?
fg = ENV.fetch('FZF_FG', 252).to_i fg = ENV.fetch('FZF_FG', 252).to_i
bg = ENV.fetch('FZF_BG', 236).to_i bg = ENV.fetch('FZF_BG', 236).to_i
C.init_pair 1, 110, dbg C.init_pair 1, 110, dbg
@ -270,7 +274,7 @@ if C.can_change_color?
C.init_pair 5, 148, dbg C.init_pair 5, 148, dbg
C.init_pair 6, 144, dbg C.init_pair 6, 144, dbg
C.init_pair 7, 161, bg C.init_pair 7, 161, bg
else else
C.init_pair 1, C::COLOR_BLUE, dbg C.init_pair 1, C::COLOR_BLUE, dbg
C.init_pair 2, C::COLOR_GREEN, dbg C.init_pair 2, C::COLOR_GREEN, dbg
C.init_pair 3, C::COLOR_YELLOW, C::COLOR_BLACK C.init_pair 3, C::COLOR_YELLOW, C::COLOR_BLACK
@ -278,12 +282,26 @@ else
C.init_pair 5, C::COLOR_GREEN, dbg C.init_pair 5, C::COLOR_GREEN, dbg
C.init_pair 6, C::COLOR_WHITE, dbg C.init_pair 6, C::COLOR_WHITE, dbg
C.init_pair 7, C::COLOR_RED, C::COLOR_BLACK C.init_pair 7, C::COLOR_RED, C::COLOR_BLACK
end end
def color sym, bold = false def color sym, bold = false
C.color_pair([:blue, :match, :chosen, C.color_pair([:blue, :match, :chosen,
:match!, :fan, :info, :red].index(sym) + 1) | :match!, :fan, :info, :red].index(sym) + 1) |
(bold ? C::A_BOLD : 0) (bold ? C::A_BOLD : 0)
end
else
def color sym, bold = false
case sym
when :chosen
bold ? C::A_REVERSE : 0
when :match
C::A_UNDERLINE
when :match!
C::A_REVERSE | C::A_UNDERLINE
else
0
end | (bold ? C::A_BOLD : 0)
end
end end
@read = @read =