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

[ruby/reline] Keep original characters in inputrc

https://github.com/ruby/reline/commit/96583c6336
This commit is contained in:
aycabta 2020-07-20 20:52:07 +09:00
parent 44b24ab4c1
commit 80a7358cfc
3 changed files with 107 additions and 4 deletions

View file

@ -167,7 +167,7 @@ class Reline::Config
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
@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)

View file

@ -36,6 +36,51 @@ class Reline::Config::Test < Reline::TestCase
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

View file

@ -115,6 +115,56 @@ begin
(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