From 9491cc854270feb105b819648fb7b9b3419d8986 Mon Sep 17 00:00:00 2001 From: ima1zumi Date: Mon, 22 Nov 2021 21:16:20 +0900 Subject: [PATCH] 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. Co-authored-by: TOMITA Masahiro --- lib/reline/key_stroke.rb | 1 + test/reline/yamatanooroti/test_rendering.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/lib/reline/key_stroke.rb b/lib/reline/key_stroke.rb index 16e5f69914..c1c61513a9 100644 --- a/lib/reline/key_stroke.rb +++ b/lib/reline/key_stroke.rb @@ -4,6 +4,7 @@ def initialize(config) 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) diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index e1dde83589..e89d3efba8 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -739,6 +739,16 @@ def test_meta_key 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")