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

Support Control- and Meta-

This commit is contained in:
aycabta 2019-07-04 20:58:11 +09:00
parent d9f8b88b47
commit 6c2b59f923
2 changed files with 6 additions and 5 deletions

View file

@ -5,8 +5,7 @@ class Reline::Config
DEFAULT_PATH = '~/.inputrc' DEFAULT_PATH = '~/.inputrc'
# TODO: Control- and Meta- 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}|./
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}|./
class InvalidInputrc < RuntimeError class InvalidInputrc < RuntimeError
attr_accessor :file, :lineno attr_accessor :file, :lineno
@ -246,9 +245,9 @@ class Reline::Config
def key_notation_to_code(notation) def key_notation_to_code(notation)
case notation case notation
when /\\C-([A-Za-z_])/ when /\\(?:C|Control)-([A-Za-z_])/
(1 + $1.downcase.ord - ?a.ord) (1 + $1.downcase.ord - ?a.ord)
when /\\M-([0-9A-Za-z_])/ when /\\(?:M|Meta)-([0-9A-Za-z_])/
modified_key = $1 modified_key = $1
case $1 case $1
when /[0-9]/ when /[0-9]/
@ -258,7 +257,7 @@ class Reline::Config
when /[a-z]/ when /[a-z]/
?\M-a.bytes.first + (modified_key.ord - ?a.ord) ?\M-a.bytes.first + (modified_key.ord - ?a.ord)
end 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 # 129 M-^A
when /\\(\d{1,3})/ then $1.to_i(8) # octal when /\\(\d{1,3})/ then $1.to_i(8) # octal
when /\\x(\h{1,2})/ then $1.to_i(16) # hexadecimal when /\\x(\h{1,2})/ then $1.to_i(16) # hexadecimal

View file

@ -53,10 +53,12 @@ class Reline::Config::Test < Reline::TestCase
def test_bind_key_with_ctrl_chars 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"', '"\C-h\C-H"')
assert_equal ['input'.bytes, "\C-h\C-h".bytes], @config.bind_key('"input"', '"\Control-h\Control-H"')
end end
def test_bind_key_with_meta_chars 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"', '"\M-h\M-H"')
assert_equal ['input'.bytes, "\M-h\M-H".bytes], @config.bind_key('"input"', '"\Meta-h\Meta-H"')
end end
def test_bind_key_with_octal_number def test_bind_key_with_octal_number