This commit is contained in:
aycabta 2019-07-04 20:58:11 +09:00
Родитель d9f8b88b47
Коммит 6c2b59f923
2 изменённых файлов: 6 добавлений и 5 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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