Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute compress_meta_key if convert_meta is on #389

Merged
merged 2 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/reline/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def initialize
@keyseq_timeout = 500
@test_mode = false
@autocompletion = false
@convert_meta = true if seven_bit_encoding?(Reline::IOGate.encoding)
end

def reset
Expand Down Expand Up @@ -387,4 +388,8 @@ def parse_keyseq(str)
end
ret
end

private def seven_bit_encoding?(encoding)
encoding == Encoding::US_ASCII
end
end
1 change: 1 addition & 0 deletions lib/reline/key_stroke.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 18 additions & 0 deletions test/reline/test_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ def setup
Dir.mkdir(@tmpdir)
end
Dir.chdir(@tmpdir)
Reline.test_mode
@config = Reline::Config.new
end

def teardown
Dir.chdir(@pwd)
FileUtils.rm_rf(@tmpdir)
Reline.test_reset
@config.reset
end

Expand Down Expand Up @@ -81,6 +83,22 @@ def test_string_value_with_parens_and_quotes
assert_equal '(Emacs)', @config.instance_variable_get(:@emacs_mode_string)
end

def test_encoding_is_ascii
@config.reset
Reline::IOGate.reset(encoding: Encoding::US_ASCII)
@config = Reline::Config.new

assert_equal true, @config.convert_meta
end

def test_encoding_is_not_ascii
@config.reset
Reline::IOGate.reset(encoding: Encoding::UTF_8)
@config = Reline::Config.new

assert_equal nil, @config.convert_meta
end

def test_comment_line
@config.read_lines([" #a: error\n"])
assert_not_include @config.key_bindings, nil
Expand Down
10 changes: 10 additions & 0 deletions test/reline/yamatanooroti/test_rendering.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down