Skip to content

Commit fe3c930

Browse files
Restore old 1.8.7 check on completion_proc=
`rb-readline`, the default readline implementation that currently comes with Windows, does not allow `nil` to be passed in here because it doesn't respond to `call`. See: https://github.com/ConnorAtherton/rb-readline/blob/9fba246073f78831b7c7129c76cc07d8476a8892/lib/readline.rb#L91-L97
1 parent a1b8eaa commit fe3c930

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

lib/thor/line_editor/readline.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def self.available?
1313
def readline
1414
if echo?
1515
::Readline.completion_append_character = nil
16-
::Readline.completion_proc = completion_proc
16+
# rb-readline does not allow Readline.completion_proc= to receive nil.
17+
if complete = completion_proc
18+
::Readline.completion_proc = complete
19+
end
1720
::Readline.readline(prompt, add_to_history?)
1821
else
1922
super

spec/line_editor/readline_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@
2323
describe "#readline" do
2424
it "invokes the readline library" do
2525
expect(::Readline).to receive(:readline).with("> ", true).and_return("foo")
26-
expect(::Readline).to receive(:completion_proc=)
26+
expect(::Readline).to_not receive(:completion_proc=)
2727
editor = Thor::LineEditor::Readline.new("> ", {})
2828
expect(editor.readline).to eq("foo")
2929
end
3030

3131
it "supports the add_to_history option" do
3232
expect(::Readline).to receive(:readline).with("> ", false).and_return("foo")
33-
expect(::Readline).to receive(:completion_proc=)
33+
expect(::Readline).to_not receive(:completion_proc=)
3434
editor = Thor::LineEditor::Readline.new("> ", :add_to_history => false)
3535
expect(editor.readline).to eq("foo")
3636
end

0 commit comments

Comments
 (0)