rubysl-irb 1.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +3 -2
  3. data/lib/irb/cmd/chws.rb +6 -6
  4. data/lib/irb/cmd/fork.rb +10 -10
  5. data/lib/irb/cmd/help.rb +24 -14
  6. data/lib/irb/cmd/load.rb +8 -7
  7. data/lib/irb/cmd/nop.rb +8 -8
  8. data/lib/irb/cmd/pushws.rb +6 -5
  9. data/lib/irb/cmd/subirb.rb +6 -7
  10. data/lib/irb/completion.rb +90 -58
  11. data/lib/irb/context.rb +197 -30
  12. data/lib/irb/ext/change-ws.rb +17 -10
  13. data/lib/irb/ext/history.rb +20 -10
  14. data/lib/irb/ext/loader.rb +22 -12
  15. data/lib/irb/ext/math-mode.rb +16 -6
  16. data/lib/irb/ext/multi-irb.rb +69 -24
  17. data/lib/irb/ext/save-history.rb +87 -37
  18. data/lib/irb/ext/tracer.rb +17 -7
  19. data/lib/irb/ext/use-loader.rb +14 -6
  20. data/lib/irb/ext/workspaces.rb +16 -6
  21. data/lib/irb/extend-command.rb +92 -34
  22. data/lib/irb/frame.rb +18 -5
  23. data/lib/irb/help.rb +20 -19
  24. data/lib/irb/init.rb +156 -104
  25. data/lib/irb/input-method.rb +96 -23
  26. data/lib/irb/inspector.rb +145 -0
  27. data/lib/irb/lc/.document +4 -0
  28. data/lib/irb/lc/error.rb +8 -7
  29. data/lib/irb/lc/{help-message.rb → help-message} +14 -11
  30. data/lib/irb/lc/ja/encoding_aliases.rb +10 -0
  31. data/lib/irb/lc/ja/error.rb +19 -16
  32. data/lib/irb/lc/ja/help-message +33 -28
  33. data/lib/irb/locale.rb +83 -85
  34. data/lib/irb/magic-file.rb +37 -0
  35. data/lib/irb/notifier.rb +101 -15
  36. data/lib/irb/output-method.rb +38 -32
  37. data/lib/irb/ruby-lex.rb +143 -81
  38. data/lib/irb/ruby-token.rb +13 -19
  39. data/lib/irb/slex.rb +26 -27
  40. data/lib/irb/src_encoding.rb +4 -0
  41. data/lib/irb/version.rb +6 -7
  42. data/lib/irb/workspace.rb +22 -15
  43. data/lib/irb/ws-for-case-2.rb +5 -6
  44. data/lib/irb/xmp.rb +91 -4
  45. data/lib/rubysl/irb/irb.rb +523 -175
  46. data/lib/rubysl/irb/version.rb +1 -1
  47. data/rubysl-irb.gemspec +7 -6
  48. metadata +35 -15
data/lib/irb/help.rb CHANGED
@@ -1,35 +1,36 @@
1
1
  #
2
2
  # irb/help.rb - print usage module
3
- # $Release Version: 0.9.5$
4
- # $Revision: 16857 $
5
- # $Date: 2008-06-06 01:05:24 -0700 (Fri, 06 Jun 2008) $
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ishitsuka.com)
7
6
  #
8
7
  # --
9
8
  #
10
- #
11
9
  #
10
+ #
11
+
12
+ require 'irb/magic-file'
12
13
 
13
14
  module IRB
15
+ # Outputs the irb help message, see IRB@Command+line+options.
14
16
  def IRB.print_usage
15
17
  lc = IRB.conf[:LC_MESSAGES]
16
- path = lc.find("irb/help-message.rb")
18
+ path = lc.find("irb/help-message")
17
19
  space_line = false
