irb 1.1.0 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,7 +8,6 @@
8
8
  #
9
9
 
10
10
  require "readline"
11
- autoload :RDoc, "rdoc"
12
11
 
13
12
  module IRB
14
13
  module InputCompletor # :nodoc:
@@ -36,13 +35,7 @@ module IRB
36
35
  yield
37
36
  ]
38
37
 
39
- BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
40
-
41
38
  CompletionProc = proc { |input|
42
- retrieve_completion_data(input).compact.map{ |i| i.encode(Encoding.default_external) }
43
- }
44
-
45
- def self.retrieve_completion_data(input, doc_namespace = false)
46
39
  bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
47
40
 
48
41
  case input
@@ -52,11 +45,7 @@ module IRB
52
45
  message = Regexp.quote($3)
53
46
 
54
47
  candidates = String.instance_methods.collect{|m| m.to_s}
55
- if doc_namespace
56
- "String.#{message}"
57
- else
58
- select_message(receiver, message, candidates)
59
- end
48
+ select_message(receiver, message, candidates)
60
49
 
61
50
  when /^(\/[^\/]*\/)\.([^.]*)$/
62
51
  # Regexp
@@ -64,11 +53,7 @@ module IRB
64
53
  message = Regexp.quote($2)
65
54
 
66
55
  candidates = Regexp.instance_methods.collect{|m| m.to_s}
67
- if doc_namespace
68
- "Regexp.#{message}"
69
- else
70
- select_message(receiver, message, candidates)
71
- end
56
+ select_message(receiver, message, candidates)
72
57
 
73
58
  when /^([^\]]*\])\.([^.]*)$/
74
59
  # Array
@@ -76,28 +61,19 @@ module IRB
76
61
  message = Regexp.quote($2)
77
62
 
78
63
  candidates = Array.instance_methods.collect{|m| m.to_s}
79
- if doc_namespace
80
- "Array.#{message}"
81
- else
82
- select_message(receiver, message, candidates)
83
- end
64
+ select_message(receiver, message, candidates)
84
65
 
85
66
  when /^([^\}]*\})\.([^.]*)$/
86
67
  # Proc or Hash
87
68
  receiver = $1
88
69
  message = Regexp.quote($2)
89
70
 
90
- proc_candidates = Proc.instance_methods.collect{|m| m.to_s}
91
- hash_candidates = Hash.instance_methods.collect{|m| m.to_s}
92
- if doc_namespace
93
- ["Proc.#{message}", "Hash.#{message}"]
94
- else
95
- select_message(receiver, message, proc_candidates | hash_candidates)
96
- end
71
+ candidates = Proc.instance_methods.collect{|m| m.to_s}
72
+ candidates |= Hash.instance_methods.collect{|m| m.to_s}
73
+ select_message(receiver, message, candidates)
97
74
 
98
75
  when /^(:[^:.]*)$/
99
76
  # Symbol
100
- return nil if doc_namespace
101
77
  if Symbol.respond_to?(:all_symbols)
102
78
  sym = $1
103
79
  candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
@@ -110,11 +86,7 @@ module IRB
110
86
  # Absolute Constant or class methods
111
87
  receiver = $1
112
88
  candidates = Object.constants.collect{|m| m.to_s}
113
- if doc_namespace
114
- candidates.find { |i| i == receiver }
115
- else
116
- candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
117
- end
89
+ candidates.grep(/^#{receiver}/).collect{|e| "::" + e}
118
90
 
119
91
  when /^([A-Z].*)::([^:.]*)$/
120
92
  # Constant or class methods
@@ -126,11 +98,7 @@ module IRB
126
98
  rescue Exception
127
99
  candidates = []
128
100
  end
129
- if doc_namespace
130
- "#{receiver}::#{message}"
131
- else
132
- select_message(receiver, message, candidates, "::")
133
- end
101
+ select_message(receiver, message, candidates, "::")
134
102
 
135
103
  when /^(:[^:.]+)(\.|::)([^.]*)$/
136
104
  # Symbol
@@ -139,33 +107,20 @@ module IRB
139
107
  message = Regexp.quote($3)
140
108
 
141
109
  candidates = Symbol.instance_methods.collect{|m| m.to_s}
142
- if doc_namespace
143
- "Symbol.#{message}"
144
- else
145
- select_message(receiver, message, candidates, sep)
146
- end
110
+ select_message(receiver, message, candidates, sep)
147
111
 
148
- when /^(?<num>-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE][+-]?[0-9]+i?|r)?)(?<sep>\.|::)(?<mes>[^.]*)$/
112
+ when /^(-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)(\.|::)([^.]*)$/
149
113
  # Numeric
