irb 1.3.7 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddb63fc9d57700014a7da313e20504596ca42dfee0952547fa545d726f08d7d6
4
- data.tar.gz: cc4ee2f880d56dc7f792ecc406f489f8555601d19499f45d8f8828cc260ed1b0
3
+ metadata.gz: be0bdb184f8483785b83b91bc57339e994a15b2d1435720e8f17b9f04b2b924e
4
+ data.tar.gz: 02ca5b9f06cedc077c79f07ad33765225736f9d7ffa9bb93671cf739131a2d9c
5
5
  SHA512:
6
- metadata.gz: c5b128b8ce5457862489e313231af33167802619c3847da526dda30c83f7fc96d1a248d2916e17da4cbd45f8d30aee8c181237182b97b5741cf4bc4c13568bfb
7
- data.tar.gz: 61147b2b4e76f34076043feaa84feeb2e893a140d3d7d1e5013a00f87f27f694802f8ae21788709a7ee03c5b41ee445735aec93bfedbeaa9fcf02d6bf06f705d
6
+ metadata.gz: faa52653f45b98a0ce82b215110376e3cac3faefa34928a50067e101c3171a0fbc492ba3b7a23334ac81f23448526e6931fca45925a07ab914aa2634c8e1de9a
7
+ data.tar.gz: 4da73a1293f021bcb3a0ed996ac4f48f3c73884d34efa438987b230cda72ce3aa0c6ac67865e57655cdcc8ffd49cb6ca267c564711345247ed889857f60156c1
data/Gemfile CHANGED
@@ -1,15 +1,13 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
3
  gemspec
6
4
 
7
5
  group :development do
8
- gem "bundler"
9
6
  is_unix = RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
10
7
  is_truffleruby = RUBY_DESCRIPTION =~ /truffleruby/
11
- gem 'vterm', '>= 0.0.5' if is_unix && ENV['WITH_VTERM']
12
- gem 'yamatanooroti', '>= 0.0.6'
8
+ gem "vterm", ">= 0.0.5" if is_unix && ENV['WITH_VTERM']
9
+ gem "yamatanooroti", ">= 0.0.6"
13
10
  gem "rake"
14
11
  gem "stackprof" if is_unix && !is_truffleruby
12
+ gem "test-unit"
15
13
  end
data/Rakefile CHANGED
@@ -4,14 +4,23 @@ require "rake/testtask"
4
4
  Rake::TestTask.new(:test) do |t|
5
5
  t.libs << "test" << "test/lib"
6
6
  t.libs << "lib"
7
+ t.ruby_opts << "-rhelper"
7
8
  t.test_files = FileList["test/irb/test_*.rb"]
8
9
  end
9
10
 
10
11
  Rake::TestTask.new(:test_yamatanooroti) do |t|
11
- t.libs << 'test'
12
+ t.libs << 'test' << "test/lib"
12
13
  t.libs << 'lib'
13
14
  #t.loader = :direct
15
+ t.ruby_opts << "-rhelper"
14
16
  t.pattern = 'test/irb/yamatanooroti/test_*.rb'
15
17
  end
16
18
 
19
+ task :sync_tool do
20
+ require 'fileutils'
21
+ FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
22
+ FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
23
+ FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
24
+ end
25
+
17
26
  task :default => :test
data/doc/irb/irb.rd.ja CHANGED
@@ -40,15 +40,24 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
40
40
  irb.rb [options] file_name opts
41
41
  options:
42
42
  -f ~/.irbrc を読み込まない.
43
- -m bcモード(分数, 行列の計算ができる)
44
43
  -d $DEBUG をtrueにする(ruby -d と同じ)
45
- -Kc ruby -Kcと同じ
46
44
  -r load-module ruby -r と同じ.