18
- File.foreach(path) do
19
- |l|
20
- if /^\s*$/ =~ l
21
- lc.puts l unless space_line
22
- space_line = true
23
- next
20
+ IRB::MagicFile.open(path){|f|
21
+ f.each_line do |l|
22
+ if /^\s*$/ =~ l
23
+ lc.puts l unless space_line
24
+ space_line = true
25
+ next
26
+ end
27
+ space_line = false
28
+
29
+ l.sub!(/#.*$/, "")
30
+ next if /^\s*$/ =~ l
31
+ lc.puts l
24
32
  end
25
- space_line = false
26
-
27
- l.sub!(/#.*$/, "")
28
- l.sub!(/<<HELP/, "")
29
- l.sub!(/HELP/, "")
30
- next if /^\s*$/ =~ l
31
- lc.puts l
32
- end
33
+ }
33
34
  end
34
35
  end
35
36
 
data/lib/irb/init.rb CHANGED
@@ -1,16 +1,15 @@
1
1
  #
2
2
  # irb/init.rb - irb initialize module
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
9
+ #
11
10
  #
12
11
 
13
- module IRB
12
+ module IRB # :nodoc:
14
13
 
15
14
  # initialize config
16
15
  def IRB.setup(ap_path)
@@ -21,7 +20,7 @@ module IRB
21
20
  IRB.load_modules
22
21
 
23
22
  unless @CONF[:PROMPT][@CONF[:PROMPT_MODE]]
24
- IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
23
+ IRB.fail(UndefinedPromptMode, @CONF[:PROMPT_MODE])
25
24
  end
26
25
  end
27
26
 
@@ -34,7 +33,6 @@ module IRB
34
33
  unless ap_path and @CONF[:AP_NAME]
35
34
  ap_path = File.join(File.dirname(File.dirname(__FILE__)), "irb.rb")
36
35
  end
37
-
38
36
  @CONF[:AP_NAME] = File::basename(ap_path, ".rb")
39
37
 
40
38
  @CONF[:IRB_NAME] = "irb"
@@ -46,7 +44,7 @@ module IRB
46
44
 
47
45
  @CONF[:MATH_MODE] = false
48
46
  @CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
49
- @CONF[:INSPECT_MODE] = nil
47
+ @CONF[:INSPECT_MODE] = true
50
48
  @CONF[:USE_TRACER] = false
51
49
  @CONF[:USE_LOADER] = false
52
50
  @CONF[:IGNORE_SIGINT] = true
@@ -61,49 +59,49 @@ module IRB
61
59
 
62
60
  @CONF[:PROMPT] = {
63
61
  :NULL => {
64
- :PROMPT_I => nil,
65
- :PROMPT_N => nil,
66
- :PROMPT_S => nil,
67
- :PROMPT_C => nil,
68
- :RETURN => "%s\n"
69
- },
62
+ :PROMPT_I => nil,
63
+ :PROMPT_N => nil,
64
+ :PROMPT_S => nil,
65
+ :PROMPT_C => nil,
66
+ :RETURN => "%s\n"
67
+ },
70
68
  :DEFAULT => {
71
- :PROMPT_I => "%N(%m):%03n:%i> ",
72
- :PROMPT_N => "%N(%m):%03n:%i> ",
73
- :PROMPT_S => "%N(%m):%03n:%i%l ",
74
- :PROMPT_C => "%N(%m):%03n:%i* ",
75
- :RETURN => "=> %s\n"
76
- },
69
+ :PROMPT_I => "%N(%m):%03n:%i> ",
70
+ :PROMPT_N => "%N(%m):%03n:%i> ",
71
+ :PROMPT_S => "%N(%m):%03n:%i%l ",
72
+ :PROMPT_C => "%N(%m):%03n:%i* ",
73
+ :RETURN => "=> %s\n"
74
+ },
77
75
  :CLASSIC => {
78
- :PROMPT_I => "%N(%m):%03n:%i> ",
79
- :PROMPT_N => "%N(%m):%03n:%i> ",
80
- :PROMPT_S => "%N(%m):%03n:%i%l ",
81
- :PROMPT_C => "%N(%m):%03n:%i* ",
82
- :RETURN => "%s\n"
83
- },
76
+ :PROMPT_I => "%N(%m):%03n:%i> ",
77
+ :PROMPT_N => "%N(%m):%03n:%i> ",
78
+ :PROMPT_S => "%N(%m):%03n:%i%l ",
79
+ :PROMPT_C => "%N(%m):%03n:%i* ",
80
+ :RETURN => "%s\n"
81
+ },
84
82
  :SIMPLE => {
85
- :PROMPT_I => ">> ",
86
- :PROMPT_N => ">> ",
87
- :PROMPT_S => nil,
88
- :PROMPT_C => "?> ",
89
- :RETURN => "=> %s\n"
90
- },
83
+ :PROMPT_I => ">> ",
84
+ :PROMPT_N => ">> ",
85
+ :PROMPT_S => nil,
86
+ :PROMPT_C => "?> ",
87
+ :RETURN => "=> %s\n"
88
+ },
91
89
  :INF_RUBY => {
92
- :PROMPT_I => "%N(%m):%03n:%i> ",
93
- # :PROMPT_N => "%N(%m):%03n:%i> ",
94
- :PROMPT_N => nil,
95
- :PROMPT_S => nil,
96
- :PROMPT_C => nil,
97
- :RETURN => "%s\n",
98
- :AUTO_INDENT => true
99
- },
90
+ :PROMPT_I => "%N(%m):%03n:%i> ",
91
+ # :PROMPT_N => "%N(%m):%03n:%i> ",
92
+ :PROMPT_N => nil,
93
+ :PROMPT_S => nil,
94
+ :PROMPT_C => nil,
95
+ :RETURN => "%s\n",
96
+ :AUTO_INDENT => true
97
+ },
100
98
  :XMP => {
101
- :PROMPT_I => nil,
102
- :PROMPT_N => nil,
103
- :PROMPT_S => nil,
104
- :PROMPT_C => nil,
105
- :RETURN => " ==>%s\n"
106
- }
99
+ :PROMPT_I => nil,
100
+ :PROMPT_N => nil,
101
+ :PROMPT_S => nil,
102
+ :PROMPT_C => nil,
103
+ :RETURN => " ==>%s\n"
104
+ }
107
105
  }
