irb 1.7.1 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.document +1 -1
  3. data/Gemfile +10 -1
  4. data/README.md +265 -20
  5. data/Rakefile +13 -10
  6. data/doc/irb/irb.rd.ja +1 -3
  7. data/irb.gemspec +2 -1
  8. data/lib/irb/cmd/nop.rb +3 -52
  9. data/lib/irb/color.rb +4 -2
  10. data/lib/irb/command/backtrace.rb +17 -0
  11. data/lib/irb/command/base.rb +62 -0
  12. data/lib/irb/command/break.rb +17 -0
  13. data/lib/irb/command/catch.rb +17 -0
  14. data/lib/irb/command/chws.rb +40 -0
  15. data/lib/irb/command/context.rb +16 -0
  16. data/lib/irb/{cmd → command}/continue.rb +3 -3
  17. data/lib/irb/command/debug.rb +71 -0
  18. data/lib/irb/{cmd → command}/delete.rb +3 -3
  19. data/lib/irb/command/disable_irb.rb +19 -0
  20. data/lib/irb/command/edit.rb +63 -0
  21. data/lib/irb/command/exit.rb +18 -0
  22. data/lib/irb/{cmd → command}/finish.rb +3 -3
  23. data/lib/irb/command/force_exit.rb +18 -0
  24. data/lib/irb/command/help.rb +83 -0
  25. data/lib/irb/command/history.rb +45 -0
  26. data/lib/irb/command/info.rb +17 -0
  27. data/lib/irb/command/internal_helpers.rb +27 -0
  28. data/lib/irb/{cmd → command}/irb_info.rb +7 -7
  29. data/lib/irb/{cmd → command}/load.rb +23 -8
  30. data/lib/irb/{cmd → command}/ls.rb +42 -19
  31. data/lib/irb/{cmd → command}/measure.rb +18 -17
  32. data/lib/irb/{cmd → command}/next.rb +3 -3
  33. data/lib/irb/command/pushws.rb +65 -0
  34. data/lib/irb/command/show_doc.rb +51 -0
  35. data/lib/irb/command/show_source.rb +74 -0
  36. data/lib/irb/{cmd → command}/step.rb +3 -3
  37. data/lib/irb/command/subirb.rb +123 -0
  38. data/lib/irb/{cmd → command}/whereami.rb +3 -5
  39. data/lib/irb/command.rb +23 -0
  40. data/lib/irb/completion.rb +133 -102
  41. data/lib/irb/context.rb +182 -66
  42. data/lib/irb/debug/ui.rb +103 -0
  43. data/lib/irb/{cmd/debug.rb → debug.rb} +53 -59
  44. data/lib/irb/default_commands.rb +265 -0
  45. data/lib/irb/easter-egg.rb +16 -6
  46. data/lib/irb/ext/change-ws.rb +6 -8
  47. data/lib/irb/ext/{history.rb → eval_history.rb} +7 -7
  48. data/lib/irb/ext/loader.rb +4 -4
  49. data/lib/irb/ext/multi-irb.rb +5 -5
  50. data/lib/irb/ext/tracer.rb +12 -51
  51. data/lib/irb/ext/use-loader.rb +6 -8
  52. data/lib/irb/ext/workspaces.rb +10 -34
  53. data/lib/irb/frame.rb +1 -1
  54. data/lib/irb/help.rb +3 -3
  55. data/lib/irb/helper_method/base.rb +16 -0
  56. data/lib/irb/helper_method/conf.rb +11 -0
  57. data/lib/irb/helper_method.rb +29 -0
  58. data/lib/irb/{ext/save-history.rb → history.rb} +20 -58
  59. data/lib/irb/init.rb +154 -58
  60. data/lib/irb/input-method.rb +238 -203
  61. data/lib/irb/inspector.rb +3 -3
  62. data/lib/irb/lc/error.rb +1 -11
  63. data/lib/irb/lc/help-message +4 -0
  64. data/lib/irb/lc/ja/error.rb +1 -11
  65. data/lib/irb/lc/ja/help-message +13 -0
  66. data/lib/irb/locale.rb +2 -2
  67. data/lib/irb/nesting_parser.rb +13 -3
  68. data/lib/irb/notifier.rb +1 -1
  69. data/lib/irb/output-method.rb +2 -8
  70. data/lib/irb/pager.rb +91 -0
  71. data/lib/irb/ruby-lex.rb +391 -471
  72. data/lib/irb/ruby_logo.aa +43 -0
  73. data/lib/irb/source_finder.rb +139 -0
  74. data/lib/irb/statement.rb +80 -0
  75. data/lib/irb/version.rb +3 -3
  76. data/lib/irb/workspace.rb +24 -4
  77. data/lib/irb/ws-for-case-2.rb +1 -1
  78. data/lib/irb/xmp.rb +3 -3
  79. data/lib/irb.rb +1232 -604
  80. data/man/irb.1 +7 -0
  81. metadata +60 -32
  82. data/lib/irb/cmd/backtrace.rb +0 -21
  83. data/lib/irb/cmd/break.rb +0 -21
  84. data/lib/irb/cmd/catch.rb +0 -21
  85. data/lib/irb/cmd/chws.rb +0 -36
  86. data/lib/irb/cmd/edit.rb +0 -61
  87. data/lib/irb/cmd/help.rb +0 -23
  88. data/lib/irb/cmd/info.rb +0 -21
  89. data/lib/irb/cmd/pushws.rb +0 -45
  90. data/lib/irb/cmd/show_cmds.rb +0 -39
  91. data/lib/irb/cmd/show_doc.rb +0 -48
  92. data/lib/irb/cmd/show_source.rb +0 -113
  93. data/lib/irb/cmd/subirb.rb +0 -66
  94. data/lib/irb/extend-command.rb +0 -356
  95. data/lib/irb/src_encoding.rb +0 -7