47
- --verbose これから実行する行を表示する(デフォルト)
48
- --noverbose これから実行する行を表示しない
49
- --echo 実行結果を表示する(デフォルト)
50
- --noecho 実行結果を表示しない
51
- --inspect 結果出力にinspectを用いる(bcモード以外はデフォルト).
45
+ -I path $LOAD_PATH に path を追加する.
46
+ -U ruby -U と同じ.
47
+ -E enc ruby -E と同じ.
48
+ -w ruby -w と同じ.
49
+ -W[level=2] ruby -W と同じ.
50
+ --context-mode n 新しいワークスペースを作成した時に関連する Binding
51
+ オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
52
+ --echo 実行結果を表示する(デフォルト).
53
+ --noecho 実行結果を表示しない.
54
+ --echo-on-assignment
55
+ 代入時に実行結果を表示する.
56
+ --noecho-on-assignment
57
+ 代入時に実行結果を表示しない.
58
+ --truncate-echo-on-assignment
59
+ 代入時に省略された実行結果を表示する(デフォルト).
60
+ --inspect 結果出力にinspectを用いる.
52
61
  --noinspect 結果出力にinspectを用いない.
53
62
  --singleline シングルラインエディタを利用する.
54
63
  --nosingleline シングルラインエディタを利用しない. デフォルトの動
@@ -56,23 +65,30 @@ irbの使い方は, Rubyさえ知っていればいたって簡単です. 基本
56
65
  用しようとする.
57
66
  --colorize 色付けを利用する.
58
67
  --nocolorize 色付けを利用しない.
68
+ --autocomplete オートコンプリートを利用する.
69
+ --noautocomplete オートコンプリートを利用しない.
59
70
  --prompt prompt-mode
60
71
  --prompt-mode prompt-mode
61
72
  プロンプトモードを切替えます. 現在定義されているプ
62
73
  ロンプトモードは, default, simple, xmp, inf-rubyが
63
- 用意されています. デフォルトはdefaultプロンプトモー
64
- ドになっています.
65
-
74
+ 用意されています.
66
75
  --inf-ruby-mode emacsのinf-ruby-mode用のプロンプト表示を行なう. 特
67
76
  に指定がない限り, ラインエディタは使わなくなる.
68
77
  --simple-prompt
69
78
  非常にシンプルなプロンプトを用いるモードです.
70
79
  --noprompt プロンプト表示を行なわない.
80
+ --single-irb irb 中で self を実行して得られるオブジェクトをサ
81
+ ブ irb と共有する.
71
82
  --tracer コマンド実行時にトレースを行なう.
72
83
  --back-trace-limit n
73
84
  バックトレース表示をバックトレースの頭から n, 後ろ
74
85
  からnだけ行なう. デフォルトは16
75
- -v, --version irbのバージョンを表示する
86
+
87
+ --verbose 詳細なメッセージを出力する.
88
+ --noverbose 詳細なメッセージを出力しない(デフォルト).
89
+ -v, --version irbのバージョンを表示する.
90
+ -h, --help irb のヘルプを表示する.
91
+ -- 以降のコマンドライン引数をオプションとして扱わない.
76
92
 
77
93
  = コンフィギュレーション
78
94
 
@@ -137,12 +153,12 @@ PROMPT_I, PROMPT_N, PROMPT_S, PROMPT_Cは, フォーマットを指定します.
137
153
 
138
154
  例えば, デフォルトのプロンプトモードは:
139
155
 