108
106
 
109
107
  @CONF[:PROMPT_MODE] = (STDIN.tty? ? :DEFAULT : :NULL)
@@ -112,10 +110,12 @@ module IRB
112
110
  @CONF[:CONTEXT_MODE] = 3 # use binding in function on TOPLEVEL_BINDING
113
111
  @CONF[:SINGLE_IRB] = false
114
112
 
115
- # @CONF[:LC_MESSAGES] = "en"
113
+ # @CONF[:LC_MESSAGES] = "en"
116
114
  @CONF[:LC_MESSAGES] = Locale.new
117
115
 
118
- @CONF[:DEBUG_LEVEL] = 1
116
+ @CONF[:AT_EXIT] = []
117
+
118
+ @CONF[:DEBUG_LEVEL] = 0
119
119
  end
120
120
 
121
121
  def IRB.init_error
@@ -130,87 +130,117 @@ module IRB
130
130
  while opt = ARGV.shift
131
131
  case opt
132
132
  when "-f"
133
- @CONF[:RC] = false
133
+ @CONF[:RC] = false
134
134
  when "-m"
135
- @CONF[:MATH_MODE] = true
135
+ @CONF[:MATH_MODE] = true
136
136
  when "-d"
137
- $DEBUG = true
137
+ $DEBUG = true
138
+ $VERBOSE = true
139
+ when "-w"
140
+ $VERBOSE = true
141
+ when /^-W(.+)?/
142
+ opt = $1 || ARGV.shift
143
+ case opt
144
+ when "0"
145
+ $VERBOSE = nil
146
+ when "1"
147
+ $VERBOSE = false
148
+ else
149
+ $VERBOSE = true
150
+ end
138
151
  when /^-r(.+)?/
