зеркало из https://github.com/github/ruby.git
[ruby/reline] Implement `show-all-if-ambiguous` feature
(https://github.com/ruby/reline/pull/683) https://github.com/ruby/reline/commit/0fe4fdc794
This commit is contained in:
Родитель
4218e6bbd5
Коммит
604c29e8a2
|
@ -880,10 +880,12 @@ class Reline::LineEditor
|
||||||
@completion_state = CompletionState::PERFECT_MATCH
|
@completion_state = CompletionState::PERFECT_MATCH
|
||||||
else
|
else
|
||||||
@completion_state = CompletionState::MENU_WITH_PERFECT_MATCH
|
@completion_state = CompletionState::MENU_WITH_PERFECT_MATCH
|
||||||
|
complete(list, true) if @config.show_all_if_ambiguous
|
||||||
end
|
end
|
||||||
@perfect_matched = completed
|
@perfect_matched = completed
|
||||||
else
|
else
|
||||||
@completion_state = CompletionState::MENU
|
@completion_state = CompletionState::MENU
|
||||||
|
complete(list, true) if @config.show_all_if_ambiguous
|
||||||
end
|
end
|
||||||
if not just_show_list and target < completed
|
if not just_show_list and target < completed
|
||||||
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding)
|
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding)
|
||||||
|
|
|
@ -143,6 +143,11 @@ opt.on('--complete') {
|
||||||
%w{String ScriptError SyntaxError Signal}.select{ |c| c.start_with?(target) }
|
%w{String ScriptError SyntaxError Signal}.select{ |c| c.start_with?(target) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
opt.on('--complete-menu-with-perfect-match') {
|
||||||
|
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
|
||||||
|
%w{abs abs2}.select{ |c| c.start_with?(target) }
|
||||||
|
}
|
||||||
|
}
|
||||||
opt.on('--autocomplete') {
|
opt.on('--autocomplete') {
|
||||||
Reline.autocompletion = true
|
Reline.autocompletion = true
|
||||||
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
|
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
|
||||||
|
|
|
@ -1006,6 +1006,47 @@ begin
|
||||||
EOC
|
EOC
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_completion_menu_is_displayed_horizontally
|
||||||
|
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete}, startup_message: 'Multiline REPL.')
|
||||||
|
write("S\t\t")
|
||||||
|
close
|
||||||
|
assert_screen(<<~'EOC')
|
||||||
|
Multiline REPL.
|
||||||
|
prompt> S
|
||||||
|
ScriptError String
|
||||||
|
Signal SyntaxError
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show_all_if_ambiguous_on
|
||||||
|
write_inputrc <<~LINES
|
||||||
|
set show-all-if-ambiguous on
|
||||||
|
LINES
|
||||||
|
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete}, startup_message: 'Multiline REPL.')
|
||||||
|
write("S\t")
|
||||||
|
close
|
||||||
|
assert_screen(<<~'EOC')
|
||||||
|
Multiline REPL.
|
||||||
|
prompt> S
|
||||||
|
ScriptError String
|
||||||
|
Signal SyntaxError
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_show_all_if_ambiguous_on_and_menu_with_perfect_match
|
||||||
|
write_inputrc <<~LINES
|
||||||
|
set show-all-if-ambiguous on
|
||||||
|
LINES
|
||||||
|
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete-menu-with-perfect-match}, startup_message: 'Multiline REPL.')
|
||||||
|
write("a\t")
|
||||||
|
close
|
||||||
|
assert_screen(<<~'EOC')
|
||||||
|
Multiline REPL.
|
||||||
|
prompt> abs
|
||||||
|
abs abs2
|
||||||
|
EOC
|
||||||
|
end
|
||||||
|
|
||||||
def test_simple_dialog
|
def test_simple_dialog
|
||||||
iterate_over_face_configs do |config_name, config_file|
|
iterate_over_face_configs do |config_name, config_file|
|
||||||
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib -r#{config_file.path} #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
|
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib -r#{config_file.path} #{@pwd}/test/reline/yamatanooroti/multiline_repl --dialog simple}, startup_message: 'Multiline REPL.')
|
||||||
|
|
Загрузка…
Ссылка в новой задаче