@@ -1,24 +1,17 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/input-method.rb - input methods used irb
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
5
  #
6
6
 
7
- require_relative 'src_encoding'
8
7
  require_relative 'completion'
8
+ require_relative "history"
9
9
  require 'io/console'
10
10
  require 'reline'
11
11
 
12
12
  module IRB
13
- STDIN_FILE_NAME = "(line)" # :nodoc:
14
13
  class InputMethod
15
-
16
- # Creates a new input method object
17
- def initialize(file = STDIN_FILE_NAME)
18
- @file_name = file
19
- end
20
- # The file name of this input method, usually given during initialization.
21
- attr_reader :file_name
14
+ BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
22
15
 
23
16
  # The irb prompt associated with this input method
24
17
  attr_accessor :prompt
@@ -27,7 +20,7 @@ module IRB
27
20
  #
28
21
  # See IO#gets for more information.
29
22
  def gets
30
- fail NotImplementedError, "gets"
23
+ fail NotImplementedError
31
24
  end
32
25
  public :gets
33
26
 
@@ -47,6 +40,14 @@ module IRB
47
40
  false
48
41
  end
49
42
 
43
+ def support_history_saving?
44
+ false
45
+ end
46
+
47
+ def prompting?
48
+ false
49
+ end
50
+
50
51
  # For debug message
51
52
  def inspect
52
53
  'Abstract InputMethod'
@@ -56,7 +57,6 @@ module IRB
56
57
  class StdioInputMethod < InputMethod
57
58
  # Creates a new input method object
58
59
  def initialize
59
- super
60
60
  @line_no = 0
61
61
  @line = []
62
62
  @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
@@ -67,6 +67,7 @@ module IRB
67
67
  #
68
68
  # See IO#gets for more information.
69
69
  def gets
70
+ puts if @stdout.tty? # workaround for debug compatibility test
70
71
  print @prompt
71
72
  line = @stdin.gets
72
73
  @line[@line_no += 1] = line
@@ -95,6 +96,10 @@ module IRB
95
96
  true
96
97
  end
97
98
 
99
+ def prompting?
100
+ STDIN.tty?
101
+ end
102
+
98
103
  # Returns the current line number for #io.
99
104
  #
100
105
  # #line counts the number of times #gets is called.
@@ -130,12 +135,9 @@ module IRB
130
135
 
131
136
  # Creates a new input method object
132
137
  def initialize(file)
133
- super
134
138
  @io = file.is_a?(IO) ? file : File.open(file)
135
139
  @external_encoding = @io.external_encoding
136
140
  end
137
- # The file name of this input method, usually given during initialization.
138
- attr_reader :file_name
139
141
 