139
- opt = $1 || ARGV.shift
140
- @CONF[:LOAD_MODULES].push opt if opt
152
+ opt = $1 || ARGV.shift
153
+ @CONF[:LOAD_MODULES].push opt if opt
141
154
  when /^-I(.+)?/
142
155
  opt = $1 || ARGV.shift
143
- load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
144
- when /^-K(.)/
145
- $KCODE = $1
156
+ load_path.concat(opt.split(File::PATH_SEPARATOR)) if opt
157
+ when '-U'
158
+ set_encoding("UTF-8", "UTF-8")
159
+ when /^-E(.+)?/, /^--encoding(?:=(.+))?/
160
+ opt = $1 || ARGV.shift
161
+ set_encoding(*opt.split(':', 2))
146
162
  when "--inspect"
147
- @CONF[:INSPECT_MODE] = true
163
+ if /^-/ !~ ARGV.first
164
+ @CONF[:INSPECT_MODE] = ARGV.shift
165
+ else
166
+ @CONF[:INSPECT_MODE] = true
167
+ end
148
168
  when "--noinspect"
149
- @CONF[:INSPECT_MODE] = false
169
+ @CONF[:INSPECT_MODE] = false
150
170
  when "--readline"
151
- @CONF[:USE_READLINE] = true
171
+ @CONF[:USE_READLINE] = true
152
172
  when "--noreadline"
153
- @CONF[:USE_READLINE] = false
173
+ @CONF[:USE_READLINE] = false
154
174
  when "--echo"
155
- @CONF[:ECHO] = true
175
+ @CONF[:ECHO] = true
156
176
  when "--noecho"
157
- @CONF[:ECHO] = false
177
+ @CONF[:ECHO] = false
158
178
  when "--verbose"
159
- @CONF[:VERBOSE] = true
179
+ @CONF[:VERBOSE] = true
160
180
  when "--noverbose"
161
- @CONF[:VERBOSE] = false
162
- when "--prompt-mode", "--prompt"
163
- prompt_mode = ARGV.shift.upcase.tr("-", "_").intern
164
- @CONF[:PROMPT_MODE] = prompt_mode
181
+ @CONF[:VERBOSE] = false
182
+ when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
183
+ opt = $1 || ARGV.shift
184
+ prompt_mode = opt.upcase.tr("-", "_").intern
185
+ @CONF[:PROMPT_MODE] = prompt_mode
165
186
  when "--noprompt"
166
- @CONF[:PROMPT_MODE] = :NULL
187
+ @CONF[:PROMPT_MODE] = :NULL
167
188
  when "--inf-ruby-mode"
168
- @CONF[:PROMPT_MODE] = :INF_RUBY
189
+ @CONF[:PROMPT_MODE] = :INF_RUBY
169
190
  when "--sample-book-mode", "--simple-prompt"
170
- @CONF[:PROMPT_MODE] = :SIMPLE
191
+ @CONF[:PROMPT_MODE] = :SIMPLE
171
192
  when "--tracer"
172
- @CONF[:USE_TRACER] = true
173
- when "--back-trace-limit"
174
- @CONF[:BACK_TRACE_LIMIT] = ARGV.shift.to_i
175
- when "--context-mode"
176
- @CONF[:CONTEXT_MODE] = ARGV.shift.to_i
193
+ @CONF[:USE_TRACER] = true
194
+ when /^--back-trace-limit(?:=(.+))?/
195
+ @CONF[:BACK_TRACE_LIMIT] = ($1 || ARGV.shift).to_i
196
+ when /^--context-mode(?:=(.+))?/
197
+ @CONF[:CONTEXT_MODE] = ($1 || ARGV.shift).to_i
177
198
  when "--single-irb"