140
- IRB.conf[:PROMPT_MODE][:DEFAULT] = {
156
+ IRB.conf[:PROMPT][:DEFAULT] = {
141
157
  :PROMPT_I => "%N(%m):%03n:%i> ",
142
158
  :PROMPT_N => "%N(%m):%03n:%i> ",
143
159
  :PROMPT_S => "%N(%m):%03n:%i%l ",
144
160
  :PROMPT_C => "%N(%m):%03n:%i* ",
145
- :RETURN => "%s\n"
161
+ :RETURN => "=> %s\n"
146
162
  }
147
163
 
148
164
  となっています.
@@ -374,7 +390,7 @@ rubyでは, 以下のプログラムはエラーになります.
374
390
  パイルしてローカル変数を決定するからです. それに対し, irbは実行可能に
375
391
  なる(式が閉じる)と自動的に評価しているからです. 上記の例では,
376
392
 
377
- evel "foo = 0"
393
+ eval "foo = 0"
378
394
 
379
395
  を行なった時点で評価を行ない, その時点で変数が定義されるため, 次式で
380
396
  変数fooは定義されているからです.
data/irb.gemspec CHANGED
@@ -36,5 +36,5 @@ Gem::Specification.new do |spec|
36
36
 
37
37
  spec.required_ruby_version = Gem::Requirement.new(">= 2.5")
38
38
 
39
- spec.add_dependency "reline", ">= 0.2.7"
39
+ spec.add_dependency "reline", ">= 0.3.0"
40
40
  end
data/lib/irb/cmd/help.rb CHANGED
@@ -17,7 +17,8 @@ module IRB
17
17
  class Help < Nop
18
18
  def execute(*names)
19
19
  require 'rdoc/ri/driver'
20
- IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new)
20
+ opts = RDoc::RI::Driver.process_args([])
21
+ IRB::ExtendCommand::Help.const_set(:Ri, RDoc::RI::Driver.new(opts))
21
22
  rescue LoadError, SystemExit
22
23
  IRB::ExtendCommand::Help.remove_method(:execute)
23
24
  # raise NoMethodError in ensure
data/lib/irb/cmd/info.rb CHANGED
@@ -16,8 +16,9 @@ module IRB
16
16
  str += "RUBY_PLATFORM: #{RUBY_PLATFORM}\n"
17
17
  str += "LANG env: #{ENV["LANG"]}\n" if ENV["LANG"] && !ENV["LANG"].empty?
18
18
  str += "LC_ALL env: #{ENV["LC_ALL"]}\n" if ENV["LC_ALL"] && !ENV["LC_ALL"].empty?
19
+ str += "East Asian Ambiguous Width: #{Reline.ambiguous_width.inspect}\n"
19
20
  if RbConfig::CONFIG['host_os'] =~ /mswin|msys|mingw|cygwin|bccwin|wince|emc/
20
- codepage = `chcp`.sub(/.*: (\d+)\n/, '\1')
21
+ codepage = `chcp`.b.sub(/.*: (\d+)\n/, '\1')
21
22
  str += "Code page: #{codepage}\n"
22
23
  end
23
24
  str
@@ -61,15 +61,12 @@ module IRB
61
61
  lex = RubyLex.new
62
62
  lines = File.read(file).lines[(first_line - 1)..-1]
63
63
  tokens = RubyLex.ripper_lex_without_warning(lines.join)
64
-
65
- code = +""
66
64
  prev_tokens = []
67
65
 
68
66
  # chunk with line number
69
- tokens.chunk { |tok| tok[0][0] }.each do |lnum, chunk|
70
- code << lines[lnum]
67
+ tokens.chunk { |tok| tok.pos[0] }.each do |lnum, chunk|
68
+ code = lines[0..lnum].join
71
69
  prev_tokens.concat chunk
72
-
73
70
  continue = lex.process_continue(prev_tokens)
74
71
  code_block_open = lex.check_code_block(code, prev_tokens)
75
72
  if !continue && !code_block_open
@@ -38,16 +38,48 @@ module IRB
38
38
 
39
39
  BASIC_WORD_BREAK_CHARACTERS = " \t\n`><=;|&{("
40
40
 