150
- receiver = $~[:num]
151
- sep = $~[:sep]
152
- message = Regexp.quote($~[:mes])
114
+ receiver = $1
115
+ sep = $5
116
+ message = Regexp.quote($6)
153
117
 
154
118
  begin
155
- instance = eval(receiver, bind)
156
- if doc_namespace
157
- "#{instance.class.name}.#{message}"
158
- else
159
- candidates = instance.methods.collect{|m| m.to_s}
160
- select_message(receiver, message, candidates, sep)
161
- end
119
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
162
120
  rescue Exception
163
- if doc_namespace
164
- nil
165
- else
166
- candidates = []
167
- end
121
+ candidates = []
168
122
  end
123
+ select_message(receiver, message, candidates, sep)
169
124
 
170
125
  when /^(-?0x[0-9a-fA-F_]+)(\.|::)([^.]*)$/
171
126
  # Numeric(0xFFFF)
@@ -174,30 +129,16 @@ module IRB
174
129
  message = Regexp.quote($3)
175
130
 
176
131
  begin
177
- instance = eval(receiver, bind)
178
- if doc_namespace
179
- "#{instance.class.name}.#{message}"
180
- else
181
- candidates = instance.methods.collect{|m| m.to_s}
182
- select_message(receiver, message, candidates, sep)
183
- end
132
+ candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
184
133
  rescue Exception
185
- if doc_namespace
186
- nil
187
- else
188
- candidates = []
189
- end
134
+ candidates = []
190
135
  end
136
+ select_message(receiver, message, candidates, sep)
191
137
 
192
138
  when /^(\$[^.]*)$/
193
139
  # global var
194
- gvar = $1
195
- all_gvars = global_variables.collect{|m| m.to_s}
196
- if doc_namespace
197
- all_gvars.find{ |i| i == gvar }
198
- else
199
- all_gvars.grep(Regexp.new(Regexp.quote(gvar)))
200
- end
140
+ regmessage = Regexp.new(Regexp.quote($1))
141
+ candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
201
142
 
