ruby-changes:62624
From: aycabta <ko1@a...>
Date: Tue, 18 Aug 2020 19:16:11 +0900 (JST)
Subject: [ruby-changes:62624] 80a7358cfc (master): [ruby/reline] Keep original characters in inputrc
https://git.ruby-lang.org/ruby.git/commit/?id=80a7358cfc From 80a7358cfcafa9748c232be851e5f70bede32acb Mon Sep 17 00:00:00 2001 From: aycabta <aycabta@g...> Date: Mon, 20 Jul 2020 20:52:07 +0900 Subject: [ruby/reline] Keep original characters in inputrc https://github.com/ruby/reline/commit/96583c6336 diff --git a/lib/reline/config.rb b/lib/reline/config.rb index 9b8ddc0..1cd6079 100644 --- a/lib/reline/config.rb +++ b/lib/reline/config.rb @@ -167,7 +167,7 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L167 case line when /^set +([^ ]+) +([^ ]+)/i - var, value = $1.downcase, $2.downcase + var, value = $1.downcase, $2 bind_variable(var, value) next when /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o @@ -270,17 +270,25 @@ class Reline::Config https://github.com/ruby/ruby/blob/trunk/lib/reline/config.rb#L270 @show_mode_in_prompt = false end when 'vi-cmd-mode-string' - @vi_cmd_mode_icon = value + @vi_cmd_mode_icon = retrieve_string(value) when 'vi-ins-mode-string' - @vi_ins_mode_icon = value + @vi_ins_mode_icon = retrieve_string(value) when 'emacs-mode-string' - @emacs_mode_string = value + @emacs_mode_string = retrieve_string(value) when *VARIABLE_NAMES then variable_name = :"@#{name.tr(?-, ?_)}" instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on') end end + def retrieve_string(str) + if str =~ /\A"(.*)"\z/ + parse_keyseq($1).map(&:chr).join + else + parse_keyseq(str).map(&:chr).join + end + end + def bind_key(key, func_name) if key =~ /\A"(.*)"\z/ keyseq = parse_keyseq($1) diff --git a/test/reline/test_config.rb b/test/reline/test_config.rb index d24d4e8..c1455cd 100644 --- a/test/reline/test_config.rb +++ b/test/reline/test_config.rb @@ -36,6 +36,51 @@ class Reline::Config::Test < Reline::TestCase https://github.com/ruby/ruby/blob/trunk/test/reline/test_config.rb#L36 assert_equal true, @config.instance_variable_get(:@disable_completion) end + def test_string_value + @config.read_lines(<<~LINES.lines) + set show-mode-in-prompt on + set emacs-mode-string Emacs + LINES + + assert_equal 'Emacs', @config.instance_variable_get(:@emacs_mode_string) + end + + def test_string_value_with_brackets + @config.read_lines(<<~LINES.lines) + set show-mode-in-prompt on + set emacs-mode-string [Emacs] + LINES + + assert_equal '[Emacs]', @config.instance_variable_get(:@emacs_mode_string) + end + + def test_string_value_with_brackets_and_quotes + @config.read_lines(<<~LINES.lines) + set show-mode-in-prompt on + set emacs-mode-string "[Emacs]" + LINES + + assert_equal '[Emacs]', @config.instance_variable_get(:@emacs_mode_string) + end + + def test_string_value_with_parens + @config.read_lines(<<~LINES.lines) + set show-mode-in-prompt on + set emacs-mode-string (Emacs) + LINES + + assert_equal '(Emacs)', @config.instance_variable_get(:@emacs_mode_string) + end + + def test_string_value_with_parens_and_quotes + @config.read_lines(<<~LINES.lines) + set show-mode-in-prompt on + set emacs-mode-string "(Emacs)" + LINES + + assert_equal '(Emacs)', @config.instance_variable_get(:@emacs_mode_string) + end + def test_comment_line @config.read_lines([" #a: error\n"]) assert_not_include @config.key_bindings, nil diff --git a/test/reline/yamatanooroti/test_rendering.rb b/test/reline/yamatanooroti/test_rendering.rb index 0d04e38..d348b87 100644 --- a/test/reline/yamatanooroti/test_rendering.rb +++ b/test/reline/yamatanooroti/test_rendering.rb @@ -115,6 +115,56 @@ begin https://github.com/ruby/ruby/blob/trunk/test/reline/yamatanooroti/test_rendering.rb#L115 (cmd)prompt> :a EOC end + + def test_original_mode_icon_emacs + File.open(@inputrc_file, 'w') do |f| + f.write <<~LINES + set show-mode-in-prompt on + set emacs-mode-string [emacs] + LINES + end + start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}) + close + assert_screen(<<~EOC) + Multiline REPL. + [emacs]prompt> + EOC + end + + def test_original_mode_icon_with_quote + File.open(@inputrc_file, 'w') do |f| + f.write <<~LINES + set show-mode-in-prompt on + set emacs-mode-string "[emacs]" + LINES + end + start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}) + close + assert_screen(<<~EOC) + Multiline REPL. + [emacs]prompt> + EOC + end + + def test_original_mode_icon_vi + File.open(@inputrc_file, 'w') do |f| + f.write <<~LINES + set editing-mode vi + set show-mode-in-prompt on + set vi-ins-mode-string "{InS}" + set vi-cmd-mode-string "{CmD}" + LINES + end + start_terminal(5, 30, %W{ruby -I#{@pwd}/lib #{@pwd}/bin/multiline_repl}) + write(":a\n\C-[k") + close + assert_screen(<<~EOC) + Multiline REPL. + {InS}prompt> :a + => :a + {CmD}prompt> :a + EOC + end end rescue LoadError, NameError # On Ruby repository, this test suit doesn't run because Ruby repo doesn't -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/