140
142
  # Whether the end of this input method has been reached, returns +true+ if
141
143
  # there is no more data to read.
@@ -168,114 +170,99 @@ module IRB
168
170
  end
169
171
  end
170
172
 
171
- begin
172
- class ReadlineInputMethod < InputMethod
173
- def self.initialize_readline
174
- require "readline"
175
- rescue LoadError
176
- else
177
- include ::Readline
178
- end
173
+ class ReadlineInputMethod < StdioInputMethod
174
+ def self.initialize_readline
175
+ require "readline"
176
+ rescue LoadError
177
+ else
178
+ include ::Readline
179
+ end
179
180
 
180
- # Creates a new input method object using Readline
181
- def initialize
182
- self.class.initialize_readline
183
- if Readline.respond_to?(:encoding_system_needs)
184
- IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
185
- end
186
- super
181
+ include HistorySavingAbility
187
182
 
188
- @line_no = 0
189
- @line = []
190
- @eof = false
183
+ # Creates a new input method object using Readline
184
+ def initialize
185
+ self.class.initialize_readline
186
+ if Readline.respond_to?(:encoding_system_needs)
187
+ IRB.__send__(:set_encoding, Readline.encoding_system_needs.name, override: false)
188
+ end
191
189
 
192
- @stdin = IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
193
- @stdout = IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
190
+ super
194
191
 
195
- if Readline.respond_to?("basic_word_break_characters=")
196
- Readline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
197
- end
198
- Readline.completion_append_character = nil
199
- Readline.completion_proc = IRB::InputCompletor::CompletionProc
200
- end
192
+ @eof = false
193
+ @completor = RegexpCompletor.new
201
194
 
202
- # Reads the next line from this input method.
203
- #
204
- # See IO#gets for more information.
205
- def gets
206
- Readline.input = @stdin
207
- Readline.output = @stdout
208
- if l = readline(@prompt, false)
209
- HISTORY.push(l) if !l.empty?
210
- @line[@line_no += 1] = l + "\n"
211
- else
212
- @eof = true
213
- l
214
- end
195
+ if Readline.respond_to?("basic_word_break_characters=")
196
+ Readline.basic_word_break_characters = BASIC_WORD_BREAK_CHARACTERS
215
197
  end
198
+ Readline.completion_append_character = nil
199
+ Readline.completion_proc = ->(target) {
200
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
201
+ @completor.completion_candidates('', target, '', bind: bind)
202
+ }
203
+ end
216
204
 
217
- # Whether the end of this input method has been reached, returns +true+
218
- # if there is no more data to read.
219
- #
220
- # See IO#eof? for more information.
221
- def eof?
222
- @eof
223
- end
205
+ def completion_info
206
+ 'RegexpCompletor'
207
+ end
224
208
 
225
- # Whether this input method is still readable when there is no more data to
226
- # read.
227
- #
228
- # See IO#eof for more information.
229
- def readable_after_eof?
230
- true
209
+ # Reads the next line from this input method.
210
+ #
211
+ # See IO#gets for more information.
212
+ def gets
213
+ Readline.input = @stdin
214
+ Readline.output = @stdout
215
+ if l = readline(@prompt, false)
216
+ HISTORY.push(l) if !l.empty?
217
+ @line[@line_no += 1] = l + "\n"
218
+ else
219
+ @eof = true
220
+ l
231
221
  end
222
+ end
232
223
 
233
- # Returns the current line number for #io.
234
- #
235
- # #line counts the number of times #gets is called.
236
- #
237
- # See IO#lineno for more information.
238
- def line(line_no)
239
- @line[line_no]
240
- end
224
+ # Whether the end of this input method has been reached, returns +true+
225
+ # if there is no more data to read.
226
+ #
227
+ # See IO#eof? for more information.
228
+ def eof?
229
+ @eof
230
+ end
241
231
 
242
- # The external encoding for standard input.
243
- def encoding
244
- @stdin.external_encoding
245
- end
232
+ def prompting?
233
+ true
234
+ end
246
235
 
