[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:
Mari Imaizumi 2024-04-19 21:08:18 +09:00 коммит произвёл git
Родитель 4218e6bbd5
Коммит 604c29e8a2
3 изменённых файлов: 48 добавлений и 0 удалений

Просмотреть файл

@ -880,10 +880,12 @@ class Reline::LineEditor
@completion_state = CompletionState::PERFECT_MATCH
else
@completion_state = CompletionState::MENU_WITH_PERFECT_MATCH
complete(list, true) if @config.show_all_if_ambiguous
end
@perfect_matched = completed
else
@completion_state = CompletionState::MENU
complete(list, true) if @config.show_all_if_ambiguous
end
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)

Просмотреть файл

@ -143,6 +143,11 @@ opt.on('--complete') {
%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') {
Reline.autocompletion = true
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|

Просмотреть файл

@ -1006,6 +1006,47 @@ begin
EOC
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
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.')