ruby-changes:67569
From: aycabta <ko1@a...>
Date: Fri, 3 Sep 2021 04:27:57 +0900 (JST)
Subject: [ruby-changes:67569] 9e0caba187 (master): [ruby/reline] Add Reline::Key#match?
https://git.ruby-lang.org/ruby.git/commit/?id=9e0caba187 From 9e0caba187746acb03449ea5b08334cd6b68ea0a Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Fri, 3 Sep 2021 03:29:10 +0900 Subject: [ruby/reline] Add Reline::Key#match? https://github.com/ruby/reline/commit/8f6aa3af2e --- lib/reline.rb | 8 +++++++- lib/reline/line_editor.rb | 4 +++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/reline.rb b/lib/reline.rb index f1f82bf..81619de 100644 --- a/lib/reline.rb +++ b/lib/reline.rb @@ -16,7 +16,13 @@ module Reline https://github.com/ruby/ruby/blob/trunk/lib/reline.rb#L16 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 50aeac9..d302008 100644 --- a/lib/reline/line_editor.rb +++ b/lib/reline/line_editor.rb @@ -1480,7 +1480,9 @@ class Reline::LineEditor https://github.com/ruby/ruby/blob/trunk/lib/reline/line_editor.rb#L1480 @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? -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/