247
- # For debug message
248
- def inspect
249
- readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
250
- str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
251
- inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
252
- str += " and #{inputrc_path}" if File.exist?(inputrc_path)
253
- str
254
- end
236
+ # For debug message
237
+ def inspect
238
+ readline_impl = (defined?(Reline) && Readline == Reline) ? 'Reline' : 'ext/readline'
239
+ str = "ReadlineInputMethod with #{readline_impl} #{Readline::VERSION}"
240
+ inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
241
+ str += " and #{inputrc_path}" if File.exist?(inputrc_path)
242
+ str
255
243
  end
256
244
  end
257
245
 
258
- class RelineInputMethod < InputMethod
259
- include Reline
260
-
246
+ class RelineInputMethod < StdioInputMethod
247
+ HISTORY = Reline::HISTORY
248
+ include HistorySavingAbility
261
249
  # Creates a new input method object using Reline
262
- def initialize
250
+ def initialize(completor)
263
251
  IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
264
- super
265
252
 
266
- @line_no = 0
267
- @line = []
268
- @eof = false
253
+ super()
269
254
 
270
- @stdin = ::IO.open(STDIN.to_i, :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
271
- @stdout = ::IO.open(STDOUT.to_i, 'w', :external_encoding => IRB.conf[:LC_MESSAGES].encoding, :internal_encoding => "-")
255
+ @eof = false
256
+ @completor = completor
272
257
 
273
- if Reline.respond_to?("basic_word_break_characters=")
274
- Reline.basic_word_break_characters = IRB::InputCompletor::BASIC_WORD_BREAK_CHARACTERS
275
- end
258
+ Reline.basic_word_break_characters = BASIC_WORD_BREAK_CHARACTERS
276
259
  Reline.completion_append_character = nil
277
260
  Reline.completer_quote_characters = ''
278
- Reline.completion_proc = IRB::InputCompletor::CompletionProc
261
+ Reline.completion_proc = ->(target, preposing, postposing) {
262
+ bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
263
+ @completion_params = [preposing, target, postposing, bind]
264
+ @completor.completion_candidates(preposing, target, postposing, bind: bind)
265
+ }
279
266
  Reline.output_modifier_proc =
280
267
  if IRB.conf[:USE_COLORIZE]
281
268
  proc do |output, complete: |
@@ -288,18 +275,23 @@ module IRB
288
275
  Reline::Unicode.escape_for_print(output)
289
276
  end
290
277
  end
291
- Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
278
+ Reline.dig_perfect_match_proc = ->(matched) { display_document(matched) }
292
279
  Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
293
280
 
294
281
  if IRB.conf[:USE_AUTOCOMPLETE]
295
282
  begin
296
283
  require 'rdoc'
297
- Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
284
+ Reline.add_dialog_proc(:show_doc, show_doc_dialog_proc, Reline::DEFAULT_DIALOG_CONTEXT)
298
285
  rescue LoadError
299
286
  end
300
287
  end
301
288
  end
302
289
 
290
+ def completion_info
291
+ autocomplete_message = Reline.autocompletion ? 'Autocomplete' : 'Tab Complete'
292
+ "#{autocomplete_message}, #{@completor.inspect}"
293
+ end
294
+
303
295
  def check_termination(&block)
304
296
  @check_termination_proc = block
305
297
  end
@@ -312,100 +304,165 @@ module IRB
312
304
  @auto_indent_proc = block
313
305
  end
314
306
 
315
- SHOW_DOC_DIALOG = ->() {
316
- dialog.trap_key = nil
317
- alt_d = [
318
- [Reline::Key.new(nil, 0xE4, true)], # Normal Alt+d.
319
- [27, 100], # Normal Alt+d when convert-meta isn't used.
320
- [195, 164], # The "ä" that appears when Alt+d is pressed on xterm.
321
- [226, 136, 130] # The "∂" that appears when Alt+d in pressed on iTerm2.
322
- ]
307
+ def retrieve_doc_namespace(matched)
308
+ preposing, _target, postposing, bind = @completion_params
309
+ @completor.doc_namespace(preposing, matched, postposing, bind: bind)
310
+ end
323
311
 
324
- if just_cursor_moving and completion_journey_data.nil?
325
- return nil
326
- end
327
- cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
328
- return nil if result.nil? or pointer.nil? or pointer < 0
329
- name = result[pointer]
330
- name = IRB::InputCompletor.retrieve_completion_data(name, doc_namespace: true)
312
+ def rdoc_ri_driver
313
+ return @rdoc_ri_driver if defined?(@rdoc_ri_driver)
331
314
 
332
- options = {}
333
- options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
334
- driver = RDoc::RI::Driver.new(options)
315
+ begin
316
+ require 'rdoc'
317
+ rescue LoadError
318
+ @rdoc_ri_driver = nil
319
+ else
320
+ options = {}
321
+ options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
322
+ @rdoc_ri_driver = RDoc::RI::Driver.new(options)
323
+ end
324
+ end
335
325
 
336
- if key.match?(dialog.name)
337
- begin
338
- driver.display_names([name])
339
- rescue RDoc::RI::Driver::NotFoundError
326
+ def show_doc_dialog_proc
327
+ input_method = self # self is changed in the lambda below.
328
+ ->() {
329
+ dialog.trap_key = nil
330
+ alt_d = [
331
+ [27, 100], # Normal Alt+d when convert-meta isn't used.
332
+ # When option/alt is not configured as a meta key in terminal emulator,
333
+ # option/alt + d will send a unicode character depend on OS keyboard setting.
334
+ [195, 164], # "ä" in somewhere (FIXME: environment information is unknown).
335
+ [226, 136, 130] # "∂" Alt+d on Mac keyboard.
336
+ ]
337
+
338
+ if just_cursor_moving and completion_journey_data.nil?
339
+ return nil
340
340
  end
341
- end
341
+ cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
342
+ return nil if result.nil? or pointer.nil? or pointer < 0
342
343
 
343
- begin
344
- name = driver.expand_name(name)
345
- rescue RDoc::RI::Driver::NotFoundError
346
- return nil
347
- rescue
348
- return nil # unknown error
349
- end
350
- doc = nil
351
- used_for_class = false
352
- if not name =~ /#|\./
353
- found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name)
354
- if not found.empty?
355
- doc = driver.class_document(name, found, klasses, includes, extends)
356
- used_for_class = true
344
+ name = input_method.retrieve_doc_namespace(result[pointer])
345
+ # Use first one because document dialog does not support multiple namespaces.
346
+ name = name.first if name.is_a?(Array)
347
+
348
+ show_easter_egg = name&.match?(/\ARubyVM/) && !ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
349
+
350
+ driver = input_method.rdoc_ri_driver
351
+
352
+ if key.match?(dialog.name)
353
+ if show_easter_egg
354
+ IRB.__send__(:easter_egg)
355
+ else
356
+ begin
357
+ driver.display_names([name])
358
+ rescue RDoc::RI::Driver::NotFoundError
359
+ end
360
+ end
357
361
  end
358
- end
359
- unless used_for_class
360
- doc = RDoc::Markup::Document.new
362
+
361
363
  begin
362
- driver.add_method(doc, name)
364
+ name = driver.expand_name(name)
363
365
  rescue RDoc::RI::Driver::NotFoundError
364
- doc = nil
366
+ return nil
365
367
  rescue
366
368
  return nil # unknown error
367
369
  end
368
- end
369
- return nil if doc.nil?
370
- width = 40
371
-
372
- right_x = cursor_pos_to_render.x + autocomplete_dialog.width
373
- if right_x + width > screen_width
374
- right_width = screen_width - (right_x + 1)
375
- left_x = autocomplete_dialog.column - width
376
- left_x = 0 if left_x < 0
377
- left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width
378
- if right_width.positive? and left_width.positive?
379
- if right_width >= left_width
370
+ doc = nil
371
+ used_for_class = false
372
+ if not name =~ /#|\./
373
+ found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name)
374
+ if not found.empty?
375
+ doc = driver.class_document(name, found, klasses, includes, extends)
376
+ used_for_class = true
377
+ end
378
+ end
379
+ unless used_for_class
380
+ doc = RDoc::Markup::Document.new
381
+ begin
382
+ driver.add_method(doc, name)
383
+ rescue RDoc::RI::Driver::NotFoundError
384
+ doc = nil
385
+ rescue
386
+ return nil # unknown error
387
+ end
388
+ end
389
+ return nil if doc.nil?
390
+ width = 40
391
+
392
+ right_x = cursor_pos_to_render.x + autocomplete_dialog.width
393
+ if right_x + width > screen_width
394
+ right_width = screen_width - (right_x + 1)
395
+ left_x = autocomplete_dialog.column - width
396
+ left_x = 0 if left_x < 0
397
+ left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width
398
+ if right_width.positive? and left_width.positive?
399
+ if right_width >= left_width
400
+ width = right_width
401
+ x = right_x
402
+ else
403
+ width = left_width
404
+ x = left_x
405
+ end
406
+ elsif right_width.positive? and left_width <= 0
380
407
  width = right_width
381
408
  x = right_x
382
- else
409
+ elsif right_width <= 0 and left_width.positive?
383
410
  width = left_width
384
411
  x = left_x
412
+ else # Both are negative width.
413
+ return nil
385
414
  end
386
- elsif right_width.positive? and left_width <= 0
387
- width = right_width
415
+ else
388
416
  x = right_x
389
- elsif right_width <= 0 and left_width.positive?
390
- width = left_width
391
- x = left_x
392
- else # Both are negative width.
393
- return nil
394
417
  end
418
+ formatter = RDoc::Markup::ToAnsi.new
419
+ formatter.width = width
420
+ dialog.trap_key = alt_d
421
+ mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
422
+ if show_easter_egg
423
+ type = STDOUT.external_encoding == Encoding::UTF_8 ? :unicode : :ascii
424
+ contents = IRB.send(:easter_egg_logo, type).split("\n")
425
+ message = "Press #{mod_key}+d to see more"
426
+ contents[0][0, message.size] = message
427
+ else
428
+ message = "Press #{mod_key}+d to read the full document"
429
+ contents = [message] + doc.accept(formatter).split("\n")
430
+ end
431
+ contents = contents.take(preferred_dialog_height)
432
+
433
+ y = cursor_pos_to_render.y
434
+ Reline::DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
435
+ }
436
+ end
437
+
438
+ def display_document(matched)
439
+ driver = rdoc_ri_driver
440
+ return unless driver
441
+
442
+ if matched =~ /\A(?:::)?RubyVM/ and not ENV['RUBY_YES_I_AM_NOT_A_NORMAL_USER']
443
+ IRB.__send__(:easter_egg)
444
+ return
445
+ end
446
+
447
+ namespace = retrieve_doc_namespace(matched)
448
+ return unless namespace
449
+
450
+ if namespace.is_a?(Array)
451
+ out = RDoc::Markup::Document.new
452
+ namespace.each do |m|
453
+ begin
454
+ driver.add_method(out, m)
455
+ rescue RDoc::RI::Driver::NotFoundError
456
+ end
457
+ end
458
+ driver.display(out)
395
459
  else
