m/fzf
1
0
mirror of https://github.com/junegunn/fzf.git synced 2025-11-17 07:43:39 -05:00

Introduce escape time-out for better handling of escape sequences

This commit is contained in:
Junegunn Choi
2014-03-08 01:28:32 +09:00
parent 19e24bd644
commit 871dfb709d

27
fzf
View File

@@ -753,8 +753,15 @@ class FZF
end end
end end
def read_nb chars = 1, default = nil def read_nb chars = 1, default = nil, tries = 20
@tty.read_nonblock(chars).ord rescue default tries.times do |_|
begin
return @tty.read_nonblock(chars).ord
rescue Exception
sleep 0.01
end
end
default
end end
def get_mouse def get_mouse
@@ -808,7 +815,7 @@ class FZF
end end
ord = ord =
case ord = read_nb(1, :esc) case read_nb(1, :esc)
when 91 when 91
case read_nb(1, nil) case read_nb(1, nil)
when 68 then ctrl(:b) when 68 then ctrl(:b)
@@ -816,12 +823,14 @@ class FZF
when 66 then ctrl(:j) when 66 then ctrl(:j)
when 65 then ctrl(:k) when 65 then ctrl(:k)
when 90 then :stab when 90 then :stab
when 49 then read_nb(1); ctrl(:a) when 50 then read_nb; :ins
when 50 then read_nb(1); :ins when 51 then read_nb; :del
when 51 then read_nb(1); :del when 53 then read_nb; :pgup
when 52 then read_nb(1); ctrl(:e) when 54 then read_nb; :pgdn
when 53 then read_nb(1); :pgup when 49 then read_nb; ctrl(:a)
when 54 then read_nb(1); :pgdn when 52 then read_nb; ctrl(:e)
when 72 then ctrl(:a)
when 70 then ctrl(:e)
when 77 when 77
get_mouse get_mouse
end end