Skip to content

Commit

Permalink
Set default value for Reline.input, Reline.output and Reline.special_…
Browse files Browse the repository at this point in the history
…prefixes
  • Loading branch information
ima1zumi committed Jan 15, 2025
1 parent 24e6128 commit fc0289b
Showing 1 changed file with 20 additions and 5 deletions.
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
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
elsif !val.respond_to?(:write)
raise TypeError
end

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

0 comments on commit fc0289b

Please sign in to comment.