178
- @CONF[:SINGLE_IRB] = true
179
- when "--irb_debug"
180
- @CONF[:DEBUG_LEVEL] = ARGV.shift.to_i
199
+ @CONF[:SINGLE_IRB] = true
200
+ when /^--irb_debug(?:=(.+))?/
201
+ @CONF[:DEBUG_LEVEL] = ($1 || ARGV.shift).to_i
181
202
  when "-v", "--version"
182
- print IRB.version, "\n"
183
- exit 0
203
+ print IRB.version, "\n"
204
+ exit 0
184
205
  when "-h", "--help"
185
- require "irb/help"
186
- IRB.print_usage
187
- exit 0
206
+ require "irb/help"
207
+ IRB.print_usage
208
+ exit 0
209
+ when "--"
210
+ if opt = ARGV.shift
211
+ @CONF[:SCRIPT] = opt
212
+ $0 = opt
213
+ end
214
+ break
188
215
  when /^-/
189
- IRB.fail UnrecognizedSwitch, opt
216
+ IRB.fail UnrecognizedSwitch, opt
190
217
  else
191
- @CONF[:SCRIPT] = opt
192
- $0 = opt
193
- break
218
+ @CONF[:SCRIPT] = opt
219
+ $0 = opt
220
+ break
194
221
  end
195
222
  end
196
-
197
223
  if RUBY_VERSION >= FEATURE_IOPT_CHANGE_VERSION
198
224
  load_path.collect! do |path|
199
- /\A\.\// =~ path ? path : File.expand_path(path)
225
+ /\A\.\// =~ path ? path : File.expand_path(path)
200
226
  end
201
227
  end
202
228
  $LOAD_PATH.unshift(*load_path)
229
+
203
230
  end
204
231
 
205
232
  # running config
206
233
  def IRB.run_config
207
234
  if @CONF[:RC]
208
235
  begin
209
- load rc_file
236
+ load rc_file
210
237
  rescue LoadError, Errno::ENOENT
211
- rescue => e
212
- print "load error: #{rc_file}\n"
213
- raise e
238
+ rescue # StandardError, ScriptError
239
+ print "load error: #{rc_file}\n"
240
+ print $!.class, ": ", $!, "\n"
241
+ for err in $@[0, $@.size - 2]
242
+ print "\t", err, "\n"
243
+ end
214
244
  end
215
245
  end
216
246
  end
@@ -219,23 +249,28 @@ module IRB
219
249
  def IRB.rc_file(ext = IRBRC_EXT)
220
250
  if !@CONF[:RC_NAME_GENERATOR]
221
251
  rc_file_generators do |rcgen|
222
- @CONF[:RC_NAME_GENERATOR] ||= rcgen
223
- if File.exist?(rcgen.call(IRBRC_EXT))
224
- @CONF[:RC_NAME_GENERATOR] = rcgen
225
- break
226
- end
252
+ @CONF[:RC_NAME_GENERATOR] ||= rcgen
253
+ if File.exist?(rcgen.call(IRBRC_EXT))
254
+ @CONF[:RC_NAME_GENERATOR] = rcgen
255
+ break
256
+ end
227
257
  end
228
258
  end
229
- @CONF[:RC_NAME_GENERATOR].call ext
259
+ case rc_file = @CONF[:RC_NAME_GENERATOR].call(ext)
260
+ when String
261
+ return rc_file
262
+ else
263
+ IRB.fail IllegalRCNameGenerator
264
+ end
230
265
  end
231
266
 
232
267
  # enumerate possible rc-file base name generators
233
268
  def IRB.rc_file_generators
234
269
  if irbrc = ENV["IRBRC"]
235
- yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
270
+ yield proc{|rc| rc == "rc" ? irbrc : irbrc+rc}
236
271
  end
237
272
  if home = ENV["HOME"]
238
- yield proc{|rc| home+"/.irb#{rc}"}
273
+ yield proc{|rc| home+"/.irb#{rc}"}
239
274
  end
240
275
  home = Dir.pwd
241
276
  yield proc{|rc| home+"/.irb#{rc}"}