202
143
  when /^([^."].*)(\.|::)([^.]*)$/
203
144
  # variable.func or func.func
@@ -205,7 +146,7 @@ module IRB
205
146
  sep = $2
206
147
  message = Regexp.quote($3)
207
148
 
208
- gv = eval("global_variables", bind).collect{|m| m.to_s}.append("true", "false", "nil")
149
+ gv = eval("global_variables", bind).collect{|m| m.to_s}
209
150
  lv = eval("local_variables", bind).collect{|m| m.to_s}
210
151
  iv = eval("instance_variables", bind).collect{|m| m.to_s}
211
152
  cv = eval("self.class.constants", bind).collect{|m| m.to_s}
@@ -236,11 +177,7 @@ module IRB
236
177
  candidates.sort!
237
178
  candidates.uniq!
238
179
  end
239
- if doc_namespace
240
- "#{rec.class.name}#{sep}#{candidates.find{ |i| i == message }}"
241
- else
242
- select_message(receiver, message, candidates, sep)
243
- end
180
+ select_message(receiver, message, candidates, sep)
244
181
 
245
182
  when /^\.([^.]*)$/
246
183
  # unknown(maybe String)
@@ -249,50 +186,12 @@ module IRB
249
186
  message = Regexp.quote($1)
250
187
 
251
188
  candidates = String.instance_methods(true).collect{|m| m.to_s}
252
- if doc_namespace
253
- "String.#{candidates.find{ |i| i == message }}"
254
- else
255
- select_message(receiver, message, candidates)
256
- end
189
+ select_message(receiver, message, candidates)
257
190
 
258
191
  else
259
192
  candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
260
- conditions |= ReservedWords
261
-
262
- if doc_namespace
263
- candidates.find{ |i| i == input }
264
- else
265
- candidates.grep(/^#{Regexp.quote(input)}/)
266
- end
267
- end
268
- end
269
193
 
270
- PerfectMatchedProc = ->(matched) {
271
- RDocRIDriver ||= RDoc::RI::Driver.new
272
- if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
273
- File.open(File.join(__dir__, 'ruby_logo.aa')) do |f|
274
- RDocRIDriver.page do |io|
275
- IO.copy_stream(f, io)
276
- end
277
- end
278
- return
279
- end
280
- namespace = retrieve_completion_data(matched, true)
281
- return unless matched
282
- if namespace.is_a?(Array)
283
- out = RDoc::Markup::Document.new
284
- namespace.each do |m|
285
- begin
286
- RDocRIDriver.add_method(out, m)
287
- rescue RDoc::RI::Driver::NotFoundError
288
- end
289
- end
290
- RDocRIDriver.display(out)
291
- else
292
- begin
293
- RDocRIDriver.display_names([namespace])
294
- rescue RDoc::RI::Driver::NotFoundError
295
- end
194
+ (candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
296
195
  end
297
196
  }
298
197
 
@@ -337,3 +236,9 @@ module IRB
337
236
  end
338
237
  end
339
238
  end
239
+
240
+ if Readline.respond_to?("basic_word_break_characters=")
241
+ Readline.basic_word_break_characters= " \t\n`><=;|&{("
242
+ end
243
+ Readline.completion_append_character = nil
244
+ Readline.completion_proc = IRB::InputCompletor::CompletionProc
@@ -22,10 +22,10 @@ module IRB
22
22
  #
23
23
  # The optional +input_method+ argument:
24
24
  #
25
- # +nil+:: uses stdin or Reidline or Readline
25
+ # +nil+:: uses stdin or Readline
26
26
  # +String+:: uses a File
27
27
  # +other+:: uses this as InputMethod
28
- def initialize(irb, workspace = nil, input_method = nil)
28
+ def initialize(irb, workspace = nil, input_method = nil, output_method = nil)
29
29
  @irb = irb
30
30
  if workspace
31
31
  @workspace = workspace
@@ -39,21 +39,7 @@ module IRB
39
39
  @rc = IRB.conf[:RC]
40
40
  @load_modules = IRB.conf[:LOAD_MODULES]
41
41
 
42
- if IRB.conf.has_key?(:USE_SINGLELINE)
43
- @use_singleline = IRB.conf[:USE_SINGLELINE]
44
- elsif IRB.conf.has_key?(:USE_READLINE) # backward compatibility
45
- @use_singleline = IRB.conf[:USE_READLINE]
46
- else
47
- @use_singleline = nil
48
- end
49
- if IRB.conf.has_key?(:USE_MULTILINE)
50
- @use_multiline = IRB.conf[:USE_MULTILINE]
51
- elsif IRB.conf.has_key?(:USE_REIDLINE) # backward compatibility
52
- @use_multiline = IRB.conf[:USE_REIDLINE]
53
- else
54
- @use_multiline = nil
55
- end
56
- @use_colorize = IRB.conf[:USE_COLORIZE]
42
+ @use_readline = IRB.conf[:USE_READLINE]
57
43
  @verbose = IRB.conf[:VERBOSE]
58
44
  @io = nil
59
45
 
@@ -78,47 +64,23 @@ module IRB
78
64
 
79
65
  case input_method
80
66
  when nil
81
- @io = nil
82
- case use_multiline?
67
+ case use_readline?
83
68
  when nil
84
- if STDIN.tty? && IRB.conf[:PROMPT_MODE] != :INF_RUBY && !use_singleline?
85
- # Both of multiline mode and singleline mode aren't specified.
86
- puts <<~EOM
87
- This version of IRB is drastically different from the previous version.
88
- If you hit any issues, you can use "irb --legacy" to run the old version.
89
- If you want to just erase this message, please use "irb --multiline".
90
- EOM
91
- @io = ReidlineInputMethod.new
69
+ if (defined?(ReadlineInputMethod) && STDIN.tty? &&
70
+ IRB.conf[:PROMPT_MODE] != :INF_RUBY)
71
+ @io = ReadlineInputMethod.new
92
72
  else
93
- @io = nil
73
+ @io = StdioInputMethod.new
94
74
  end
95
75
  when false
96
- @io = nil
76
+ @io = StdioInputMethod.new
97
77
  when true
98
- @io = ReidlineInputMethod.new
99
- end
100
- unless @io
101
- case use_singleline?
102
- when nil
103
- if (defined?(ReadlineInputMethod) && STDIN.tty? &&
104
- IRB.conf[:PROMPT_MODE] != :INF_RUBY)
105
- @io = ReadlineInputMethod.new
106
- else
107
- @io = nil
108
- end
109
- when false
110
- @io = nil
111
- when true
112
- if defined?(ReadlineInputMethod)
113
- @io = ReadlineInputMethod.new
114
- else
115
- @io = nil
116
- end
78
+ if defined?(ReadlineInputMethod)
79
+ @io = ReadlineInputMethod.new
117
80
  else
118
- @io = nil
81
+ @io = StdioInputMethod.new
119
82
  end
120
83
  end
121
- @io = StdioInputMethod.new unless @io
122
84
 
123
85
  when String
124
86
  @io = FileInputMethod.new(input_method)
@@ -129,15 +91,17 @@ module IRB
129
91
  end
130
92
  self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
131
93
 
94
+ if output_method
95
+ @output_method = output_method
96
+ else
97
+ @output_method = StdioOutputMethod.new
98
+ end
99
+
132
100
  @echo = IRB.conf[:ECHO]
133
101
  if @echo.nil?
134
102
  @echo = true
135
103
  end
136
-
137
- @echo_on_assignment = IRB.conf[:ECHO_ON_ASSIGNMENT]
138
- if @echo_on_assignment.nil?
139
- @echo_on_assignment = false
140
- end
104
+ self.debug_level = IRB.conf[:DEBUG_LEVEL]
141
105
  end
142
106
 
143
107
  # The top-level workspace, see WorkSpace#main
@@ -153,9 +117,9 @@ module IRB
153
117
  attr_reader :thread
154
118
  # The current input method
155
119
  #
156
- # Can be either StdioInputMethod, ReadlineInputMethod,
157
- # ReidlineInputMethod, FileInputMethod or other specified when the
158
- # context is created. See ::new for more # information on +input_method+.
120
+ # Can be either StdioInputMethod, ReadlineInputMethod, FileInputMethod or
121
+ # other specified when the context is created. See ::new for more
122
+ # information on +input_method+.
159
123
  attr_accessor :io
160
124
 
161
125
  # Current irb session
@@ -173,18 +137,12 @@ module IRB
173
137
  # +input_method+ passed to Context.new
174
138
  attr_accessor :irb_path
175
139
 
176
- # Whether multiline editor mode is enabled or not.
177
- #
178
- # A copy of the default <code>IRB.conf[:USE_MULTILINE]</code>
179
- attr_reader :use_multiline
180
- # Whether singleline editor mode is enabled or not.
140
+ # Whether +Readline+ is enabled or not.
181
141
  #
182
- # A copy of the default <code>IRB.conf[:USE_SINGLELINE]</code>
183
- attr_reader :use_singleline
184
- # Whether colorization is enabled or not.
142
+ # A copy of the default <code>IRB.conf[:USE_READLINE]</code>
185
143
  #
186
- # A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
187
- attr_reader :use_colorize
144
+ # See #use_readline= for more information.
145
+ attr_reader :use_readline
188
146
  # A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
189
147
  attr_reader :inspect_mode
190
148
 
@@ -207,17 +165,17 @@ module IRB
207
165
  # Can be either the default <code>IRB.conf[:AUTO_INDENT]</code>, or the
208
166
  # mode set by #prompt_mode=
209
167
  #
210
- # To disable auto-indentation in irb:
168
+ # To enable auto-indentation in irb:
211
169
  #
212
- # IRB.conf[:AUTO_INDENT] = false
170
+ # IRB.conf[:AUTO_INDENT] = true
213
171
  #
214
172
  # or
215
173
  #
216
- # irb_context.auto_indent_mode = false
174
+ # irb_context.auto_indent_mode = true
217
175
  #
218
176
  # or
219
177
  #
220
- # IRB.CurrentContext.auto_indent_mode = false
178
+ # IRB.CurrentContext.auto_indent_mode = true
221
179
  #
222
180
  # See IRB@Configuration for more information.
223
181
  attr_accessor :auto_indent_mode
@@ -249,19 +207,14 @@ module IRB
249
207
  # puts "omg"
250
208
  # # omg
251
209
  attr_accessor :echo
252
- # Whether to echo for assignment expressions
253
- #
254
- # Uses IRB.conf[:ECHO_ON_ASSIGNMENT] if available, or defaults to +false+.
255
- #
256
- # a = "omg"
257
- # IRB.CurrentContext.echo_on_assignment = true
258
- # a = "omg"
259
- # #=> omg
260
- attr_accessor :echo_on_assignment
261
210
  # Whether verbose messages are displayed or not.
262
211
  #
263
212
  # A copy of the default <code>IRB.conf[:VERBOSE]</code>
264
213
  attr_accessor :verbose
214
+ # The debug level of irb
215
+ #
216
+ # See #debug_level= for more information.
217
+ attr_reader :debug_level
265
218
 
266
219
  # The limit of backtrace lines displayed as top +n+ and tail +n+.
267
220
  #
@@ -272,33 +225,18 @@ module IRB
272
225
  # See IRB@Command+line+options for more command line options.
273
226
  attr_accessor :back_trace_limit
274
227
 
275
- # Alias for #use_multiline
276
- alias use_multiline? use_multiline
277
- # Alias for #use_singleline
278
- alias use_singleline? use_singleline
279
- # backward compatibility
280
- alias use_reidline use_multiline
281
- # backward compatibility
282
- alias use_reidline? use_multiline
283
- # backward compatibility
284
- alias use_readline use_singleline
285
- # backward compatibility
286
- alias use_readline? use_singleline
287
- # Alias for #use_colorize
288
- alias use_colorize? use_colorize
228
+ # Alias for #use_readline
229
+ alias use_readline? use_readline
289
230
  # Alias for #rc
290
231
  alias rc? rc
291
232
  alias ignore_sigint? ignore_sigint
292
233
  alias ignore_eof? ignore_eof
293
234
  alias echo? echo
294
- alias echo_on_assignment? echo_on_assignment
295
235
 
296
236
  # Returns whether messages are displayed or not.
297
237
  def verbose?
298
238
  if @verbose.nil?
299
- if @io.kind_of?(ReidlineInputMethod)
300
- false
301
- elsif defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
239
+ if defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)
302
240
  false
303
241
  elsif !STDIN.tty? or @io.kind_of?(FileInputMethod)
304
242
  true
@@ -311,11 +249,9 @@ module IRB
311
249
  end
312
250
 
313
251
  # Whether #verbose? is +true+, and +input_method+ is either
314
- # StdioInputMethod or ReidlineInputMethod or ReadlineInputMethod, see #io
315
- # for more information.
252
+ # StdioInputMethod or ReadlineInputMethod, see #io for more information.
316
253
  def prompting?
317
254
  verbose? || (STDIN.tty? && @io.kind_of?(StdioInputMethod) ||
318
- @io.kind_of?(ReidlineInputMethod) ||
319
255
  (defined?(ReadlineInputMethod) && @io.kind_of?(ReadlineInputMethod)))
320
256
  end
321
257
 
@@ -414,11 +350,36 @@ module IRB
414
350
  @inspect_mode
415
351
  end
416
352
 
353
+ # Obsolete method.
354
+ #
355
+ # Can be set using the +--noreadline+ and +--readline+ command line
356
+ # options.
357
+ #
358
+ # See IRB@Command+line+options for more command line options.
359
+ def use_readline=(opt)
360
+ print "This method is obsolete."
361
+ print "Do nothing."
362
+ end
363
+
364
+ # Sets the debug level of irb
365
+ #
366
+ # Can also be set using the +--irb_debug+ command line option.
367
+ #
368
+ # See IRB@Command+line+options for more command line options.
369
+ def debug_level=(value)
370
+ @debug_level = value
371
+ RubyLex.debug_level = value
372
+ end
373
+
374
+ # Whether or not debug mode is enabled, see #debug_level=.
375
+ def debug?
376
+ @debug_level > 0
377
+ end
378
+
417
379
  def evaluate(line, line_no, exception: nil) # :nodoc:
418
380
  @line_no = line_no
419
381
  if exception
420
- line_no -= 1
421
- line = "begin ::Kernel.raise _; rescue _.class\n#{line}\n""end"
382
+ line = "begin ::Kernel.raise _; rescue _.class; #{line}; end"
422
383
  @workspace.local_variable_set(:_, exception)
423
384
  end
424
385
  set_last_value(@workspace.evaluate(self, line, irb_path, line_no))