irb 1.7.1 → 1.13.2

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.
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,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/lc/ja/error.rb -
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -12,11 +12,6 @@ module IRB
12
12
  super("スイッチ(#{val})が分りません")
13
13
  end
14
14
  end
15
- class NotImplementedError < StandardError
16
- def initialize(val)
17
- super("`#{val}'の定義が必要です")
18
- end
19
- end
20
15
  class CantReturnToNormalMode < StandardError
21
16
  def initialize
22
17
  super("Normalモードに戻れません.")
@@ -52,11 +47,6 @@ module IRB
52
47
  super("プロンプトモード(#{val})は定義されていません.")
53
48
  end
54
49
  end
55
- class IllegalRCGenerator < StandardError
56
- def initialize
57
- super("RC_NAME_GENERATORが正しく定義されていません.")
58
- end
59
- end
60
50
 
61
51
  # :startdoc:
62
52
  end
@@ -9,10 +9,18 @@ Usage: irb.rb [options] [programfile] [arguments]
9
9
  -W[level=2] ruby -W と同じ.
10
10
  --context-mode n 新しいワークスペースを作成した時に関連する Binding
11
11
  オブジェクトの作成方法を 0 から 3 のいずれかに設定する.
12
+ --extra-doc-dir 指定したディレクトリのドキュメントを追加で読み込む.
12
13
  --echo 実行結果を表示する(デフォルト).
13
14
  --noecho 実行結果を表示しない.
15
+ --echo-on-assignment
16
+ 代入結果を表示する.
17
+ --noecho-on-assignment
18
+ 代入結果を表示しない.
19
+ --truncate-echo-on-assignment
20
+ truncateされた代入結果を表示する(デフォルト).
14
21
  --inspect 結果出力にinspectを用いる.
15
22
  --noinspect 結果出力にinspectを用いない.
23
+ --no-pager ページャを使用しない.
16
24
  --multiline マルチラインエディタを利用する.
17
25
  --nomultiline マルチラインエディタを利用しない.
18
26
  --singleline シングルラインエディタを利用する.
@@ -21,6 +29,9 @@ Usage: irb.rb [options] [programfile] [arguments]
21
29
  --nocolorize 色付けを利用しない.
22
30
  --autocomplete オートコンプリートを利用する.
23
31
  --noautocomplete オートコンプリートを利用しない.
32
+ --regexp-completor
33
+ 補完に正規表現を利用する.
34
+ --type-completor 補完に型情報を利用する.
24
35
  --prompt prompt-mode/--prompt-mode prompt-mode
25
36
  プロンプトモードを切替えます. 現在定義されているプ
26
37
  ロンプトモードは, default, simple, xmp, inf-rubyが
@@ -31,6 +42,8 @@ Usage: irb.rb [options] [programfile] [arguments]
31
42
  --sample-book-mode/--simple-prompt
32
43
  非常にシンプルなプロンプトを用いるモードです.
33
44
  --noprompt プロンプト表示を行なわない.
45
+ --script スクリプトモード(最初の引数をスクリプトファイルとして扱う、デフォルト)
46
+ --noscript 引数をargvとして扱う.
34
47
  --single-irb irb 中で self を実行して得られるオブジェクトをサ
35
48
  ブ irb と共有する.
36
49
  --tracer コマンド実行時にトレースを行なう.
data/lib/irb/locale.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # irb/locale.rb - internationalization module
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -94,7 +94,7 @@ module IRB # :nodoc:
94
94
  end
95
95
  end
96
96
 
97
- def find(file , paths = $:)
97
+ def find(file, paths = $:)
98
98
  dir = File.dirname(file)
99
99
  dir = "" if dir == "."
100
100
  base = File.basename(file)
@@ -12,6 +12,8 @@ module IRB
12
12
  skip = false
13
13
  last_tok, state, args = opens.last
14
14
  case state
15
+ when :in_alias_undef
16
+ skip = t.event == :on_kw
15
17
  when :in_unquoted_symbol
16
18
  unless IGNORE_TOKENS.include?(t.event)
17
19
  opens.pop
@@ -61,17 +63,17 @@ module IRB
61
63
  if args.include?(:arg)
62
64
  case t.event
63
65
  when :on_nl, :on_semicolon
64
- # def recever.f;
66
+ # def receiver.f;
65
67
  body = :normal
66
68
  when :on_lparen
67
- # def recever.f()
69
+ # def receiver.f()
68
70
  next_args << :eq
69
71
  else
70
72
  if t.event == :on_op && t.tok == '='
71
73
  # def receiver.f =
72
74
  body = :oneliner
73
75
  else
74
- # def recever.f arg
76
+ # def receiver.f arg
75
77
  next_args << :arg_without_paren
76
78
  end
77
79
  end
@@ -130,6 +132,10 @@ module IRB
130
132
  opens.pop
131
133
  opens << [t, nil]
132
134
  end
