summaryrefslogtreecommitdiff
path: root/ruby_1_9_3/lib/irb/input-method.rb
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-14 11:27:23 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-14 11:27:23 +0000
commitaa6e98139c8e1ea442fb2182341aaa08ff55b529 (patch)
treea509eb830418991995bfe3b840d4bf270ff7f0e2 /ruby_1_9_3/lib/irb/input-method.rb
parent9e9d191cf367caa17776231a2d0fad0da47b160a (diff)
add tag v1_9_3_426
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/tags/v1_9_3_426@40733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ruby_1_9_3/lib/irb/input-method.rb')
-rw-r--r--ruby_1_9_3/lib/irb/input-method.rb142
1 files changed, 142 insertions, 0 deletions
diff --git a/ruby_1_9_3/lib/irb/input-method.rb b/ruby_1_9_3/lib/irb/input-method.rb
new file mode 100644
index 0000000000..7227df4ca0
--- /dev/null
+++ b/ruby_1_9_3/lib/irb/input-method.rb
@@ -0,0 +1,142 @@
+#
+# irb/input-method.rb - input methods used irb
+# $Release Version: 0.9.6$
+# $Revision$
+# by Keiju ISHITSUKA(keiju@ruby-lang.org)
+#
+# --
+#
+#
+#
+require 'irb/src_encoding'
+require 'irb/magic-file'
+
+module IRB
+ #
+ # InputMethod
+ # StdioInputMethod
+ # FileInputMethod
+ # (ReadlineInputMethod)
+ #
+ STDIN_FILE_NAME = "(line)"
+ class InputMethod
+ @RCS_ID='-$Id$-'
+
+ def initialize(file = STDIN_FILE_NAME)
+ @file_name = file
+ end
+ attr_reader :file_name
+
+ attr_accessor :prompt
+
+ def gets
+ IRB.fail NotImplementedError, "gets"
+ end
+ public :gets
+
+ def readable_atfer_eof?
+ false
+ end
+ end
+
+ class StdioInputMethod < InputMethod
+ def initialize
+ 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, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
+ end
+
+ def gets
+ print @prompt
+ line = @stdin.gets
+ @line[@line_no += 1] = line
+ end
+
+ def eof?
+ @stdin.eof?
+ end
+
+ def readable_atfer_eof?
+ true
+ end
+
+ def line(line_no)
+ @line[line_no]
+ end
+
+ def encoding
+ @stdin.external_encoding
+ end
+ end
+
+ class FileInputMethod < InputMethod
+ def initialize(file)
+ super
+ @io = IRB::MagicFile.open(file)
+ end
+ attr_reader :file_name
+
+ def eof?
+ @io.eof?
+ end
+
+ def gets
+ print @prompt
+ l = @io.gets
+# print @prompt, l
+ l
+ end
+
+ def encoding
+ @io.external_encoding
+ end
+ end
+
+ begin
+ require "readline"
+ class ReadlineInputMethod < InputMethod
+ include Readline
+ def initialize
+ super
+
+ @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, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
+ end
+
+ def gets
+ Readline.input = @stdin
+ Readline.output = @stdout
+ if l = readline(@prompt, false)
+ HISTORY.push(l) if !l.empty?
+ @line[@line_no += 1] = l + "\n"
+ else
+ @eof = true
+ l
+ end
+ end
+
+ def eof?
+ @eof
+ end
+
+ def readable_atfer_eof?
+ true
+ end
+
+ def line(line_no)
+ @line[line_no]
+ end
+
+ def encoding
+ @stdin.external_encoding
+ end
+ end
+ rescue LoadError
+ end
+end