396
- x = right_x
460
+ begin
461
+ driver.display_names([namespace])
462
+ rescue RDoc::RI::Driver::NotFoundError
463
+ end
397
464
  end
398
- formatter = RDoc::Markup::ToAnsi.new
399
- formatter.width = width
400
- dialog.trap_key = alt_d
401
- mod_key = RUBY_PLATFORM.match?(/darwin/) ? "Option" : "Alt"
402
- message = "Press #{mod_key}+d to read the full document"
403
- contents = [message] + doc.accept(formatter).split("\n")
404
- contents = contents.take(preferred_dialog_height) if respond_to?(:preferred_dialog_height)
405
-
406
- y = cursor_pos_to_render.y
407
- DialogRenderInfo.new(pos: Reline::CursorPos.new(x, y), contents: contents, width: width, bg_color: '49')
408
- }
465
+ end
409
466
 
410
467
  # Reads the next line from this input method.
411
468
  #
@@ -415,8 +472,8 @@ module IRB
415
472
  Reline.output = @stdout
416
473
  Reline.prompt_proc = @prompt_proc
417
474
  Reline.auto_indent_proc = @auto_indent_proc if @auto_indent_proc
418
- if l = readmultiline(@prompt, false, &@check_termination_proc)
419
- HISTORY.push(l) if !l.empty?
475
+ if l = Reline.readmultiline(@prompt, false, &@check_termination_proc)
476
+ Reline::HISTORY.push(l) if !l.empty?
420
477
  @line[@line_no += 1] = l + "\n"