41
- def self.retrieve_files_to_require_from_load_path
42
- @@files_from_load_path ||= $LOAD_PATH.flat_map { |path|
43
- begin
44
- Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
45
- rescue Errno::ENOENT
46
- []
41
+ def self.absolute_path?(p) # TODO Remove this method after 2.6 EOL.
42
+ if File.respond_to?(:absolute_path?)
43
+ File.absolute_path?(p)
44
+ else
45
+ if File.absolute_path(p) == p
46
+ true
47
+ else
48
+ false
47
49
  end
48
- }.uniq.map { |path|
49
- path.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '')
50
- }
50
+ end
51
+ end
52
+
53
+ def self.retrieve_gem_and_system_load_path
54
+ gem_paths = Gem::Specification.latest_specs(true).map { |s|
55
+ s.require_paths.map { |p|
56
+ if absolute_path?(p)
57
+ p
58
+ else
59
+ File.join(s.full_gem_path, p)
60
+ end
61
+ }
62
+ }.flatten if defined?(Gem::Specification)
63
+ (gem_paths.to_a | $LOAD_PATH).sort
64
+ end
65
+
66
+ def self.retrieve_files_to_require_from_load_path
67
+ @@files_from_load_path ||=
68
+ (
69
+ shortest = []
70
+ rest = retrieve_gem_and_system_load_path.each_with_object([]) { |path, result|
71
+ begin
72
+ names = Dir.glob("**/*.{rb,#{RbConfig::CONFIG['DLEXT']}}", base: path)
73
+ rescue Errno::ENOENT
74
+ nil
75
+ end
76
+ next if names.empty?
77
+ names.map! { |n| n.sub(/\.(rb|#{RbConfig::CONFIG['DLEXT']})\z/, '') }.sort!
78
+ shortest << names.shift
79
+ result.concat(names)
80
+ }
81
+ shortest.sort! | rest
82
+ )
51
83
  end
52
84
 
53
85
  def self.retrieve_files_to_require_relative_from_current_dir
@@ -160,12 +192,12 @@ module IRB
160
192
  sym = $1
161
193
  candidates = Symbol.all_symbols.collect do |s|
162
194
  ":" + s.id2name.encode(Encoding.default_external)
163
- rescue Encoding::UndefinedConversionError
195
+ rescue EncodingError
164
196
  # ignore
165
197
  end
166
198
  candidates.grep(/^#{Regexp.quote(sym)}/)
167
199
 
168
- when /^::([A-Z][^:\.\(]*)$/
200
+ when /^::([A-Z][^:\.\(\)]*)$/
169
201
  # Absolute Constant or class methods
170
202
  receiver = $1
171
203
  candidates = Object.constants.collect{|m| m.to_s}
@@ -258,7 +290,7 @@ module IRB
258
290
  all_gvars.grep(Regexp.new(Regexp.quote(gvar)))
259
291
  end
260
292
 
261
- when /^([^."].*)(\.|::)([^.]*)$/
293
+ when /^([^.:"].*)(\.|::)([^.]*)$/
262
294
  # variable.func or func.func
263
295
  receiver = $1
264
296
  sep = $2
@@ -296,7 +328,8 @@ module IRB
296
328
  candidates.uniq!
297
329
  end
298
330
  if doc_namespace
299
- "#{rec.class.name}#{sep}#{candidates.find{ |i| i == message }}"
331
+ rec_class = rec.is_a?(Module) ? rec : rec.class
332
+ "#{rec_class.name}#{sep}#{candidates.find{ |i| i == message }}"
300
333
  else
301
334
  select_message(receiver, message, candidates, sep)
302
335
  end
@@ -315,12 +348,19 @@ module IRB
315
348
  end
316
349
 
317
350
  else
318
- candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
319
- candidates |= ReservedWords
320
-
321
351
  if doc_namespace
322
- candidates.find{ |i| i == input }
352
+ vars = eval("local_variables | instance_variables", bind).collect{|m| m.to_s}
353
+ perfect_match_var = vars.find{|m| m.to_s == input}
354
+ if perfect_match_var
355
+ eval("#{perfect_match_var}.class.name", bind)
356
+ else
357
+ candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
358
+ candidates |= ReservedWords
359
+ candidates.find{ |i| i == input }
360
+ end
323
361
  else
362
+ candidates = eval("methods | private_methods | local_variables | instance_variables | self.class.constants", bind).collect{|m| m.to_s}
363
+ candidates |= ReservedWords
324
364
  candidates.grep(/^#{Regexp.quote(input)}/)
325
365
  end
326
366
  end
data/lib/irb/context.rb CHANGED
@@ -54,6 +54,7 @@ module IRB
54
54
  @use_multiline = nil
55
55
  end
56
56
  @use_colorize = IRB.conf[:USE_COLORIZE]
57
+ @use_autocomplete = IRB.conf[:USE_AUTOCOMPLETE]
57
58
  @verbose = IRB.conf[:VERBOSE]
58
59
  @io = nil
59
60
 
@@ -124,6 +125,8 @@ module IRB
124
125
  end
125
126
  self.save_history = IRB.conf[:SAVE_HISTORY] if IRB.conf[:SAVE_HISTORY]
126
127
 
128
+ @extra_doc_dirs = IRB.conf[:EXTRA_DOC_DIRS]
129
+
127
130
  @echo = IRB.conf[:ECHO]
128
131
  if @echo.nil?
129
132
  @echo = true
@@ -147,18 +150,18 @@ module IRB
147
150
 
148
151
  # The toplevel workspace, see #home_workspace
149
152
  attr_reader :workspace_home
150
- # WorkSpace in the current context
153
+ # WorkSpace in the current context.
151
154
  attr_accessor :workspace
152
- # The current thread in this context
155
+ # The current thread in this context.
153
156
  attr_reader :thread
154
- # The current input method
157
+ # The current input method.
155
158
  #
156
159
  # Can be either StdioInputMethod, ReadlineInputMethod,
157
160
  # ReidlineInputMethod, FileInputMethod or other specified when the
158
161
  # context is created. See ::new for more # information on +input_method+.
159
162
  attr_accessor :io
160
163
 
161
- # Current irb session
164
+ # Current irb session.
162
165
  attr_accessor :irb
163
166
  # A copy of the default <code>IRB.conf[:AP_NAME]</code>
164
167
  attr_accessor :ap_name
@@ -185,20 +188,22 @@ module IRB
185
188
  #
186
189
  # A copy of the default <code>IRB.conf[:USE_COLORIZE]</code>
187
190
  attr_reader :use_colorize
191
+ # A copy of the default <code>IRB.conf[:USE_AUTOCOMPLETE]</code>
192
+ attr_reader :use_autocomplete
188
193
  # A copy of the default <code>IRB.conf[:INSPECT_MODE]</code>
189
194
  attr_reader :inspect_mode
190
195
 
191
196
  # A copy of the default <code>IRB.conf[:PROMPT_MODE]</code>
192
197
  attr_reader :prompt_mode
193
- # Standard IRB prompt
198
+ # Standard IRB prompt.
194
199
  #
195
200
  # See IRB@Customizing+the+IRB+Prompt for more information.
196
201
  attr_accessor :prompt_i
197
- # IRB prompt for continuated strings
202
+ # IRB prompt for continuated strings.
198
203
  #
199
204
  # See IRB@Customizing+the+IRB+Prompt for more information.
200
205
  attr_accessor :prompt_s
201
- # IRB prompt for continuated statement (e.g. immediately after an +if+)
206
+ # IRB prompt for continuated statement. (e.g. immediately after an +if+)
202
207
  #
203
208
  # See IRB@Customizing+the+IRB+Prompt for more information.
204
209
  attr_accessor :prompt_c
@@ -238,6 +243,9 @@ module IRB
238
243
  #
239
244
  # If set to +false+, <code>^D</code> will quit irb.
240
245
  attr_accessor :ignore_eof
246
+ # Specify the installation locations of the ri file to be displayed in the
247
+ # document dialog.
248
+ attr_accessor :extra_doc_dirs
241
249
  # Whether to echo the return value to output or not.
242
250
  #
243
251
  # Uses <code>IRB.conf[:ECHO]</code> if available, or defaults to +true+.
@@ -249,7 +257,7 @@ module IRB
249
257
  # puts "omg"
250
258
  # # omg
251
259
  attr_accessor :echo
252
- # Whether to echo for assignment expressions
260
+ # Whether to echo for assignment expressions.
253
261
  #
254
262
  # If set to +false+, the value of assignment will not be shown.
255
263
  #
@@ -261,13 +269,28 @@ module IRB
261
269
  #
262
270
  # a = "omg"
263
271
  # #=> omg
272
+ #
264
273
  # a = "omg" * 10
265
274
  # #=> omgomgomgomgomgomgomg...
275
+ #
266
276
  # IRB.CurrentContext.echo_on_assignment = false
267
277
  # a = "omg"
278
+ #
268
279
  # IRB.CurrentContext.echo_on_assignment = true
269
- # a = "omg"
280
+ # a = "omg" * 10
270
281
  # #=> omgomgomgomgomgomgomgomgomgomg
282
+ #
283
+ # To set the behaviour of showing on assignment in irb:
284
+ #
285
+ # IRB.conf[:ECHO_ON_ASSIGNMENT] = :truncate or true or false
286
+ #
287
+ # or
288
+ #
289
+ # irb_context.echo_on_assignment = :truncate or true or false
290
+ #
291
+ # or
292
+ #
293
+ # IRB.CurrentContext.echo_on_assignment = :truncate or true or false
271
294
  attr_accessor :echo_on_assignment
272
295
  # Whether a newline is put before multiline output.
273
296
  #
@@ -311,6 +334,8 @@ module IRB
311
334
  alias use_readline? use_singleline
312
335
  # Alias for #use_colorize
313
336
  alias use_colorize? use_colorize
337
+ # Alias for #use_autocomplete
338
+ alias use_autocomplete? use_autocomplete
314
339
  # Alias for #rc
315
340
  alias rc? rc
316
341
  alias ignore_sigint? ignore_sigint
@@ -366,6 +391,7 @@ module IRB
366
391
  @prompt_c = pconf[:PROMPT_C]
367
392
  @prompt_n = pconf[:PROMPT_N]
368
393
  @return_format = pconf[:RETURN]
394
+ @return_format = "%s\n" if @return_format == nil
369
395
  if ai = pconf.include?(:AUTO_INDENT)
370
396
  @auto_indent_mode = ai
371
397
  else
@@ -458,6 +484,8 @@ module IRB
458
484
  # Exits the current session, see IRB.irb_exit
459
485
  def exit(ret = 0)
460
486
  IRB.irb_exit(@irb, ret)
487
+ rescue UncaughtThrowError
488
+ super
461
489
  end
462
490
 
463
491
  NOPRINTING_IVARS = ["@last_value"] # :nodoc:
data/lib/irb/init.rb CHANGED
@@ -45,11 +45,13 @@ module IRB # :nodoc:
45
45
 
46
46
  @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
47
47
  @CONF[:USE_COLORIZE] = !ENV['NO_COLOR']
48
+ @CONF[:USE_AUTOCOMPLETE] = true
48
49
  @CONF[:INSPECT_MODE] = true
49
50
  @CONF[:USE_TRACER] = false
50
51
  @CONF[:USE_LOADER] = false
51
52
  @CONF[:IGNORE_SIGINT] = true
52
53
  @CONF[:IGNORE_EOF] = false
54
+ @CONF[:EXTRA_DOC_DIRS] = []
53
55
  @CONF[:ECHO] = nil
54
56
  @CONF[:ECHO_ON_ASSIGNMENT] = nil
55
57
  @CONF[:VERBOSE] = nil
@@ -256,6 +258,9 @@ module IRB # :nodoc:
256
258
  @CONF[:USE_MULTILINE] = true
257
259
  when "--nomultiline", "--noreidline"
258
260
  @CONF[:USE_MULTILINE] = false
261
+ when /^--extra-doc-dir(?:=(.+))?/
262
+ opt = $1 || argv.shift
263
+ @CONF[:EXTRA_DOC_DIRS] << opt
259
264
  when "--echo"
260
265
  @CONF[:ECHO] = true
261
266
  when "--noecho"
@@ -274,6 +279,10 @@ module IRB # :nodoc:
274
279
  @CONF[:USE_COLORIZE] = true
275
280
  when "--nocolorize"
276
281
  @CONF[:USE_COLORIZE] = false
282
+ when "--autocomplete"
283
+ @CONF[:USE_AUTOCOMPLETE] = true
284
+ when "--noautocomplete"
285
+ @CONF[:USE_AUTOCOMPLETE] = false
277
286
  when /^--prompt-mode(?:=(.+))?/, /^--prompt(?:=(.+))?/
278
287
  opt = $1 || argv.shift
279
288
  prompt_mode = opt.upcase.tr("-", "_").intern
@@ -14,6 +14,7 @@ require_relative 'magic-file'
14
14
  require_relative 'completion'
15
15
  require 'io/console'
16
16
  require 'reline'
17
+ require 'rdoc'
17
18
 
18
19
  module IRB
19
20
  STDIN_FILE_NAME = "(line)" # :nodoc:
@@ -264,7 +265,8 @@ module IRB
264
265
 
265
266
  class ReidlineInputMethod < InputMethod
266
267
  include Reline
267
- # Creates a new input method object using Readline
268
+
269
+ # Creates a new input method object using Reline
268
270
  def initialize
269
271
  IRB.__send__(:set_encoding, Reline.encoding_system_needs.name, override: false)
270
272
  super
@@ -294,6 +296,10 @@ module IRB
294
296
  end
295
297
  end
296
298
  Reline.dig_perfect_match_proc = IRB::InputCompletor::PerfectMatchedProc
299
+ Reline.autocompletion = IRB.conf[:USE_AUTOCOMPLETE]
300
+ if IRB.conf[:USE_AUTOCOMPLETE]
301
+ Reline.add_dialog_proc(:show_doc, SHOW_DOC_DIALOG, Reline::DEFAULT_DIALOG_CONTEXT)
302
+ end
297
303
  end
298
304
 
299
305
  def check_termination(&block)
@@ -308,6 +314,99 @@ module IRB
308
314
  @auto_indent_proc = block
309
315
  end
310
316
 
317
+ SHOW_DOC_DIALOG = ->() {
318
+ dialog.trap_key = nil
319
+ alt_d = [
320
+ [Reline::Key.new(nil, 0xE4, true)], # Normal Alt+d.
321
+ [27, 100], # Normal Alt+d when convert-meta isn't used.
322
+ [195, 164], # The "ä" that appears when Alt+d is pressed on xterm.
323
+ [226, 136, 130] # The "∂" that appears when Alt+d in pressed on iTerm2.
324
+ ]
325
+
326
+ if just_cursor_moving and completion_journey_data.nil?
327
+ return nil
328
+ end
329
+ cursor_pos_to_render, result, pointer, autocomplete_dialog = context.pop(4)
330
+ return nil if result.nil? or pointer.nil? or pointer < 0
331
+ name = result[pointer]
332
+ name = IRB::InputCompletor.retrieve_completion_data(name, doc_namespace: true)
333
+
334
+ options = {}
335
+ options[:extra_doc_dirs] = IRB.conf[:EXTRA_DOC_DIRS] unless IRB.conf[:EXTRA_DOC_DIRS].empty?
336
+ driver = RDoc::RI::Driver.new(options)
337
+
338
+ if key.match?(dialog.name)
339
+ begin
340
+ driver.display_names([name])
341
+ rescue RDoc::RI::Driver::NotFoundError
342
+ end
343
+ end
344
+
345
+ begin
346
+ name = driver.expand_name(name)
347
+ rescue RDoc::RI::Driver::NotFoundError
348
+ return nil
349
+ rescue
350
+ return nil # unknown error
351
+ end
352
+ doc = nil
353
+ used_for_class = false
354
+ if not name =~ /#|\./
355
+ found, klasses, includes, extends = driver.classes_and_includes_and_extends_for(name)
356
+ if not found.empty?
357
+ doc = driver.class_document(name, found, klasses, includes, extends)
358
+ used_for_class = true
359
+ end
360
+ end
361
+ unless used_for_class
362
+ doc = RDoc::Markup::Document.new
363
+ begin
364
+ driver.add_method(doc, name)
365
+ rescue RDoc::RI::Driver::NotFoundError
366
+ doc = nil
367
+ rescue
368
+ return nil # unknown error
369
+ end
370
+ end
371
+ return nil if doc.nil?
372
+ width = 40
373
+
374
+ right_x = cursor_pos_to_render.x + autocomplete_dialog.width
375
+ if right_x + width > screen_width
376
+ right_width = screen_width - (right_x + 1)
377
+ left_x = autocomplete_dialog.column - width
378
+ left_x = 0 if left_x < 0
379
+ left_width = width > autocomplete_dialog.column ? autocomplete_dialog.column : width
380
+ if right_width.positive? and left_width.positive?
381
+ if right_width >= left_width
382
+ width = right_width
383
+ x = right_x
384
+ else
385
+ width = left_width
386
+ x = left_x
387
+ end
388
+ elsif right_width.positive? and left_width <= 0
389
+ width = right_width
390
+ x = right_x
391
+ elsif right_width <= 0 and left_width.positive?
392
+ width = left_width
393
+ x = left_x
394
+ else # Both are negative width.
395
+ return nil
396
+ end
397
+ else
398
+ x = right_x
399
+ end
400
+ formatter = RDoc::Markup::ToAnsi.new
401
+ formatter.width = width
402
+ dialog.trap_key = alt_d
403
+ message = 'Press Alt+d to read the full document'
404
+ contents = [message] + doc.accept(formatter).split("\n")
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
+ }
409
+
311
410
  # Reads the next line from this input method.
312
411
  #
313
412
  # See IO#gets for more information.
@@ -20,8 +20,15 @@ Usage: irb.rb [options] [programfile] [arguments]
20
20
  -W[level=2] Same as `ruby -W`
21
21
  --context-mode n Set n[0-4] to method to create Binding Object,
22
22
  when new workspace was created
23
- --echo Show result(default)
23
+ --extra-doc-dir Add an extra doc dir for the doc dialog
24
+ --echo Show result (default)
24
25
  --noecho Don't show result
26
+ --echo-on-assignment
27
+ Show result on assignment
28
+ --noecho-on-assignment
29
+ Don't show result on assignment
30
+ --truncate-echo-on-assignment
31
+ Show truncated result on assignment (default)
25
32
  --inspect Use `inspect' for output
26
33
  --noinspect Don't use inspect for output
27
34
  --multiline Use multiline editor module
@@ -30,6 +37,8 @@ Usage: irb.rb [options] [programfile] [arguments]
30
37
  --nosingleline Don't use singleline editor module
31
38
  --colorize Use colorization
32
39
  --nocolorize Don't use colorization
40
+ --autocomplete Use autocompletion
41
+ --noautocomplete Don't use autocompletion
33
42
  --prompt prompt-mode/--prompt-mode prompt-mode
34
43
  Switch prompt mode. Pre-defined prompt modes are
35
44
  `default', `simple', `xmp' and `inf-ruby'
@@ -29,6 +29,8 @@ Usage: irb.rb [options] [programfile] [arguments]
29
29
  --nosingleline シングルラインエディタを利用しない.
30
30
  --colorize 色付けを利用する.
31
31
  --nocolorize 色付けを利用しない.
32
+ --autocomplete オートコンプリートを利用する.
33
+ --noautocomplete オートコンプリートを利用しない.
32
34
  --prompt prompt-mode/--prompt-mode prompt-mode
33
35
  プロンプトモードを切替えます. 現在定義されているプ
34
36
  ロンプトモードは, default, simple, xmp, inf-rubyが