mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-02 21:22:01 -07:00
Compare commits
36 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
ae84d8c7a4 | ||
|
dbd627c38a | ||
|
d172c3ce03 | ||
|
9904f5354e | ||
|
f345bf7983 | ||
|
875f9b6534 | ||
|
871dfb709d | ||
|
19e24bd644 | ||
|
457a240457 | ||
|
bbf4567dd8 | ||
|
27d3b52843 | ||
|
dcb4694ec1 | ||
|
2fb8ae010f | ||
|
65ae6cabb5 | ||
|
86a66da04d | ||
|
d66b02b0cd | ||
|
b3182c3304 | ||
|
2dbca00bfb | ||
|
b22fd6de6d | ||
|
245ee42763 | ||
|
98bef4600c | ||
|
f5d53b94fe | ||
|
00c8a68430 | ||
|
c1be834ff9 | ||
|
2c0dc2f3b1 | ||
|
1c94fef720 | ||
|
b711d76b8e | ||
|
4396ab7548 | ||
|
2b8c2b9f2a | ||
|
426284c87e | ||
|
089691faaf | ||
|
301290663d | ||
|
1155da7e1c | ||
|
eca0a99fb4 | ||
|
96215c4619 | ||
|
b2d2be55ef |
66
README.md
66
README.md
@@ -32,18 +32,14 @@ The script will setup:
|
|||||||
|
|
||||||
### Install as Vim plugin
|
### Install as Vim plugin
|
||||||
|
|
||||||
You can use any Vim plugin manager to install fzf for Vim. If you don't use one,
|
Once you have cloned the repository, add the following line to your .vimrc.
|
||||||
I recommend you try [vim-plug](https://github.com/junegunn/vim-plug).
|
|
||||||
|
|
||||||
1. [Install vim-plug](https://github.com/junegunn/vim-plug#usage)
|
```vim
|
||||||
2. Edit your .vimrc
|
set rtp+=~/.fzf
|
||||||
|
```
|
||||||
|
|
||||||
call plug#begin()
|
Or you may use any Vim plugin manager, such as
|
||||||
Plug 'junegunn/fzf'
|
[vim-plug](https://github.com/junegunn/vim-plug).
|
||||||
" ...
|
|
||||||
call plug#end()
|
|
||||||
|
|
||||||
3. Run `:PlugInstall`
|
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
@@ -54,12 +50,16 @@ usage: fzf [options]
|
|||||||
Options
|
Options
|
||||||
-m, --multi Enable multi-select
|
-m, --multi Enable multi-select
|
||||||
-x, --extended Extended-search mode
|
-x, --extended Extended-search mode
|
||||||
|
-e, --extended-exact Extended-search mode (exact match)
|
||||||
-q, --query=STR Initial query
|
-q, --query=STR Initial query
|
||||||
|
-f, --filter=STR Filter mode. Do not start interactive finder.
|
||||||
-s, --sort=MAX Maximum number of matched items to sort (default: 1000)
|
-s, --sort=MAX Maximum number of matched items to sort (default: 1000)
|
||||||
+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-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
|
||||||
|
+2, --no-256 Disable 256-color
|
||||||
|
--black Use black background
|
||||||
--no-mouse Disable mouse
|
--no-mouse Disable mouse
|
||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
@@ -104,8 +104,9 @@ The following readline key bindings should also work as expected.
|
|||||||
If you enable multi-select mode with `-m` option, you can select multiple items
|
If you enable multi-select mode with `-m` option, you can select multiple items
|
||||||
with TAB or Shift-TAB key.
|
with TAB or Shift-TAB key.
|
||||||
|
|
||||||
You can also use mouse. Click on an item to select it or shift-click to select
|
You can also use mouse. Double-click on an item to select it or shift-click (or
|
||||||
multiple items. Use mouse wheel to move the cursor up and down.
|
ctrl-click) to select multiple items. Use mouse wheel to move the cursor up and
|
||||||
|
down.
|
||||||
|
|
||||||
### Extended-search mode
|
### Extended-search mode
|
||||||
|
|
||||||
@@ -123,6 +124,9 @@ such as: `^music .mp3$ sbtrkt !rmx`
|
|||||||
| `'wild` | Items that include `wild` | exact-match (quoted) |
|
| `'wild` | Items that include `wild` | exact-match (quoted) |
|
||||||
| `!'fire` | Items that do not include `fire` | inverse-exact-match |
|
| `!'fire` | Items that do not include `fire` | inverse-exact-match |
|
||||||
|
|
||||||
|
If you don't need fuzzy matching and do not wish to "quote" every word, start
|
||||||
|
fzf with `-e` or `--extended-exact` option.
|
||||||
|
|
||||||
Useful examples
|
Useful examples
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
@@ -287,34 +291,20 @@ a very large list of files, fzf is significantly faster and it does not block.
|
|||||||
Tips
|
Tips
|
||||||
----
|
----
|
||||||
|
|
||||||
### Faster startup with `--disable-gems` options
|
### Rendering issues
|
||||||
|
|
||||||
If you're running Ruby 1.9 or above, you can improve the startup time with
|
If you have any rendering issues, check the followings:
|
||||||
`--disable-gems` option to Ruby.
|
|
||||||
|
|
||||||
- `time ruby ~/bin/fzf -h`
|
1. Make sure `$TERM` is correctly set. fzf will use 256-color only if it
|
||||||
- 0.077 sec
|
contains `256` (e.g. `xterm-256color`)
|
||||||
- `time ruby --disable-gems ~/bin/fzf -h`
|
2. If you're on screen or tmux, `$TERM` should be either `screen` or
|
||||||
- 0.025 sec
|
`screen-256color`
|
||||||
|
3. Some terminal emulators (e.g. mintty) have problem displaying default
|
||||||
You can define fzf function with the option as follows:
|
background color and make some text unable to read. In that case, try `--black`
|
||||||
|
option. And if it solves your problem, I recommend including it in
|
||||||
```sh
|
`FZF_DEFAULT_OPTS` for further convenience.
|
||||||
fzf() {
|
4. If you still have problem, try `--no-256` option or even `--no-color`.
|
||||||
ruby --disable-gems ~/bin/fzf "$@"
|
5. Ruby 1.9 or above is required for correctly displaying unicode characters.
|
||||||
}
|
|
||||||
export -f fzf
|
|
||||||
```
|
|
||||||
|
|
||||||
However, this is automatically set up in your .bashrc and .zshrc if you use the
|
|
||||||
bundled [install](https://github.com/junegunn/fzf/blob/master/install) script.
|
|
||||||
|
|
||||||
### Incorrect display on Ruby 1.8
|
|
||||||
|
|
||||||
It is reported that the output of fzf can become unreadable on some terminals
|
|
||||||
when it's running on Ruby 1.8. If you experience the problem, upgrade your Ruby
|
|
||||||
to 1.9 or above. Ruby 1.9 or above is also required for displaying Unicode
|
|
||||||
characters.
|
|
||||||
|
|
||||||
### Ranking algorithm
|
### Ranking algorithm
|
||||||
|
|
||||||
|
413
fzf
413
fzf
@@ -7,13 +7,13 @@
|
|||||||
# / __/ / /_/ __/
|
# / __/ / /_/ __/
|
||||||
# /_/ /___/_/ Fuzzy finder for your shell
|
# /_/ /___/_/ Fuzzy finder for your shell
|
||||||
#
|
#
|
||||||
# Version: 0.7.0 (January 30, 2014)
|
# Version: 0.8.1 (March 9, 2014)
|
||||||
#
|
#
|
||||||
# Author: Junegunn Choi
|
# Author: Junegunn Choi
|
||||||
# URL: https://github.com/junegunn/fzf
|
# URL: https://github.com/junegunn/fzf
|
||||||
# License: MIT
|
# License: MIT
|
||||||
#
|
#
|
||||||
# Copyright (c) 2013 Junegunn Choi
|
# Copyright (c) 2014 Junegunn Choi
|
||||||
#
|
#
|
||||||
# MIT License
|
# MIT License
|
||||||
#
|
#
|
||||||
@@ -50,7 +50,7 @@ end
|
|||||||
|
|
||||||
class FZF
|
class FZF
|
||||||
C = Curses
|
C = Curses
|
||||||
attr_reader :rxflag, :sort, :color, :mouse, :multi, :query, :extended
|
attr_reader :rxflag, :sort, :color, :black, :ansi256, :mouse, :multi, :query, :filter, :extended
|
||||||
|
|
||||||
class AtomicVar
|
class AtomicVar
|
||||||
def initialize value
|
def initialize value
|
||||||
@@ -63,10 +63,8 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
def set value = nil
|
def set value = nil
|
||||||
if block_given?
|
@mutex.synchronize do
|
||||||
@mutex.synchronize { @value = yield @value }
|
@value = block_given? ? yield(@value) : value
|
||||||
else
|
|
||||||
@mutex.synchronize { @value = value }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -79,9 +77,12 @@ class FZF
|
|||||||
@rxflag = nil
|
@rxflag = nil
|
||||||
@sort = ENV.fetch('FZF_DEFAULT_SORT', 1000).to_i
|
@sort = ENV.fetch('FZF_DEFAULT_SORT', 1000).to_i
|
||||||
@color = true
|
@color = true
|
||||||
|
@ansi256 = true
|
||||||
|
@black = false
|
||||||
@multi = false
|
@multi = false
|
||||||
@extended = false
|
|
||||||
@mouse = true
|
@mouse = true
|
||||||
|
@extended = nil
|
||||||
|
@filter = nil
|
||||||
|
|
||||||
argv =
|
argv =
|
||||||
if opts = ENV['FZF_DEFAULT_OPTS']
|
if opts = ENV['FZF_DEFAULT_OPTS']
|
||||||
@@ -96,12 +97,17 @@ class FZF
|
|||||||
when '-h', '--help' then usage 0
|
when '-h', '--help' then usage 0
|
||||||
when '-m', '--multi' then @multi = true
|
when '-m', '--multi' then @multi = true
|
||||||
when '+m', '--no-multi' then @multi = false
|
when '+m', '--no-multi' then @multi = false
|
||||||
when '-x', '--extended' then @extended = true
|
when '-x', '--extended' then @extended = :fuzzy
|
||||||
when '+x', '--no-extended' then @extended = false
|
when '+x', '--no-extended' then @extended = nil
|
||||||
when '-i' then @rxflag = Regexp::IGNORECASE
|
when '-i' then @rxflag = Regexp::IGNORECASE
|
||||||
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 '-2', '--256' then @ansi256 = true
|
||||||
|
when '+2', '--no-256' then @ansi256 = false
|
||||||
|
when '--black' then @black = true
|
||||||
|
when '--no-black' then @black = false
|
||||||
|
when '--mouse' then @mouse = true
|
||||||
when '--no-mouse' then @mouse = 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'
|
||||||
@@ -109,12 +115,19 @@ class FZF
|
|||||||
@query = AtomicVar.new query.dup
|
@query = AtomicVar.new query.dup
|
||||||
when /^-q(.*)$/, /^--query=(.*)$/
|
when /^-q(.*)$/, /^--query=(.*)$/
|
||||||
@query = AtomicVar.new($1)
|
@query = AtomicVar.new($1)
|
||||||
|
when '-f', '--filter'
|
||||||
|
usage 1, 'query string required' unless query = argv.shift
|
||||||
|
@filter = query
|
||||||
|
when /^-f(.*)$/, /^--filter=(.*)$/
|
||||||
|
@filter = $1
|
||||||
when '-s', '--sort'
|
when '-s', '--sort'
|
||||||
usage 1, 'sort size required' unless sort = argv.shift
|
usage 1, 'sort size required' unless sort = argv.shift
|
||||||
usage 1, 'invalid sort size' unless sort =~ /^[0-9]+$/
|
usage 1, 'invalid sort size' unless sort =~ /^[0-9]+$/
|
||||||
@sort = sort.to_i
|
@sort = sort.to_i
|
||||||
when /^-s([0-9]+)$/, /^--sort=([0-9]+)$/
|
when /^-s([0-9]+)$/, /^--sort=([0-9]+)$/
|
||||||
@sort = $1.to_i
|
@sort = $1.to_i
|
||||||
|
when '-e', '--extended-exact' then @extended = :exact
|
||||||
|
when '+e', '--no-extended-exact' then @extended = nil
|
||||||
else
|
else
|
||||||
usage 1, "illegal option: #{o}"
|
usage 1, "illegal option: #{o}"
|
||||||
end
|
end
|
||||||
@@ -126,27 +139,52 @@ class FZF
|
|||||||
@events = {}
|
@events = {}
|
||||||
@new = []
|
@new = []
|
||||||
@queue = Queue.new
|
@queue = Queue.new
|
||||||
@query ||= AtomicVar.new('')
|
@pending = nil
|
||||||
@cursor_x = AtomicVar.new(@query.length)
|
|
||||||
@matches = AtomicVar.new([])
|
unless @filter
|
||||||
@count = AtomicVar.new(0)
|
@query ||= AtomicVar.new('')
|
||||||
@vcursor = AtomicVar.new(0)
|
@cursor_x = AtomicVar.new(@query.length)
|
||||||
@vcursors = AtomicVar.new(Set.new)
|
@matches = AtomicVar.new([])
|
||||||
@spinner = AtomicVar.new('-\|/-\|/'.split(//))
|
@count = AtomicVar.new(0)
|
||||||
@selects = AtomicVar.new({}) # ordered >= 1.9
|
@vcursor = AtomicVar.new(0)
|
||||||
@main = Thread.current
|
@vcursors = AtomicVar.new(Set.new)
|
||||||
@stdout = $stdout.clone
|
@spinner = AtomicVar.new('-\|/-\|/'.split(//))
|
||||||
@plcount = 0
|
@selects = AtomicVar.new({}) # ordered >= 1.9
|
||||||
|
@main = Thread.current
|
||||||
|
@plcount = 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def start
|
def start
|
||||||
$stdout.reopen($stderr)
|
if @filter
|
||||||
|
start_reader(false).join
|
||||||
|
filter_list @new
|
||||||
|
else
|
||||||
|
@stdout = $stdout.clone
|
||||||
|
$stdout.reopen($stderr)
|
||||||
|
|
||||||
init_screen
|
start_reader true
|
||||||
start_reader
|
init_screen
|
||||||
start_renderer
|
start_renderer
|
||||||
start_search
|
start_search
|
||||||
start_loop
|
start_loop
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def filter_list list
|
||||||
|
matches = get_matcher.match(list, @filter, '', '')
|
||||||
|
if @sort && matches.length <= @sort
|
||||||
|
matches = sort_by_rank(matches)
|
||||||
|
end
|
||||||
|
matches.each { |m| puts m.first }
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_matcher
|
||||||
|
if @extended
|
||||||
|
ExtendedFuzzyMatcher.new @rxflag, @extended
|
||||||
|
else
|
||||||
|
FuzzyMatcher.new @rxflag
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def version
|
def version
|
||||||
@@ -167,12 +205,16 @@ class FZF
|
|||||||
Options
|
Options
|
||||||
-m, --multi Enable multi-select
|
-m, --multi Enable multi-select
|
||||||
-x, --extended Extended-search mode
|
-x, --extended Extended-search mode
|
||||||
|
-e, --extended-exact Extended-search mode (exact match)
|
||||||
-q, --query=STR Initial query
|
-q, --query=STR Initial query
|
||||||
|
-f, --filter=STR Filter mode. Do not start interactive finder.
|
||||||
-s, --sort=MAX Maximum number of matched items to sort (default: 1000)
|
-s, --sort=MAX Maximum number of matched items to sort (default: 1000)
|
||||||
+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-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
|
||||||
|
+2, --no-256 Disable 256-color
|
||||||
|
--black Use black background
|
||||||
--no-mouse Disable mouse
|
--no-mouse Disable mouse
|
||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
@@ -429,7 +471,9 @@ class FZF
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_VERSION.split('.').map { |e| e.rjust(3, '0') }.join > '001009'
|
AFTER_1_9 = RUBY_VERSION.split('.').map { |e| e.rjust(3, '0') }.join >= '001009'
|
||||||
|
|
||||||
|
if AFTER_1_9
|
||||||
@@wrx = Regexp.new '\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}'
|
@@wrx = Regexp.new '\p{Han}|\p{Katakana}|\p{Hiragana}|\p{Hangul}'
|
||||||
def width str
|
def width str
|
||||||
str.gsub(@@wrx, ' ').length rescue str.length
|
str.gsub(@@wrx, ' ').length rescue str.length
|
||||||
@@ -474,25 +518,20 @@ class FZF
|
|||||||
|
|
||||||
def init_screen
|
def init_screen
|
||||||
C.init_screen
|
C.init_screen
|
||||||
if @mouse
|
C.mousemask C::ALL_MOUSE_EVENTS if @mouse
|
||||||
C.mouseinterval 0
|
|
||||||
C.mousemask C::ALL_MOUSE_EVENTS
|
|
||||||
end
|
|
||||||
C.stdscr.keypad(true)
|
|
||||||
C.start_color
|
C.start_color
|
||||||
dbg =
|
dbg =
|
||||||
if C.respond_to?(:use_default_colors)
|
if !@black && C.respond_to?(:use_default_colors)
|
||||||
C.use_default_colors
|
C.use_default_colors
|
||||||
-1
|
-1
|
||||||
else
|
else
|
||||||
C::COLOR_BLACK
|
C::COLOR_BLACK
|
||||||
end
|
end
|
||||||
C.raw
|
C.raw
|
||||||
C.nonl
|
|
||||||
C.noecho
|
C.noecho
|
||||||
|
|
||||||
if @color
|
if @color
|
||||||
if C.can_change_color? && ENV['TERM'].to_s =~ /256/
|
if @ansi256 && ENV['TERM'].to_s =~ /256/
|
||||||
C.init_pair 1, 110, dbg
|
C.init_pair 1, 110, dbg
|
||||||
C.init_pair 2, 108, dbg
|
C.init_pair 2, 108, dbg
|
||||||
C.init_pair 3, 254, 236
|
C.init_pair 3, 254, 236
|
||||||
@@ -531,9 +570,11 @@ class FZF
|
|||||||
end | (bold ? C::A_BOLD : 0)
|
end | (bold ? C::A_BOLD : 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
C.refresh
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_reader
|
def start_reader curses
|
||||||
stream =
|
stream =
|
||||||
if @source.tty?
|
if @source.tty?
|
||||||
if default_command = ENV['FZF_DEFAULT_COMMAND']
|
if default_command = ENV['FZF_DEFAULT_COMMAND']
|
||||||
@@ -544,7 +585,6 @@ class FZF
|
|||||||
exit 1
|
exit 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
$stdin.reopen IO.open(IO.sysopen('/dev/tty'), 'r')
|
|
||||||
@source
|
@source
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -553,12 +593,12 @@ class FZF
|
|||||||
emit(:new) { @new << line.chomp }
|
emit(:new) { @new << line.chomp }
|
||||||
end
|
end
|
||||||
emit(:loaded) { true }
|
emit(:loaded) { true }
|
||||||
@spinner.clear
|
@spinner.clear if curses
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_search
|
def start_search
|
||||||
matcher = (@extended ? ExtendedFuzzyMatcher : FuzzyMatcher).new @rxflag
|
matcher = get_matcher
|
||||||
searcher = Thread.new {
|
searcher = Thread.new {
|
||||||
lists = []
|
lists = []
|
||||||
events = {}
|
events = {}
|
||||||
@@ -618,11 +658,11 @@ class FZF
|
|||||||
matcher.match(list, q, q[0, cx], q[cx..-1]))
|
matcher.match(list, q, q[0, cx], q[cx..-1]))
|
||||||
end
|
end
|
||||||
next if skip
|
next if skip
|
||||||
matches = fcache[q] = @sort ? found : found.reverse
|
matches = @sort ? found : found.reverse
|
||||||
end
|
if !empty && @sort && matches.length <= @sort
|
||||||
|
matches = sort_by_rank(matches)
|
||||||
if !empty && @sort && matches.length <= @sort
|
end
|
||||||
matches = sort_by_rank(matches)
|
fcache[q] = matches
|
||||||
end
|
end
|
||||||
|
|
||||||
# Atomic update
|
# Atomic update
|
||||||
@@ -683,7 +723,6 @@ class FZF
|
|||||||
def start_renderer
|
def start_renderer
|
||||||
Thread.new do
|
Thread.new do
|
||||||
begin
|
begin
|
||||||
refresh
|
|
||||||
while blk = @queue.shift
|
while blk = @queue.shift
|
||||||
blk.call
|
blk.call
|
||||||
refresh
|
refresh
|
||||||
@@ -718,8 +757,148 @@ class FZF
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_mouse st, *states
|
def read_nb chars = 1, default = nil, tries = 10
|
||||||
states.any? { |s| s & st > 0 }
|
tries.times do |_|
|
||||||
|
begin
|
||||||
|
return @tty.read_nonblock(chars).ord
|
||||||
|
rescue Exception
|
||||||
|
sleep 0.01
|
||||||
|
end
|
||||||
|
end
|
||||||
|
default
|
||||||
|
end
|
||||||
|
|
||||||
|
def read_nbs
|
||||||
|
ords = []
|
||||||
|
while ord = read_nb
|
||||||
|
ords << ord
|
||||||
|
end
|
||||||
|
ords
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_mouse
|
||||||
|
case ord = read_nb
|
||||||
|
when 32, 36, 40, 48, # mouse-down / shift / cmd / ctrl
|
||||||
|
35, 39, 43, 51 # mouse-up / shift / cmd / ctrl
|
||||||
|
x = read_nb - 33
|
||||||
|
y = read_nb - 33
|
||||||
|
{ :event => (ord % 2 == 0 ? :click : :release),
|
||||||
|
:x => x, :y => y, :shift => ord >= 36 }
|
||||||
|
when 96, 100, 104, 112, # scroll-up / shift / cmd / ctrl
|
||||||
|
97, 101, 105, 113 # scroll-down / shift / cmd / ctrl
|
||||||
|
read_nb(2)
|
||||||
|
{ :event => :scroll, :diff => (ord % 2 == 0 ? -1 : 1), :shift => ord >= 100 }
|
||||||
|
else
|
||||||
|
# e.g. 40, 43, 104, 105
|
||||||
|
read_nb(2)
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_input actions
|
||||||
|
@tty ||= IO.open(IO.sysopen('/dev/tty'), 'r')
|
||||||
|
|
||||||
|
if pending = @pending
|
||||||
|
@pending = nil
|
||||||
|
return pending
|
||||||
|
end
|
||||||
|
|
||||||
|
str = ''
|
||||||
|
while true
|
||||||
|
ord =
|
||||||
|
if str.empty?
|
||||||
|
@tty.getc.ord
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
ord = @tty.read_nonblock(1).ord
|
||||||
|
if (nb = num_unicode_bytes(ord)) > 1
|
||||||
|
ords = [ord]
|
||||||
|
(nb - 1).times do |_|
|
||||||
|
ords << @tty.read_nonblock(1).ord
|
||||||
|
end
|
||||||
|
# UTF-8 TODO Ruby 1.8
|
||||||
|
ords.pack('C*').force_encoding('UTF-8')
|
||||||
|
else
|
||||||
|
ord
|
||||||
|
end
|
||||||
|
rescue Exception
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ord =
|
||||||
|
case read_nb(1, :esc)
|
||||||
|
when 91
|
||||||
|
case read_nb(1, nil)
|
||||||
|
when 68 then ctrl(:b)
|
||||||
|
when 67 then ctrl(:f)
|
||||||
|
when 66 then ctrl(:j)
|
||||||
|
when 65 then ctrl(:k)
|
||||||
|
when 90 then :stab
|
||||||
|
when 50 then read_nb; :ins
|
||||||
|
when 51 then read_nb; :del
|
||||||
|
when 53 then read_nb; :pgup
|
||||||
|
when 54 then read_nb; :pgdn
|
||||||
|
when 49
|
||||||
|
case read_nbs
|
||||||
|
when [59, 50, 68] then ctrl(:a)
|
||||||
|
when [59, 50, 67] then ctrl(:e)
|
||||||
|
when [126] then ctrl(:a)
|
||||||
|
end
|
||||||
|
when 52 then read_nb; ctrl(:e)
|
||||||
|
when 72 then ctrl(:a)
|
||||||
|
when 70 then ctrl(:e)
|
||||||
|
when 77
|
||||||
|
get_mouse
|
||||||
|
end
|
||||||
|
when 'b', 98 then :alt_b
|
||||||
|
when 'f', 102 then :alt_f
|
||||||
|
when :esc then :esc
|
||||||
|
else next
|
||||||
|
end if ord == 27
|
||||||
|
|
||||||
|
return ord if ord.nil? || ord.is_a?(Hash)
|
||||||
|
|
||||||
|
if actions.has_key?(ord)
|
||||||
|
if str.empty?
|
||||||
|
return ord
|
||||||
|
else
|
||||||
|
@pending = ord
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
else
|
||||||
|
unless ord.is_a? String
|
||||||
|
ord = [ord].pack('U*')
|
||||||
|
end
|
||||||
|
str << ord if ord =~ /[[:print:]]/
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
class MouseEvent
|
||||||
|
DOUBLE_CLICK_INTERVAL = 0.5
|
||||||
|
|
||||||
|
attr_reader :v
|
||||||
|
|
||||||
|
def initialize v = nil
|
||||||
|
@c = 0
|
||||||
|
@v = v
|
||||||
|
@t = Time.at 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def v= v
|
||||||
|
@c = (@v == v && within?) ? @c + 1 : 0
|
||||||
|
@v = v
|
||||||
|
@t = Time.now
|
||||||
|
end
|
||||||
|
|
||||||
|
def double? v
|
||||||
|
@c == 1 && @v == v && within?
|
||||||
|
end
|
||||||
|
|
||||||
|
def within?
|
||||||
|
(Time.now - @t) < DOUBLE_CLICK_INTERVAL
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def start_loop
|
def start_loop
|
||||||
@@ -755,103 +934,75 @@ class FZF
|
|||||||
else
|
else
|
||||||
@selects[sel] = 1
|
@selects[sel] = 1
|
||||||
end
|
end
|
||||||
vselect { |v|
|
vselect { |v| v + case o
|
||||||
v + case o
|
when :stab then 1
|
||||||
when :select then 0
|
when :sclick then 0
|
||||||
when C::KEY_BTAB then 1
|
else -1
|
||||||
else -1
|
end }
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil },
|
ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil },
|
||||||
ctrl(:f) => proc { cursor = [input.length, cursor + 1].min; nil },
|
ctrl(:f) => proc { cursor = [input.length, cursor + 1].min; nil },
|
||||||
|
ctrl(:l) => proc { render { C.clear; C.refresh }; update_list true },
|
||||||
|
:del => proc { input[cursor] = '' if input.length > cursor },
|
||||||
|
:pgup => proc { vselect { |_| max_items } },
|
||||||
|
:pgdn => proc { vselect { |_| 0 } },
|
||||||
:alt_b => proc { backword.call; nil },
|
:alt_b => proc { backword.call; nil },
|
||||||
:alt_f => proc {
|
:alt_f => proc {
|
||||||
cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1
|
cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1
|
||||||
nil
|
nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
actions[C::KEY_UP] = actions[ctrl(:p)] = actions[ctrl(:k)]
|
actions[ctrl(:p)] = actions[ctrl(:k)]
|
||||||
actions[C::KEY_DOWN] = actions[ctrl(:n)] = actions[ctrl(:j)]
|
actions[ctrl(:n)] = actions[ctrl(:j)]
|
||||||
actions[C::KEY_LEFT] = actions[ctrl(:b)]
|
actions[:stab] = actions[ctrl(:i)]
|
||||||
actions[C::KEY_RIGHT] = actions[ctrl(:f)]
|
actions[127] = actions[ctrl(:h)]
|
||||||
actions[C::KEY_BTAB] = actions[:select] = actions[ctrl(:i)]
|
|
||||||
actions[C::KEY_BACKSPACE] = actions[127] = actions[ctrl(:h)]
|
|
||||||
actions[ctrl(:q)] = actions[ctrl(:g)] = actions[ctrl(:c)] = actions[:esc]
|
actions[ctrl(:q)] = actions[ctrl(:g)] = actions[ctrl(:c)] = actions[:esc]
|
||||||
|
|
||||||
emit(:key) { [@query.get, cursor] } unless @query.empty?
|
emit(:key) { [@query.get, cursor] } unless @query.empty?
|
||||||
pmv = nil
|
mouse = MouseEvent.new
|
||||||
while true
|
while true
|
||||||
@cursor_x.set cursor
|
@cursor_x.set cursor
|
||||||
render { print_input }
|
render { print_input }
|
||||||
|
|
||||||
C.stdscr.timeout = -1
|
if key = get_input(actions)
|
||||||
ch = C.getch
|
upd = actions.fetch(key, proc { |val|
|
||||||
|
case val
|
||||||
|
when String
|
||||||
|
input.insert cursor, val
|
||||||
|
cursor += val.length
|
||||||
|
when Hash
|
||||||
|
event = val[:event]
|
||||||
|
case event
|
||||||
|
when :click, :release
|
||||||
|
x, y, shift = val.values_at :x, :y, :shift
|
||||||
|
if y == cursor_y
|
||||||
|
cursor = [0, [input.length, x - 2].min].max
|
||||||
|
elsif x > 1 && y <= max_items
|
||||||
|
tv = max_items - y - 1
|
||||||
|
|
||||||
case ch
|
case event
|
||||||
when C::KEY_MOUSE
|
when :click
|
||||||
if m = C.getmouse
|
vselect { |_| tv }
|
||||||
st = m.bstate
|
actions[ctrl(:i)].call(:sclick) if shift
|
||||||
if test_mouse(st, C::BUTTON1_PRESSED, C::BUTTON1_RELEASED)
|
mouse.v = tv
|
||||||
if m.y == cursor_y
|
when :release
|
||||||
# TODO Wide-characters
|
if !shift && mouse.double?(tv)
|
||||||
cursor = [0, [input.length, m.x - 2].min].max
|
actions[ctrl(:m)].call
|
||||||
elsif m.x > 1 && m.y <= max_items
|
|
||||||
vselect { |v|
|
|
||||||
tv = max_items - m.y - 1
|
|
||||||
if test_mouse(st, C::BUTTON1_RELEASED)
|
|
||||||
if test_mouse(st, C::BUTTON_SHIFT)
|
|
||||||
ch = :select
|
|
||||||
elsif pmv == tv
|
|
||||||
ch = ctrl(:m)
|
|
||||||
end
|
end
|
||||||
pmv = tv
|
|
||||||
end
|
end
|
||||||
tv
|
end
|
||||||
}
|
when :scroll
|
||||||
|
diff, shift = val.values_at :diff, :shift
|
||||||
|
actions[ctrl(:i)].call(:sclick) if shift
|
||||||
|
actions[ctrl(diff > 0 ? :j : :k)].call
|
||||||
end
|
end
|
||||||
elsif test_mouse(st, 0x8000000, C::BUTTON2_PRESSED)
|
|
||||||
ch = C::KEY_DOWN
|
|
||||||
elsif test_mouse(st, C::BUTTON4_PRESSED)
|
|
||||||
ch = C::KEY_UP
|
|
||||||
end
|
|
||||||
end
|
|
||||||
when 27
|
|
||||||
C.stdscr.timeout = 0
|
|
||||||
ch =
|
|
||||||
case ch2 = C.getch
|
|
||||||
when 'b' then :alt_b
|
|
||||||
when 'f' then :alt_f
|
|
||||||
when nil then :esc
|
|
||||||
else
|
|
||||||
ch2
|
|
||||||
end
|
end
|
||||||
|
}).call(key)
|
||||||
|
|
||||||
|
# Dispatch key event
|
||||||
|
emit(:key) { [@query.set(input.dup), cursor] } if upd
|
||||||
end
|
end
|
||||||
|
|
||||||
upd = actions.fetch(ch, proc { |ch|
|
|
||||||
if ch.is_a?(Fixnum)
|
|
||||||
# Ruby 1.8
|
|
||||||
if (ch.chr rescue '') =~ /[[:print:]]/
|
|
||||||
ch = ch.chr
|
|
||||||
elsif (nch = num_unicode_bytes(ch)) > 1
|
|
||||||
chs = [ch]
|
|
||||||
(nch - 1).times do |i|
|
|
||||||
chs << C.getch
|
|
||||||
end
|
|
||||||
# UTF-8 TODO Ruby 1.8
|
|
||||||
ch = chs.pack('C*').force_encoding('UTF-8')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if ch.is_a?(String) && ch =~ /[[:print:]]/
|
|
||||||
input.insert cursor, ch
|
|
||||||
cursor += 1
|
|
||||||
end
|
|
||||||
}).call(ch)
|
|
||||||
|
|
||||||
# Dispatch key event
|
|
||||||
emit(:key) { [@query.set(input.dup), cursor] } if upd
|
|
||||||
end
|
end
|
||||||
ensure
|
ensure
|
||||||
C.close_screen
|
C.close_screen
|
||||||
@@ -921,9 +1072,10 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
class ExtendedFuzzyMatcher < FuzzyMatcher
|
class ExtendedFuzzyMatcher < FuzzyMatcher
|
||||||
def initialize rxflag
|
def initialize rxflag, mode = :fuzzy
|
||||||
super
|
super rxflag
|
||||||
@regexps = {}
|
@regexps = {}
|
||||||
|
@mode = mode
|
||||||
end
|
end
|
||||||
|
|
||||||
def empty? q
|
def empty? q
|
||||||
@@ -946,8 +1098,11 @@ class FZF
|
|||||||
when /^\^(.*)\$$/
|
when /^\^(.*)\$$/
|
||||||
Regexp.new('^' << sanitize(Regexp.escape($1)) << '$', rxflag_for(w))
|
Regexp.new('^' << sanitize(Regexp.escape($1)) << '$', rxflag_for(w))
|
||||||
when /^'/
|
when /^'/
|
||||||
w.length > 1 ?
|
if @mode == :fuzzy && w.length > 1
|
||||||
Regexp.new(sanitize(Regexp.escape(w[1..-1])), rxflag_for(w)) : nil
|
exact_regex w[1..-1]
|
||||||
|
elsif @mode == :exact
|
||||||
|
exact_regex w
|
||||||
|
end
|
||||||
when /^\^/
|
when /^\^/
|
||||||
w.length > 1 ?
|
w.length > 1 ?
|
||||||
Regexp.new('^' << sanitize(Regexp.escape(w[1..-1])), rxflag_for(w)) : nil
|
Regexp.new('^' << sanitize(Regexp.escape(w[1..-1])), rxflag_for(w)) : nil
|
||||||
@@ -955,11 +1110,15 @@ class FZF
|
|||||||
w.length > 1 ?
|
w.length > 1 ?
|
||||||
Regexp.new(sanitize(Regexp.escape(w[0..-2])) << '$', rxflag_for(w)) : nil
|
Regexp.new(sanitize(Regexp.escape(w[0..-2])) << '$', rxflag_for(w)) : nil
|
||||||
else
|
else
|
||||||
fuzzy_regex w
|
@mode == :fuzzy ? fuzzy_regex(w) : exact_regex(w)
|
||||||
end, invert ]
|
end, invert ]
|
||||||
}.select { |pair| pair.first }
|
}.select { |pair| pair.first }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def exact_regex w
|
||||||
|
Regexp.new(sanitize(Regexp.escape(w)), rxflag_for(w))
|
||||||
|
end
|
||||||
|
|
||||||
def match list, q, prefix, suffix
|
def match list, q, prefix, suffix
|
||||||
regexps = parse q
|
regexps = parse q
|
||||||
# Look for prefix cache
|
# Look for prefix cache
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.name = 'fzf'
|
spec.name = 'fzf'
|
||||||
spec.version = '0.7.0'
|
spec.version = '0.8.1'
|
||||||
spec.authors = ['Junegunn Choi']
|
spec.authors = ['Junegunn Choi']
|
||||||
spec.email = ['junegunn.c@gmail.com']
|
spec.email = ['junegunn.c@gmail.com']
|
||||||
spec.description = %q{Fuzzy finder for your shell}
|
spec.description = %q{Fuzzy finder for your shell}
|
||||||
|
34
install
34
install
@@ -29,7 +29,7 @@ if [ $? -eq 0 ]; then
|
|||||||
else
|
else
|
||||||
echo "Not found"
|
echo "Not found"
|
||||||
echo "Installing 'curses' gem ... "
|
echo "Installing 'curses' gem ... "
|
||||||
/usr/bin/env gem install curses
|
/usr/bin/env gem install curses -v 1.0.0
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Failed to install 'curses' gem."
|
echo "Failed to install 'curses' gem."
|
||||||
echo "Try installing it as root: sudo gem install curses"
|
echo "Try installing it as root: sudo gem install curses"
|
||||||
@@ -95,23 +95,40 @@ EOF
|
|||||||
cat >> $src << "EOF"
|
cat >> $src << "EOF"
|
||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
# Required to refresh the prompt after fzf
|
if [[ $- =~ i ]]; then
|
||||||
bind '"\er": redraw-current-line'
|
|
||||||
|
|
||||||
# CTRL-T - Paste the selected file path into the command line
|
|
||||||
__fsel() {
|
__fsel() {
|
||||||
find * -path '*/\.*' -prune \
|
find * -path '*/\.*' -prune \
|
||||||
-o -type f -print \
|
-o -type f -print \
|
||||||
|
-o -type d -print \
|
||||||
-o -type l -print 2> /dev/null | fzf -m | while read item; do
|
-o -type l -print 2> /dev/null | fzf -m | while read item; do
|
||||||
printf '%q ' "$item"
|
printf '%q ' "$item"
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
bind '"\C-t": " \C-u \C-a\C-k$(__fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'
|
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
if [ -z "$(set -o | grep '^vi.*on')" ]; then
|
||||||
bind '"\C-r": " \C-e\C-u$(history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
# Required to refresh the prompt after fzf
|
||||||
|
bind '"\er": redraw-current-line'
|
||||||
|
|
||||||
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
|
bind '"\C-t": " \C-u \C-a\C-k$(__fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'
|
||||||
|
|
||||||
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
|
bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
||||||
|
else
|
||||||
|
bind '"\C-x\C-e": shell-expand-line'
|
||||||
|
bind '"\C-x\C-r": redraw-current-line'
|
||||||
|
|
||||||
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
|
# - FIXME: Selected items are attached to the end regardless of cursor position
|
||||||
|
bind '"\C-t": "\eddi$(__fsel)\C-x\C-e\e0P$a \C-x\C-r"'
|
||||||
|
|
||||||
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
|
bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"'
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
EOF
|
EOF
|
||||||
else
|
else
|
||||||
cat >> $src << "EOF"
|
cat >> $src << "EOF"
|
||||||
@@ -125,6 +142,7 @@ fzf-file-widget() {
|
|||||||
FILES=($(
|
FILES=($(
|
||||||
find * -path '*/\.*' -prune \
|
find * -path '*/\.*' -prune \
|
||||||
-o -type f -print \
|
-o -type f -print \
|
||||||
|
-o -type d -print \
|
||||||
-o -type l -print 2> /dev/null | fzf -m))
|
-o -type l -print 2> /dev/null | fzf -m))
|
||||||
unset IFS
|
unset IFS
|
||||||
FILES=$FILES:q
|
FILES=$FILES:q
|
||||||
@@ -145,7 +163,7 @@ bindkey '\ec' fzf-cd-widget
|
|||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
fzf-history-widget() {
|
fzf-history-widget() {
|
||||||
LBUFFER=$(history | fzf +s | sed "s/ *[0-9]* *//")
|
LBUFFER=$(fc -l 1 | fzf +s | sed "s/ *[0-9]* *//")
|
||||||
zle redisplay
|
zle redisplay
|
||||||
}
|
}
|
||||||
zle -N fzf-history-widget
|
zle -N fzf-history-widget
|
||||||
|
@@ -7,7 +7,6 @@ ENV['FZF_EXECUTABLE'] = '0'
|
|||||||
load 'fzf'
|
load 'fzf'
|
||||||
|
|
||||||
class TestFZF < MiniTest::Unit::TestCase
|
class TestFZF < MiniTest::Unit::TestCase
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
ENV.delete 'FZF_DEFAULT_SORT'
|
ENV.delete 'FZF_DEFAULT_SORT'
|
||||||
ENV.delete 'FZF_DEFAULT_OPTS'
|
ENV.delete 'FZF_DEFAULT_OPTS'
|
||||||
@@ -29,56 +28,73 @@ 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 --no-mouse'
|
ENV['FZF_DEFAULT_OPTS'] = '-x -m -s 10000 -q " hello world " +c +2 --no-mouse -f "goodbye world" --black'
|
||||||
fzf = FZF.new []
|
fzf = FZF.new []
|
||||||
assert_equal 10000, fzf.sort
|
assert_equal 10000, fzf.sort
|
||||||
assert_equal ' hello world ',
|
assert_equal ' hello world ',
|
||||||
fzf.query.get
|
fzf.query.get
|
||||||
assert_equal true, fzf.extended
|
assert_equal 'goodbye world',
|
||||||
|
fzf.filter
|
||||||
|
assert_equal :fuzzy, 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.ansi256
|
||||||
|
assert_equal true, fzf.black
|
||||||
assert_equal false, fzf.mouse
|
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 --no-mouse]
|
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello
|
||||||
|
--filter=howdy --extended-exact --no-mouse --no-256]
|
||||||
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.ansi256
|
||||||
|
assert_equal false, fzf.black
|
||||||
assert_equal false, fzf.mouse
|
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 'howdy', fzf.filter
|
||||||
|
assert_equal :exact, fzf.extended
|
||||||
|
|
||||||
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello
|
fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello
|
||||||
--no-sort -i --color --no-multi]
|
--filter a --filter b --no-256 --black
|
||||||
|
--no-sort -i --color --no-multi --256]
|
||||||
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.ansi256
|
||||||
|
assert_equal true, fzf.black
|
||||||
assert_equal true, fzf.mouse
|
assert_equal true, fzf.mouse
|
||||||
assert_equal 1, fzf.rxflag
|
assert_equal 1, fzf.rxflag
|
||||||
|
assert_equal 'b', fzf.filter
|
||||||
assert_equal 'hello', fzf.query.get
|
assert_equal 'hello', fzf.query.get
|
||||||
assert_equal false, fzf.extended
|
assert_equal nil, fzf.extended
|
||||||
|
|
||||||
# Short opts
|
# Short opts
|
||||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x]
|
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fhowdy +2]
|
||||||
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.ansi256
|
||||||
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 'howdy', fzf.filter
|
||||||
|
assert_equal :fuzzy, fzf.extended
|
||||||
|
|
||||||
# Left-to-right
|
# Left-to-right
|
||||||
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x
|
fzf = FZF.new %w[-s 2000 +c -m +i -qhello -x -fgoodbye +2
|
||||||
-s 3000 -c +m -i -q world +x]
|
-s 3000 -c +m -i -q world +x -fworld -2 --black --no-black]
|
||||||
assert_equal 3000, fzf.sort
|
assert_equal 3000, 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.ansi256
|
||||||
|
assert_equal false, fzf.black
|
||||||
assert_equal 1, fzf.rxflag
|
assert_equal 1, fzf.rxflag
|
||||||
assert_equal 'world', fzf.query.get
|
assert_equal 'world', fzf.query.get
|
||||||
assert_equal false, fzf.extended
|
assert_equal 'world', fzf.filter
|
||||||
|
assert_equal nil, fzf.extended
|
||||||
|
|
||||||
fzf = FZF.new %w[--query hello +s -s 2000 --query=world]
|
fzf = FZF.new %w[--query hello +s -s 2000 --query=world]
|
||||||
assert_equal 2000, fzf.sort
|
assert_equal 2000, fzf.sort
|
||||||
@@ -370,6 +386,25 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
FZF.new([]).sort_by_rank(xmatcher.match(list, '01 __', '', '')))
|
FZF.new([]).sort_by_rank(xmatcher.match(list, '01 __', '', '')))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_extended_exact_mode
|
||||||
|
exact = FZF::ExtendedFuzzyMatcher.new Regexp::IGNORECASE, :exact
|
||||||
|
fuzzy = FZF::ExtendedFuzzyMatcher.new Regexp::IGNORECASE, :fuzzy
|
||||||
|
list = %w[
|
||||||
|
extended-exact-mode-not-fuzzy
|
||||||
|
extended'-fuzzy-mode
|
||||||
|
]
|
||||||
|
assert_equal 2, fuzzy.match(list, 'extended', '', '').length
|
||||||
|
assert_equal 2, fuzzy.match(list, 'mode extended', '', '').length
|
||||||
|
assert_equal 2, fuzzy.match(list, 'xtndd', '', '').length
|
||||||
|
assert_equal 2, fuzzy.match(list, "'-fuzzy", '', '').length
|
||||||
|
|
||||||
|
assert_equal 2, exact.match(list, 'extended', '', '').length
|
||||||
|
assert_equal 2, exact.match(list, 'mode extended', '', '').length
|
||||||
|
assert_equal 0, exact.match(list, 'xtndd', '', '').length
|
||||||
|
assert_equal 1, exact.match(list, "'-fuzzy", '', '').length
|
||||||
|
assert_equal 2, exact.match(list, "-fuzzy", '', '').length
|
||||||
|
end
|
||||||
|
|
||||||
if RUBY_PLATFORM =~ /darwin/
|
if RUBY_PLATFORM =~ /darwin/
|
||||||
NFD = '한글'
|
NFD = '한글'
|
||||||
def test_nfc
|
def test_nfc
|
||||||
@@ -425,5 +460,21 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
tokens = fzf.format line, 80, offsets
|
tokens = fzf.format line, 80, offsets
|
||||||
assert_equal [], tokens
|
assert_equal [], tokens
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_mouse_event
|
||||||
|
interval = FZF::MouseEvent::DOUBLE_CLICK_INTERVAL
|
||||||
|
me = FZF::MouseEvent.new nil
|
||||||
|
me.v = 10
|
||||||
|
assert_equal false, me.double?(10)
|
||||||
|
assert_equal false, me.double?(20)
|
||||||
|
me.v = 20
|
||||||
|
assert_equal false, me.double?(10)
|
||||||
|
assert_equal false, me.double?(20)
|
||||||
|
me.v = 20
|
||||||
|
assert_equal false, me.double?(10)
|
||||||
|
assert_equal true, me.double?(20)
|
||||||
|
sleep interval
|
||||||
|
assert_equal false, me.double?(20)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user