@@ -248,11 +283,28 @@ module IRB
248
283
  def IRB.load_modules
249
284
  for m in @CONF[:LOAD_MODULES]
250
285
  begin
251
- require m
252
- rescue
253
- print $@[0], ":", $!.class, ": ", $!, "\n"
286
+ require m
287
+ rescue LoadError => err
288
+ warn err.backtrace[0] << ":#{err.class}: #{err}"
254
289
  end
255
290
  end
256
291
  end
257
292
 
293
+
294
+ DefaultEncodings = Struct.new(:external, :internal)
295
+ class << IRB
296
+ private
297
+ def set_encoding(extern, intern = nil)
298
+ verbose, $VERBOSE = $VERBOSE, nil
299
+ Encoding.default_external = extern unless extern.nil? || extern.empty?
300
+ Encoding.default_internal = intern unless intern.nil? || intern.empty?
301
+ @CONF[:ENCODINGS] = IRB::DefaultEncodings.new(extern, intern)
302
+ [$stdin, $stdout, $stderr].each do |io|
303
+ io.set_encoding(extern, intern)
304
+ end
305
+ @CONF[:LC_MESSAGES].instance_variable_set(:@encoding, extern)
306
+ ensure
307
+ $VERBOSE = verbose
308
+ end
309
+ end
258
310
  end
@@ -1,101 +1,156 @@
1
1
  #
2
2
  # irb/input-method.rb - input methods used irb
3
- # $Release Version: 0.9.5$
4
- # $Revision: 11708 $
5
- # $Date: 2007-02-12 15:01:19 -0800 (Mon, 12 Feb 2007) $
3
+ # $Release Version: 0.9.6$
4
+ # $Revision$
6
5
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
7
6
  #
8
7
  # --
9
8
  #
10
- #
11
9
  #
10
+ #
11
+ require 'irb/src_encoding'
12
+ require 'irb/magic-file'
13
+
12
14
  module IRB
13
- #
14
- # InputMethod
15
- # StdioInputMethod
16
- # FileInputMethod
17
- # (ReadlineInputMethod)
18
- #
19
- STDIN_FILE_NAME = "(line)"
15
+ STDIN_FILE_NAME = "(line)" # :nodoc:
20
16
  class InputMethod
21
- @RCS_ID='-$Id: input-method.rb 11708 2007-02-12 23:01:19Z shyouhei $-'
17
+ @RCS_ID='-$Id$-'
22
18
 
19
+ # Creates a new input method object
23
20
  def initialize(file = STDIN_FILE_NAME)
24
21
  @file_name = file
25
22
  end
23
+ # The file name of this input method, usually given during initialization.
26
24
  attr_reader :file_name
27
25
 
26
+ # The irb prompt associated with this input method
28
27
  attr_accessor :prompt
29
-
28
+
29
+ # Reads the next line from this input method.
30
+ #
31
+ # See IO#gets for more information.
30
32
  def gets
31
33
  IRB.fail NotImplementedError, "gets"
32
34
  end
33
35
  public :gets
34
36
 
35
- def readable_atfer_eof?
37
+ # Whether this input method is still readable when there is no more data to
38
+ # read.
39
+ #
40
+ # See IO#eof for more information.
41
+ def readable_after_eof?
36
42
  false
37
43
  end
38
44
  end
39
-
45
+
40
46
  class StdioInputMethod < InputMethod
47
+ # Creates a new input method object
41
48
  def initialize
42
49
  super
43
50
  @line_no = 0
44
51
  @line = []
52
+ @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
53
+ @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
45
54
  end
46
55
 
56
+ # Reads the next line from this input method.
57
+ #
58
+ # See IO#gets for more information.
47
59
  def gets
48
60
  print @prompt
49
- @line[@line_no += 1] = $stdin.gets
61
+ line = @stdin.gets
62
+ @line[@line_no += 1] = line
50
63
  end
51
64
 
