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 27, 2025
1 parent ec28843 commit 9c7684d
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 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,26 @@ def dialog_proc(name_sym)
end

def input=(val)
raise TypeError unless val.respond_to?(:getc) or val.nil?
raise TypeError unless val.respond_to?(:getc)
if val.respond_to?(:getc) && io_gate.respond_to?(:input=)
io_gate.input = val
elsif val.nil?
io_gate.input = STDIN
return
else
# noop
# Reline::Windows does not suppport input= method
end
end

def output=(val)
raise TypeError unless val.respond_to?(:write) or val.nil?
if val.nil?
val = STDOUT
return
elsif !val.respond_to?(:write)
raise TypeError
end

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

0 comments on commit 9c7684d

Please sign in to comment.