Skip to content

Commit 0fe4fdc

Browse files
authored
Implement show-all-if-ambiguous feature (#683)
1 parent 18b3733 commit 0fe4fdc

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

lib/reline/line_editor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,12 @@ def editing_mode
880880
@completion_state = CompletionState::PERFECT_MATCH
881881
else
882882
@completion_state = CompletionState::MENU_WITH_PERFECT_MATCH
883+
complete(list, true) if @config.show_all_if_ambiguous
883884
end
884885
@perfect_matched = completed
885886
else
886887
@completion_state = CompletionState::MENU
888+
complete(list, true) if @config.show_all_if_ambiguous
887889
end
888890
if not just_show_list and target < completed
889891
@buffer_of_lines[@line_index] = (preposing + completed + completion_append_character.to_s + postposing).split("\n")[@line_index] || String.new(encoding: @encoding)

test/reline/yamatanooroti/multiline_repl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ opt.on('--complete') {
143143
%w{String ScriptError SyntaxError Signal}.select{ |c| c.start_with?(target) }
144144
}
145145
}
146+
opt.on('--complete-menu-with-perfect-match') {
147+
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|
148+
%w{abs abs2}.select{ |c| c.start_with?(target) }
149+
}
150+
}
146151
opt.on('--autocomplete') {
147152
Reline.autocompletion = true
148153
Reline.completion_proc = lambda { |target, preposing = nil, postposing = nil|

test/reline/yamatanooroti/test_rendering.rb

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,6 +1006,47 @@ def test_completion_journey_with_empty_line
10061006
EOC
10071007
end
10081008

1009+
def test_completion_menu_is_displayed_horizontally
1010+
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete}, startup_message: 'Multiline REPL.')
1011+
write("S\t\t")
1012+
close
1013+
assert_screen(<<~'EOC')
1014+
Multiline REPL.
1015+
prompt> S
1016+
ScriptError String
1017+
Signal SyntaxError
1018+
EOC
1019+
end
1020+
1021+
def test_show_all_if_ambiguous_on
1022+
write_inputrc <<~LINES
1023+
set show-all-if-ambiguous on
1024+
LINES
1025+
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete}, startup_message: 'Multiline REPL.')
1026+
write("S\t")
1027+
close
1028+
assert_screen(<<~'EOC')
1029+
Multiline REPL.
1030+
prompt> S
1031+
ScriptError String
1032+
Signal SyntaxError
1033+
EOC
1034+
end
1035+
1036+
def test_show_all_if_ambiguous_on_and_menu_with_perfect_match
1037+
write_inputrc <<~LINES
1038+
set show-all-if-ambiguous on
1039+
LINES
1040+
start_terminal(20, 50, %W{ruby -I#{@pwd}/lib #{@pwd}/test/reline/yamatanooroti/multiline_repl --complete-menu-with-perfect-match}, startup_message: 'Multiline REPL.')
1041+
write("a\t")
1042+
close
1043+
assert_screen(<<~'EOC')
1044+
Multiline REPL.
1045+
prompt> abs
1046+
abs abs2
1047+
EOC
1048+
end
1049+
10091050
def test_simple_dialog
10101051
iterate_over_face_configs do |config_name, config_file|
10111052
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.')

0 commit comments

Comments
 (0)