Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default value for Reline.input, Reline.output and Reline.special_prefixes #805

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions lib/reline.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ def filename_quote_characters=(v)
end

def special_prefixes=(v)
@special_prefixes = v.encode(encoding)
if v.nil?
@special_prefixes = ''
else
@special_prefixes = v.encode(encoding)
end
end

def completion_case_fold=(v)
Expand Down Expand Up @@ -174,14 +178,25 @@ def dialog_proc(name_sym)
end

def input=(val)
raise TypeError unless val.respond_to?(:getc) or val.nil?
if val.respond_to?(:getc) && io_gate.respond_to?(:input=)
io_gate.input = val
if val.nil?
io_gate.input = STDIN
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reline::Windows have attr_writer :output but does not have input= method and it does not support changing input.

We need a check like before, or add a no-op input= method to Reline::Windows.

return
elsif !val.respond_to?(:getc)
raise TypeError
end

io_gate.input = val
end

def output=(val)
raise TypeError unless val.respond_to?(:write) or val.nil?
if val.nil?
@output = STDOUT
io_gate.output = STDOUT
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe just val = STDOUT is enough and simple.

elsif !val.respond_to?(:write)
raise TypeError
end

@output = val
io_gate.output = val
end
Expand Down
Loading