Skip to content

Commit 46a68fc

Browse files
committed
Set default value for Reline.input, Reline.output and Reline.special_prefixes
1 parent 70212fa commit 46a68fc

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/reline.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,11 @@ def filename_quote_characters=(v)
114114
end
115115

116116
def special_prefixes=(v)
117-
@special_prefixes = v.encode(encoding)
117+
if v.nil?
118+
@special_prefixes = ''
119+
else
120+
@special_prefixes = v.encode(encoding)
121+
end
118122
end
119123

120124
def completion_case_fold=(v)
@@ -174,14 +178,25 @@ def dialog_proc(name_sym)
174178
end
175179

176180
def input=(val)
177-
raise TypeError unless val.respond_to?(:getc) or val.nil?
181+
raise TypeError unless val.respond_to?(:getc)
178182
if val.respond_to?(:getc) && io_gate.respond_to?(:input=)
179183
io_gate.input = val
184+
elsif val.nil?
185+
io_gate.input = STDIN
186+
return
187+
else
188+
# noop
189+
# Reline::Windows does not suppport input= method
180190
end
181191
end
182192

183193
def output=(val)
184-
raise TypeError unless val.respond_to?(:write) or val.nil?
194+
if val.nil?
195+
val = STDOUT
196+
elsif !val.respond_to?(:write)
197+
raise TypeError
198+
end
199+
185200
@output = val
186201
io_gate.output = val
187202
end

0 commit comments

Comments
 (0)