summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2021-09-03 03:29:10 +0900
committergit <svn-admin@ruby-lang.org>2021-09-03 04:27:48 +0900
commit9e0caba187746acb03449ea5b08334cd6b68ea0a (patch)
treea1237293e82ab90c8a816b3d17fbc78d0d167beb
parent38ae3b8e36a6bdb39a8fa743789525ad764e064d (diff)
[ruby/reline] Add Reline::Key#match?
https://github.com/ruby/reline/commit/8f6aa3af2e
-rw-r--r--lib/reline.rb8
-rw-r--r--lib/reline/line_editor.rb4
2 files changed, 10 insertions, 2 deletions
diff --git a/lib/reline.rb b/lib/reline.rb
index f1f82bff72..81619dea77 100644
--- a/lib/reline.rb
+++ b/lib/reline.rb
@@ -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)
diff --git a/lib/reline/line_editor.rb b/lib/reline/line_editor.rb
index 50aeac996f..d3020087bf 100644
--- a/lib/reline/line_editor.rb
+++ b/lib/reline/line_editor.rb
@@ -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?