From 6c2b59f9237843a4570d0ab932705b3fa5c18524 Mon Sep 17 00:00:00 2001 From: aycabta Date: Thu, 4 Jul 2019 20:58:11 +0900 Subject: Support Control- and Meta- --- lib/reline/config.rb | 9 ++++----- test/reline/test_config.rb | 2 ++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/reline/config.rb b/lib/reline/config.rb index 79eb15a1aa..bf77eca5bb 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -5,8 +5,7 @@ class Reline::Config DEFAULT_PATH = '~/.inputrc' - # TODO: Control- and Meta- - KEYSEQ_PATTERN = /\\C-[A-Za-z_]|\\M-[0-9A-Za-z_]|\\C-M-[A-Za-z_]|\\M-C-[A-Za-z_]|\\e|\\[\\\"\'abdfnrtv]|\\\d{1,3}|\\x\h{1,2}|./ + KEYSEQ_PATTERN = /\\(?:C|Control)-[A-Za-z_]|\\(?:M|Meta)-[0-9A-Za-z_]|\\(?:C|Control)-(?:M|Meta)-[A-Za-z_]|\\(?:M|Meta)-(?:C|Control)-[A-Za-z_]|\\e|\\[\\\"\'abdfnrtv]|\\\d{1,3}|\\x\h{1,2}|./ class InvalidInputrc < RuntimeError attr_accessor :file, :lineno @@ -246,9 +245,9 @@ class Reline::Config def key_notation_to_code(notation) case notation - when /\\C-([A-Za-z_])/ + when /\\(?:C|Control)-([A-Za-z_])/ (1 + $1.downcase.ord - ?a.ord) - when /\\M-([0-9A-Za-z_])/ + when /\\(?:M|Meta)-([0-9A-Za-z_])/ modified_key = $1 case $1 when /[0-9]/ @@ -258,7 +257,7 @@ class Reline::Config when /[a-z]/ ?\M-a.bytes.first + (modified_key.ord - ?a.ord) end - when /\\C-M-[A-Za-z_]/, /\\M-C-[A-Za-z_]/ + when /\\(?:C|Control)-(?:M|Meta)-[A-Za-z_]/, /\\(?:M|Meta)-(?:C|Control)-[A-Za-z_]/ # 129 M-^A when /\\(\d{1,3})/ then $1.to_i(8) # octal when /\\x(\h{1,2})/ then $1.to_i(16) # hexadecimal diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index 193b74ec03..ce2fa409a1 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -53,10 +53,12 @@ class Reline::Config::Test < Reline::TestCase def test_bind_key_with_ctrl_chars assert_equal ['input'.bytes, "\C-h\C-h".bytes], @config.bind_key('"input"', '"\C-h\C-H"') + assert_equal ['input'.bytes, "\C-h\C-h".bytes], @config.bind_key('"input"', '"\Control-h\Control-H"') end def test_bind_key_with_meta_chars assert_equal ['input'.bytes, "\M-h\M-H".bytes], @config.bind_key('"input"', '"\M-h\M-H"') + assert_equal ['input'.bytes, "\M-h\M-H".bytes], @config.bind_key('"input"', '"\Meta-h\Meta-H"') end def test_bind_key_with_octal_number -- cgit v1.2.3