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:
parent
44b24ab4c1
commit
80a7358cfc
3 changed files with 107 additions and 4 deletions
|
@ -167,7 +167,7 @@ class Reline::Config
|
||||||
|
|
||||||
case line
|
case line
|
||||||
when /^set +([^ ]+) +([^ ]+)/i
|
when /^set +([^ ]+) +([^ ]+)/i
|
||||||
var, value = $1.downcase, $2.downcase
|
var, value = $1.downcase, $2
|
||||||
bind_variable(var, value)
|
bind_variable(var, value)
|
||||||
next
|
next
|
||||||
when /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o
|
when /\s*("#{KEYSEQ_PATTERN}+")\s*:\s*(.*)\s*$/o
|
||||||
|
@ -270,17 +270,25 @@ class Reline::Config
|
||||||
@show_mode_in_prompt = false
|
@show_mode_in_prompt = false
|
||||||
end
|
end
|
||||||
when 'vi-cmd-mode-string'
|
when 'vi-cmd-mode-string'
|
||||||
@vi_cmd_mode_icon = value
|
@vi_cmd_mode_icon = retrieve_string(value)
|
||||||
when 'vi-ins-mode-string'
|
when 'vi-ins-mode-string'
|
||||||
@vi_ins_mode_icon = value
|
@vi_ins_mode_icon = retrieve_string(value)
|
||||||
when 'emacs-mode-string'
|
when 'emacs-mode-string'
|
||||||
@emacs_mode_string = value
|
@emacs_mode_string = retrieve_string(value)
|
||||||
when *VARIABLE_NAMES then
|
when *VARIABLE_NAMES then
|
||||||
variable_name = :"@#{name.tr(?-, ?_)}"
|
variable_name = :"@#{name.tr(?-, ?_)}"
|
||||||
instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on')
|
instance_variable_set(variable_name, value.nil? || value == '1' || value == 'on')
|
||||||
end
|
end
|
||||||
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)
|
def bind_key(key, func_name)
|
||||||
if key =~ /\A"(.*)"\z/
|
if key =~ /\A"(.*)"\z/
|
||||||
keyseq = parse_keyseq($1)
|
keyseq = parse_keyseq($1)
|
||||||
|
|
|
@ -36,6 +36,51 @@ class Reline::Config::Test < Reline::TestCase
|
||||||
assert_equal true, @config.instance_variable_get(:@disable_completion)
|
assert_equal true, @config.instance_variable_get(:@disable_completion)
|
||||||
end
|
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
|
def test_comment_line
|
||||||
@config.read_lines([" #a: error\n"])
|
@config.read_lines([" #a: error\n"])
|
||||||
assert_not_include @config.key_bindings, nil
|
assert_not_include @config.key_bindings, nil
|
||||||
|
|
|
@ -115,6 +115,56 @@ begin
|
||||||
(cmd)prompt> :a
|
(cmd)prompt> :a
|
||||||
EOC
|
EOC
|
||||||
end
|
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
|
end
|
||||||
rescue LoadError, NameError
|
rescue LoadError, NameError
|
||||||
# On Ruby repository, this test suit doesn't run because Ruby repo doesn't
|
# On Ruby repository, this test suit doesn't run because Ruby repo doesn't
|
||||||
|
|
Loading…
Reference in a new issue