65
+ # Whether the end of this input method has been reached, returns +true+ if
66
+ # there is no more data to read.
67
+ #
68
+ # See IO#eof? for more information.
52
69
  def eof?
53
- $stdin.eof?
70
+ @stdin.eof?
54
71
  end
55
72
 
56
- def readable_atfer_eof?
73
+ # Whether this input method is still readable when there is no more data to
74
+ # read.
75
+ #
76
+ # See IO#eof for more information.
77
+ def readable_after_eof?
57
78
  true
58
79
  end
59
80
 
81
+ # Returns the current line number for #io.
82
+ #
83
+ # #line counts the number of times #gets is called.
84
+ #
85
+ # See IO#lineno for more information.
60
86
  def line(line_no)
61
87
  @line[line_no]
62
88
  end
89
+
90
+ # The external encoding for standard input.
91
+ def encoding
92
+ @stdin.external_encoding
93
+ end
63
94
  end
64
-
95
+
96
+ # Use a File for IO with irb, see InputMethod
65
97
  class FileInputMethod < InputMethod
98
+ # Creates a new input method object
66
99
  def initialize(file)
67
100
  super
68
- @io = open(file)
101
+ @io = IRB::MagicFile.open(file)
69
102
  end
103
+ # The file name of this input method, usually given during initialization.
70
104
  attr_reader :file_name
71
105
 
106
+ # Whether the end of this input method has been reached, returns +true+ if
107
+ # there is no more data to read.
108
+ #
109
+ # See IO#eof? for more information.
72
110
  def eof?
73
111
  @io.eof?
74
112
  end
75
113
 
114
+ # Reads the next line from this input method.
115
+ #
116
+ # See IO#gets for more information.
76
117
  def gets
77
118
  print @prompt
78
119
  l = @io.gets
79
120
  # print @prompt, l
80
121
  l
81
122
  end
123
+
124
+ # The external encoding for standard input.
125
+ def encoding
126
+ @io.external_encoding
127
+ end
82
128
  end
83
129
 
84
130
  begin
85
131
  require "readline"
86
132
  class ReadlineInputMethod < InputMethod
87
- include Readline
133
+ include Readline
134
+ # Creates a new input method object using Readline
88
135
  def initialize
89
136
  super
90
137
 
91
138
  @line_no = 0
92
139
  @line = []
93
140
  @eof = false
141
+
142
+ @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
143
+ @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
94
144
  end
95
145
 
146
+ # Reads the next line from this input method.
147
+ #
148
+ # See IO#gets for more information.
96
149
  def gets
150
+ Readline.input = @stdin
151
+ Readline.output = @stdout
97
152
  if l = readline(@prompt, false)
98
- HISTORY.push(l) if !l.empty?
153
+ HISTORY.push(l) if !l.empty?
99
154
  @line[@line_no += 1] = l + "\n"
100
155
  else
101
156
  @eof = true
@@ -103,17 +158,35 @@ module IRB
103
158
  end
104
159
  end
105
160
 
161
+ # Whether the end of this input method has been reached, returns +true+
162
+ # if there is no more data to read.
163
+ #
164
+ # See IO#eof? for more information.
106
165
  def eof?
107
166
  @eof
108
167
  end
109
168
 
110
- def readable_atfer_eof?
169
+ # Whether this input method is still readable when there is no more data to
170
+ # read.
171
+ #
172
+ # See IO#eof for more information.
173
+ def readable_after_eof?
111
174
  true
112
175
  end
113
176
 
177
+ # Returns the current line number for #io.
178
+ #
179
+ # #line counts the number of times #gets is called.
180
+ #
181
+ # See IO#lineno for more information.
114
182
  def line(line_no)
115
183
  @line[line_no]
116
184
  end
185
+
186
+ # The external encoding for standard input.
187
+ def encoding
188
+ @stdin.external_encoding
189
+ end
117
190
  end
118
191
  rescue LoadError
119
192
  end