1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/reline] Add Reline::Key#match?

https://github.com/ruby/reline/commit/8f6aa3af2e
This commit is contained in:
aycabta 2021-09-03 03:29:10 +09:00 committed by git
parent 38ae3b8e36
commit 9e0caba187
2 changed files with 10 additions and 2 deletions

View file

@ -16,7 +16,13 @@ module Reline
class ConfigEncodingConversionError < StandardError; end
Key = Struct.new('Key', :char, :combined_char, :with_meta)
Key = Struct.new('Key', :char, :combined_char, :with_meta) do
def match?(key)
(key.char.nil? or char.nil? or char == key.char) and
(key.combined_char.nil? or combined_char.nil? or combined_char == key.combined_char) and
(key.with_meta.nil? or with_meta.nil? or with_meta == key.with_meta)
end
end
CursorPos = Struct.new(:x, :y)
DialogRenderInfo = Struct.new(:pos, :contents, :pointer, :bg_color, :width, :height, keyword_init: true)

View file

@ -1480,7 +1480,9 @@ class Reline::LineEditor
@last_key = key
@dialogs.each do |dialog|
# The dialog will intercept the key if trap_key is set.
return if dialog.trap_key and key.combined_char == dialog.trap_key
if dialog.trap_key and dialog.trap_key.match?(key)
return
end
end
@just_cursor_moving = nil
if key.char.nil?