421
478
  else
422
479
  @eof = true
@@ -432,37 +489,15 @@ module IRB
432
489
  @eof
433
490
  end
434
491
 
435
- # Whether this input method is still readable when there is no more data to
436
- # read.
437
- #
438
- # See IO#eof for more information.
439
- def readable_after_eof?
492
+ def prompting?
440
493
  true
441
494
  end
442
495
 
443
- # Returns the current line number for #io.
444
- #
445
- # #line counts the number of times #gets is called.
446
- #
447
- # See IO#lineno for more information.
448
- def line(line_no)
449
- @line[line_no]
450
- end
451
-
452
- # The external encoding for standard input.
453
- def encoding
454
- @stdin.external_encoding
455
- end
456
-
457
496
  # For debug message
458
497
  def inspect
459
498
  config = Reline::Config.new
460
499
  str = "RelineInputMethod with Reline #{Reline::VERSION}"
461
- if config.respond_to?(:inputrc_path)
462
- inputrc_path = File.expand_path(config.inputrc_path)
463
- else
464
- inputrc_path = File.expand_path(ENV['INPUTRC'] || '~/.inputrc')
465
- end
500
+ inputrc_path = File.expand_path(config.inputrc_path)
466
501
  str += " and #{inputrc_path}" if File.exist?(inputrc_path)
