Completely remove mouse support
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Since the version 0.7.0, fzf internally used Curses.getch() call to take user input, which allowed it to support mouse input as well. However it has turned out that Curses.getch() has introduced glitches that cannot be easily handled (e.g. Try resize the terminal). So I finally decided that it's not worth the trouble and drop the mouse support.
authored by Junegunn Choi · committed by Junegunn Choi · parent 65ae6ca · Browse files · 3 files·+72 added−136 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+72 added−136 removed
- tests:+2 added−6 removed
- other:+70 added−130 removed
Provenance
- Commit
2fb8ae0- Tree
71e3b66- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
65ae6ca
3 files changed+72 added−136 removed
modified:test/test_fzf.rb+2 added-6 removed
18 unmodified lines19 assert_equal 1000, fzf.sort20 assert_equal false, fzf.multi21 assert_equal true, fzf.color22 assert_equal nil, fzf.rxflag23- assert_equal true, fzf.mouse23 end24 25 def test_environment_variables26 # Deprecated27 ENV['FZF_DEFAULT_SORT'] = '20000'28 fzf = FZF.new []29 assert_equal 20000, fzf.sort30 32- 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 -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.color42- assert_equal false, fzf.mouse41 end42 43 def test_option_parser44 # Long opts45 fzf = FZF.new %w[--sort=2000 --no-color --multi +i --query hello48- --filter=howdy --extended-exact --no-mouse]46+ --filter=howdy --extended-exact]47 assert_equal 2000, fzf.sort48 assert_equal true, fzf.multi49 assert_equal false, fzf.color52- assert_equal false, fzf.mouse50 assert_equal 0, fzf.rxflag51 assert_equal 'hello', fzf.query.get52 assert_equal 'howdy', fzf.filter53 assert_equal :exact, fzf.extended3 unmodified lines57 --no-sort -i --color --no-multi]58 assert_equal nil, fzf.sort59 assert_equal false, fzf.multi60 assert_equal true, fzf.color64- assert_equal true, fzf.mouse61 assert_equal 1, fzf.rxflag62 assert_equal 'b', fzf.filter63 assert_equal 'hello', fzf.query.get64 assert_equal nil, fzf.extended388 unmodified linesmodified:fzf+70 added-126 removed
5 unmodified lines6 # / /_/_ / / /_7 # / __/ / /_/ __/8 # /_/ /___/_/ Fuzzy finder for your shell9 #10-# Version: 0.7.3 (March 5, 2014)10+# Version: 0.8.0 (March 6, 2014)11 #12 # Author: Junegunn Choi13 # URL: https://github.com/junegunn/fzf14 # License: MIT34 unmodified lines49 end50 51 class FZF52 C = Curses53- attr_reader :rxflag, :sort, :color, :mouse, :multi, :query, :filter, :extended53+ attr_reader :rxflag, :sort, :color, :multi, :query, :filter, :extended54 55 class AtomicVar56 def initialize value57 @value = value20 unmodified lines78 @sort = ENV.fetch('FZF_DEFAULT_SORT', 1000).to_i79 @color = true80 @multi = false81 @extended = nil82- @mouse = true82 @filter = nil84- @pending = nil83 84 argv =85 if opts = ENV['FZF_DEFAULT_OPTS']86 require 'shellwords'12 unmodified lines99 when '-i' then @rxflag = Regexp::IGNORECASE100 when '+i' then @rxflag = 0101 when '-c', '--color' then @color = true102 when '+c', '--no-color' then @color = false105- when '--no-mouse' then @mouse = false103 when '+s', '--no-sort' then @sort = nil104 when '-q', '--query'105 usage 1, 'query string required' unless query = argv.shift106 @query = AtomicVar.new query.dup18 unmodified lines125 end126 127 @source = source.clone128 @mtx = Mutex.new132- @rmtx = Mutex.new129 @cv = ConditionVariable.new130 @events = {}131 @new = []132 @queue = Queue.new133+ @pending = nil134 135 unless @filter136 @query ||= AtomicVar.new('')137 @cursor_x = AtomicVar.new(@query.length)65 unmodified lines203 +s, --no-sort Do not sort the result. Keep the sequence unchanged.204 -i Case-insensitive match (default: smart-case match)205 +i Case-sensitive match206 +c, --no-color Disable colors210- --no-mouse Disable mouse207 208 Environment variables209 FZF_DEFAULT_COMMAND Default command to use when input is tty210 FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")] + $/ + $/294 unmodified lines505 end506 507 def init_screen508 C.init_screen513- if @mouse514- C.mouseinterval 0515- C.mousemask C::ALL_MOUSE_EVENTS516- end517- C.stdscr.keypad(true)509 C.start_color510 dbg =511 if C.respond_to?(:use_default_colors)512 C.use_default_colors1 unmodified line514 else515 C::COLOR_BLACK516 end517 C.raw527- C.nonl518 C.noecho519 520 if @color521 if ENV['TERM'].to_s =~ /256/49 unmodified lines571 else572 exit 1573 end574 else585- $stdin.reopen IO.open(IO.sysopen('/dev/tty'), 'r') if curses575 @source576 end577 578 Thread.new do131 unmodified lines710 def start_renderer711 Thread.new do712 begin713 while blk = @queue.shift725- @rmtx.synchronize do726- blk.call727- refresh714+ blk.call715+ refresh728- end716 end717 rescue Exception => e718 @main.raise e719 end23 unmodified lines743 1744 end745 end746 760- def test_mouse st, *states761- states.any? { |s| s & st > 0 }762- end747+ def get_input actions748+ @tty ||= IO.open(IO.sysopen('/dev/tty'), 'r')749 764- def to_printable ch765- if ch.is_a?(Fixnum)766- # Ruby 1.8767- if (ch.chr rescue '') =~ /[[:print:]]/768- ch = ch.chr769- elsif (nch = num_unicode_bytes(ch)) > 1770- chs = [ch]771- (nch - 1).times do |i|772- chs << getch_nb773- end774- # UTF-8 TODO Ruby 1.8775- ch = chs.pack('C*').force_encoding('UTF-8')776- end777- end778-779- ch.is_a?(String) && ch =~ /[[:print:]]/ && ch780- end781-782- def getch_nb783- @rmtx.synchronize { C.getch }784- end785-786- def getch750 if pending = @pending751 @pending = nil752 return pending753 end754 792- C.stdscr.timeout = -1793- c = C.getch794- C.stdscr.timeout = 0795- if ch = to_printable(c)796- chs = [ch]797- while AFTER_1_9 && c = getch_nb798- if ch = to_printable(c)799- chs << ch755+ str = ''756+ while true757+ ord =758+ if str.empty?759+ @tty.getc.ord760 else801- @pending = c802- break761+ begin762+ ord = @tty.read_nonblock(1).ord763+ if (nb = num_unicode_bytes(ord)) > 1764+ ords = [ord]765+ (nb - 1).times do |_|766+ ords << @tty.read_nonblock(1).ord767+ end768+ # UTF-8 TODO Ruby 1.8769+ ords.pack('C*').force_encoding('UTF-8')770+ else771+ ord772+ end773+ rescue Exception774+ return str775+ end776 end777+778+ ord =779+ case ord = (@tty.read_nonblock(1).ord rescue :esc)780+ when 91781+ case (@tty.read_nonblock(1).ord rescue nil)782+ when 68 then ctrl(:b)783+ when 67 then ctrl(:f)784+ when 66 then ctrl(:j)785+ when 65 then ctrl(:k)786+ when 90 then :stab787+ else next788+ end789+ when 'b', 98 then :alt_b790+ when 'f', 102 then :alt_f791+ when :esc then :esc792+ else next793+ end if ord == 27794+795+ if actions.has_key?(ord)796+ if str.empty?797+ return ord798+ else799+ @pending = ord800+ return str801+ end802+ else803+ unless ord.is_a? String804+ ord = [ord].pack('U*')805+ end806+ str << ord if ord =~ /[[:print:]]/807 end805- chs806- else807- c808 end809 end810 811 def start_loop28 unmodified lines840 @selects.delete sel841 else842 @selects[sel] = 1843 end844- vselect { |v|845- v + case o846- when :select then 0847- when C::KEY_BTAB then 1848- else -1849- end850- }844+ vselect { |v| v + (o == :stab ? 1 : -1) }845 end846 },847 ctrl(:b) => proc { cursor = [0, cursor - 1].max; nil },848 ctrl(:f) => proc { cursor = [input.length, cursor + 1].min; nil },3 unmodified lines852 cursor += (input[cursor..-1].index(/(\S\s)|(.$)/) || -1) + 1853 nil854 },855 }862- actions[C::KEY_UP] = actions[ctrl(:p)] = actions[ctrl(:k)]863- actions[C::KEY_DOWN] = actions[ctrl(:n)] = actions[ctrl(:j)]864- actions[C::KEY_LEFT] = actions[ctrl(:b)]865- actions[C::KEY_RIGHT] = actions[ctrl(:f)]866- actions[C::KEY_BTAB] = actions[:select] = actions[ctrl(:i)]867- actions[C::KEY_BACKSPACE] = actions[127] = actions[ctrl(:h)]856+ actions[ctrl(:p)] = actions[ctrl(:k)]857+ actions[ctrl(:n)] = actions[ctrl(:j)]858+ actions[:stab] = actions[ctrl(:i)]859+ actions[127] = actions[ctrl(:h)]860 actions[ctrl(:q)] = actions[ctrl(:g)] = actions[ctrl(:c)] = actions[:esc]861 862 emit(:key) { [@query.get, cursor] } unless @query.empty?871- pmv = nil863 while true864 @cursor_x.set cursor865 render { print_input }866 876- case ch = getch877- when C::KEY_MOUSE878- if m = C.getmouse879- st = m.bstate880- if test_mouse(st, C::BUTTON1_PRESSED, C::BUTTON1_RELEASED)881- if m.y == cursor_y882- # TODO Wide-characters883- cursor = [0, [input.length, m.x - 2].min].max884- elsif m.x > 1 && m.y <= max_items885- vselect { |v|886- tv = max_items - m.y - 1887- if test_mouse(st, C::BUTTON1_RELEASED)888- if test_mouse(st, C::BUTTON_SHIFT)889- ch = :select890- elsif pmv == tv891- ch = ctrl(:m)892- end893- pmv = tv894- end895- tv896- }897- end898- elsif test_mouse(st, 0x8000000, C::BUTTON2_PRESSED)899- ch = C::KEY_DOWN900- elsif test_mouse(st, C::BUTTON4_PRESSED)901- ch = C::KEY_UP902- end903- end904- when 27905- C.stdscr.timeout = 0906- ch = # Typeahead arrow keys907- case ch2 = getch_nb908- when '[', 91909- case ch3 = getch_nb910- when 'D', 68 then ctrl(:b)911- when 'C', 67 then ctrl(:f)912- when 'B', 66 then ctrl(:j)913- when 'A', 65 then ctrl(:k)914- else ch3915- end916- when 'b', 98 then :alt_b917- when 'f', 102 then :alt_f918- when nil then :esc919- else ch2920- end921- end867+ if key = get_input(actions)868+ upd = actions.fetch(key, proc { |str|869+ input.insert cursor, str870+ cursor += str.length871+ }).call(key)872 923- upd = actions.fetch(ch, proc { |ch|924- if ch.is_a? Array925- input.insert cursor, ch.join926- cursor += ch.length927- end928- }).call(ch)929-930- # Dispatch key event931- emit(:key) { [@query.set(input.dup), cursor] } if upd873+ # Dispatch key event874+ emit(:key) { [@query.set(input.dup), cursor] } if upd875+ end876 end877 ensure878 C.close_screen879 if got142 unmodified linesmodified:README.md-4 removed
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- --no-mouse Disable mouse61 62 Environment variables63 FZF_DEFAULT_COMMAND Default command to use when input is tty64 FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")35 unmodified lines100 101 If you enable multi-select mode with `-m` option, you can select multiple items102 with TAB or Shift-TAB key.103 105-You can also use mouse. Click on an item to select it or shift-click to select106-multiple items. Use mouse wheel to move the cursor up and down.107-104 ### Extended-search mode105 106 With `-x` or `--extended` option, fzf will start in "extended-search mode".107 232 unmodified lines