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

[ruby/reline] Execute compress_meta_key if convert_meta is on

fix `#357`

When using 8-bit characters, it is better not to use `compress_meta_key`.
I believe not to use `compress_meta_key` unless `set convert-meta on` is written in the `.inputrc`.

The following is a quote from tmtm's comments.

> The behavior of this compress_meta_key method is similar to the behavior of convert-meta=on in readline, but readline turns off convert-meta if the locale contains 8bit characters.

> In readline(3):

> convert-meta (On)
> If set to On, readline will convert characters with the eighth
> bit set to an ASCII key sequence by stripping the eighth bit and
> prefixing it with an escape character (in effect, using escape
> as the meta prefix). The default is On, but readline will set
> it to Off if the locale contains eight-bit characters.

https://github.com/ruby/reline/commit/9491cc8542

Co-authored-by: TOMITA Masahiro <tommy@tmtm.org>
This commit is contained in:
ima1zumi 2021-11-22 21:16:20 +09:00 committed by git
parent 3a2ae5bb19
commit 519a945efc
2 changed files with 11 additions and 0 deletions

View file

@ -4,6 +4,7 @@ class Reline::KeyStroke
end
def compress_meta_key(ary)
return ary unless @config.convert_meta
ary.inject([]) { |result, key|
if result.size > 0 and result.last == "\e".ord
result[result.size - 1] = Reline::Key.new(key, key | 0b10000000, true)

View file

@ -739,6 +739,16 @@ begin
EOC
end
def test_not_meta_key
start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("おだんご") # "だ" in UTF-8 contains "\xA0"
close
assert_screen(<<~EOC)
Multiline REPL.
prompt>
EOC
end
def test_force_enter
start_terminal(30, 120, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl}, startup_message: 'Multiline REPL.')
write("def hoge\nend\C-p\C-e")