aboutsummaryrefslogtreecommitdiffstats
path: root/lib/irb/input-method.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irb/input-method.rb')
-rw-r--r--lib/irb/input-method.rb32
1 files changed, 27 insertions, 5 deletions
diff --git a/lib/irb/input-method.rb b/lib/irb/input-method.rb
index fc8d476eae..c4142a924e 100644
--- a/lib/irb/input-method.rb
+++ b/lib/irb/input-method.rb
@@ -8,6 +8,9 @@
#
#
#
+require 'irb/src_encoding'
+require 'irb/magic-file'
+
module IRB
#
# InputMethod
@@ -41,15 +44,19 @@ module IRB
super
@line_no = 0
@line = []
+ @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
+ @stdout = IO.open(STDOUT.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
end
def gets
print @prompt
- @line[@line_no += 1] = $stdin.gets
+ line = @stdin.gets
+ p line.encoding
+ @line[@line_no += 1] = line
end
def eof?
- $stdin.eof?
+ @stdin.eof?
end
def readable_atfer_eof?
@@ -59,12 +66,16 @@ module IRB
def line(line_no)
@line[line_no]
end
+
+ def encoding
+ @stdin.external_encoding
+ end
end
class FileInputMethod < InputMethod
def initialize(file)
super
- @io = open(file)
+ @io = IRB::MagicFile.open(file)
end
attr_reader :file_name
@@ -78,6 +89,10 @@ module IRB
# print @prompt, l
l
end
+
+ def encoding
+ @io.external_encoding
+ end
end
begin
@@ -90,11 +105,14 @@ module IRB
@line_no = 0
@line = []
@eof = false
+
+ @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
+ @stdout = IO.open(STDOUT.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
end
def gets
- Readline.input = STDIN
- Readline.output = STDOUT
+ Readline.input = @stdin
+ Readline.output = @stdout
if l = readline(@prompt, false)
HISTORY.push(l) if !l.empty?
@line[@line_no += 1] = l + "\n"
@@ -115,6 +133,10 @@ module IRB
def line(line_no)
@line[line_no]
end
+
+ def encoding
+ @stdin.external_encoding
+ end
end
rescue LoadError
end