135
+ when 'alias'
136
+ opens << [t, :in_alias_undef, 2]
137
+ when 'undef'
138
+ opens << [t, :in_alias_undef, 1]
133
139
  when 'elsif', 'else', 'when'
134
140
  opens.pop
135
141
  opens << [t, nil]
@@ -174,6 +180,10 @@ module IRB
174
180
  pending_heredocs.reverse_each { |t| opens << [t, nil] }
175
181
  pending_heredocs = []
176
182
  end
183
+ if opens.last && opens.last[1] == :in_alias_undef && !IGNORE_TOKENS.include?(t.event) && t.event != :on_heredoc_end
184
+ tok, state, arg = opens.pop
185
+ opens << [tok, state, arg - 1] if arg >= 1
186
+ end
177
187
  yield t, opens if block_given?
178
188
  end
179
189
  opens.map(&:first) + pending_heredocs.reverse
data/lib/irb/notifier.rb CHANGED
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # notifier.rb - output methods used by irb
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -1,4 +1,4 @@
1
- # frozen_string_literal: false
1
+ # frozen_string_literal: true
2
2
  #
3
3
  # output-method.rb - output methods used by irb
4
4
  # by Keiju ISHITSUKA(keiju@ruby-lang.org)
@@ -9,16 +9,10 @@ module IRB
9
9
  # IRB::Notifier. You can define your own output method to use with Irb.new,
10
10
  # or Context.new
11
11
  class OutputMethod
12
- class NotImplementedError < StandardError
13
- def initialize(val)
14
- super("Need to define `#{val}'")
15
- end
16
- end
17
-
18
12
  # Open this method to implement your own output method, raises a
19
13
  # NotImplementedError if you don't define #print in your own class.
20
14
  def print(*opts)
21
- raise NotImplementedError, "print"
15
+ raise NotImplementedError
22
16
  end
23
17
 
24
18
  # Prints the given +opts+, with a newline delimiter.
data/lib/irb/pager.rb ADDED
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ # The implementation of this class is borrowed from RDoc's lib/rdoc/ri/driver.rb.
5
+ # Please do NOT use this class directly outside of IRB.
6
+ class Pager
7
+ PAGE_COMMANDS = [ENV['RI_PAGER'], ENV['PAGER'], 'less', 'more'].compact.uniq
8
+
9
+ class << self
10
+ def page_content(content, **options)
11
+ if content_exceeds_screen_height?(content)
12
+ page(**options) do |io|
13
+ io.puts content
14
+ end
15
+ else
16
+ $stdout.puts content
17
+ end
18
+ end
19
+
20
+ def page(retain_content: false)
21
+ if should_page? && pager = setup_pager(retain_content: retain_content)
22
+ begin
23
+ pid = pager.pid
24
+ yield pager
25
+ ensure
26
+ pager.close
27
+ end
28
+ else
29
+ yield $stdout
30
+ end
31
+ # When user presses Ctrl-C, IRB would raise `IRB::Abort`
32
+ # But since Pager is implemented by running paging commands like `less` in another process with `IO.popen`,
33
+ # the `IRB::Abort` exception only interrupts IRB's execution but doesn't affect the pager
34
+ # So to properly terminate the pager with Ctrl-C, we need to catch `IRB::Abort` and kill the pager process
35
+ rescue IRB::Abort
36
+ Process.kill("TERM", pid) if pid
37
+ nil
38
+ rescue Errno::EPIPE
39
+ end
40
+
41
+ private
42
+
43
+ def should_page?
44
+ IRB.conf[:USE_PAGER] && STDIN.tty? && (ENV.key?("TERM") && ENV["TERM"] != "dumb")
45
+ end
46
+
47
+ def content_exceeds_screen_height?(content)
48
+ screen_height, screen_width = begin
49
+ Reline.get_screen_size
50
+ rescue Errno::EINVAL
51
+ [24, 80]
52
+ end
53
+
54
+ pageable_height = screen_height - 3 # leave some space for previous and the current prompt
55
+
56
+ # If the content has more lines than the pageable height
57
+ content.lines.count > pageable_height ||
58
+ # Or if the content is a few long lines
59
+ pageable_height * screen_width < Reline::Unicode.calculate_width(content, true)
60
+ end
61
+
62
+ def setup_pager(retain_content:)
63
+ require 'shellwords'
64
+
65
+ PAGE_COMMANDS.each do |pager_cmd|
66
+ cmd = Shellwords.split(pager_cmd)
67
+ next if cmd.empty?
68
+
69
+ if cmd.first == 'less'
70
+ cmd << '-R' unless cmd.include?('-R')
71
+ cmd << '-X' if retain_content && !cmd.include?('-X')
72
+ end
73
+
74
+ begin
75
+ io = IO.popen(cmd, 'w')
76
+ rescue
77
+ next
78
+ end
79
+
80
+ if $? && $?.pid == io.pid && $?.exited? # pager didn't work
81
+ next
82
+ end
83
+
84
+ return io
85
+ end
86
+
87
+ nil
88
+ end
89
+ end
90
+ end
91
+ end