467
502
  str
468
503
  end
data/lib/irb/inspector.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/inspector.rb - inspect methods
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -46,7 +46,7 @@ module IRB # :nodoc:
46
46
  # Determines the inspector to use where +inspector+ is one of the keys passed
47
47
  # during inspector definition.
48
48
  def self.keys_with_inspector(inspector)
49
- INSPECTORS.select{|k,v| v == inspector}.collect{|k, v| k}
49
+ INSPECTORS.select{|k, v| v == inspector}.collect{|k, v| k}
50
50
  end
51
51
 
52
52
  # Example
@@ -113,7 +113,7 @@ module IRB # :nodoc:
113
113
  Color.colorize_code(v.inspect, colorable: Color.colorable? && Color.inspect_colorable?(v))
114
114
  }
115
115
  Inspector.def_inspector([true, :pp, :pretty_inspect], proc{require_relative "color_printer"}){|v|
116
- IRB::ColorPrinter.pp(v, '').chomp
116
+ IRB::ColorPrinter.pp(v, +'').chomp
117
117
  }
118
118
  Inspector.def_inspector([:yaml, :YAML], proc{require "yaml"}){|v|
119
119
  begin
data/lib/irb/lc/error.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/lc/error.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -12,11 +12,6 @@ module IRB
12
12
  super("Unrecognized switch: #{val}")
13
13
  end
14
14
  end
15
- class NotImplementedError < StandardError
16
- def initialize(val)
17
- super("Need to define `#{val}'")
18
- end
19
- end
20
15
  class CantReturnToNormalMode < StandardError
21
16
  def initialize
22
17
  super("Can't return to normal mode.")
@@ -52,11 +47,6 @@ module IRB
52
47
  super("Undefined prompt mode(#{val}).")
53
48
  end
54
49
  end
55
- class IllegalRCGenerator < StandardError
56
- def initialize
57
- super("Define illegal RC_NAME_GENERATOR.")
58
- end
59
- end
60
50
 
61
51
  # :startdoc:
62
52
  end
@@ -22,6 +22,7 @@ Usage: irb.rb [options] [programfile] [arguments]
22
22
  Show truncated result on assignment (default).
23
23
  --inspect Use 'inspect' for output.
24
24
  --noinspect Don't use 'inspect' for output.
25
+ --no-pager Don't use pager.
25
26
  --multiline Use multiline editor module (default).
26
27
  --nomultiline Don't use multiline editor module.
27
28
  --singleline Use single line editor module.
@@ -30,6 +31,9 @@ Usage: irb.rb [options] [programfile] [arguments]
30
31
  --nocolorize Don't use color-highlighting.
31
32
  --autocomplete Use auto-completion (default).
32
33
  --noautocomplete Don't use auto-completion.
34
+ --regexp-completor
35
+ Use regexp based completion (default).
36
+ --type-completor Use type based completion.
33
37
  --prompt prompt-mode, --prompt-mode prompt-mode
34
38
  Set prompt mode. Pre-defined prompt modes are:
35
39
  'default', 'classic', 'simple', 'inf-ruby', 'xmp', 'null'.