irb 1.8.3 → 1.13.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.
Files changed (91) hide show
  1. checksums.yaml +4 -4
  2. data/.document +1 -1
  3. data/Gemfile +9 -1
  4. data/README.md +149 -25
  5. data/Rakefile +13 -3
  6. data/irb.gemspec +2 -2
  7. data/lib/irb/cmd/nop.rb +3 -52
  8. data/lib/irb/color.rb +2 -2
  9. data/lib/irb/command/backtrace.rb +17 -0
  10. data/lib/irb/command/base.rb +62 -0
  11. data/lib/irb/command/break.rb +17 -0
  12. data/lib/irb/command/catch.rb +17 -0
  13. data/lib/irb/command/chws.rb +40 -0
  14. data/lib/irb/command/context.rb +16 -0
  15. data/lib/irb/{cmd → command}/continue.rb +3 -3
  16. data/lib/irb/{cmd → command}/debug.rb +11 -20
  17. data/lib/irb/{cmd → command}/delete.rb +3 -3
  18. data/lib/irb/command/disable_irb.rb +19 -0
  19. data/lib/irb/command/edit.rb +63 -0
  20. data/lib/irb/command/exit.rb +18 -0
  21. data/lib/irb/{cmd → command}/finish.rb +3 -3
  22. data/lib/irb/command/force_exit.rb +18 -0
  23. data/lib/irb/command/help.rb +83 -0
  24. data/lib/irb/command/history.rb +45 -0
  25. data/lib/irb/command/info.rb +17 -0
  26. data/lib/irb/command/internal_helpers.rb +27 -0
  27. data/lib/irb/{cmd → command}/irb_info.rb +7 -7
  28. data/lib/irb/{cmd → command}/load.rb +23 -8
  29. data/lib/irb/{cmd → command}/ls.rb +30 -14
  30. data/lib/irb/{cmd → command}/measure.rb +18 -17
  31. data/lib/irb/{cmd → command}/next.rb +3 -3
  32. data/lib/irb/command/pushws.rb +65 -0
  33. data/lib/irb/command/show_doc.rb +51 -0
  34. data/lib/irb/command/show_source.rb +74 -0
  35. data/lib/irb/{cmd → command}/step.rb +3 -3
  36. data/lib/irb/{cmd → command}/subirb.rb +31 -17
  37. data/lib/irb/{cmd → command}/whereami.rb +3 -5
  38. data/lib/irb/command.rb +23 -0
  39. data/lib/irb/completion.rb +74 -31
  40. data/lib/irb/context.rb +144 -57
  41. data/lib/irb/debug.rb +18 -0
  42. data/lib/irb/default_commands.rb +260 -0
  43. data/lib/irb/easter-egg.rb +16 -6
  44. data/lib/irb/ext/change-ws.rb +6 -8
  45. data/lib/irb/ext/eval_history.rb +3 -3
  46. data/lib/irb/ext/loader.rb +4 -4
  47. data/lib/irb/ext/multi-irb.rb +5 -5
  48. data/lib/irb/ext/tracer.rb +12 -51
  49. data/lib/irb/ext/use-loader.rb +6 -8
  50. data/lib/irb/ext/workspaces.rb +10 -34
  51. data/lib/irb/frame.rb +1 -1
  52. data/lib/irb/help.rb +3 -3
  53. data/lib/irb/helper_method/base.rb +16 -0
  54. data/lib/irb/helper_method/conf.rb +11 -0
  55. data/lib/irb/helper_method.rb +29 -0
  56. data/lib/irb/history.rb +15 -4
  57. data/lib/irb/init.rb +119 -52
  58. data/lib/irb/input-method.rb +77 -27
  59. data/lib/irb/inspector.rb +3 -3
  60. data/lib/irb/lc/error.rb +1 -11
  61. data/lib/irb/lc/help-message +4 -0
  62. data/lib/irb/lc/ja/error.rb +1 -11
  63. data/lib/irb/lc/ja/help-message +13 -0
  64. data/lib/irb/locale.rb +2 -2
  65. data/lib/irb/nesting_parser.rb +13 -3
  66. data/lib/irb/notifier.rb +1 -1
  67. data/lib/irb/output-method.rb +2 -8
  68. data/lib/irb/pager.rb +16 -11
  69. data/lib/irb/ruby-lex.rb +2 -2
  70. data/lib/irb/ruby_logo.aa +43 -0
  71. data/lib/irb/source_finder.rb +112 -37
  72. data/lib/irb/statement.rb +24 -24
  73. data/lib/irb/version.rb +3 -3
  74. data/lib/irb/workspace.rb +22 -6
  75. data/lib/irb/ws-for-case-2.rb +1 -1
  76. data/lib/irb/xmp.rb +3 -3
  77. data/lib/irb.rb +1071 -556
  78. data/man/irb.1 +7 -0
  79. metadata +41 -31
  80. data/lib/irb/cmd/backtrace.rb +0 -21
  81. data/lib/irb/cmd/break.rb +0 -21
  82. data/lib/irb/cmd/catch.rb +0 -21
  83. data/lib/irb/cmd/chws.rb +0 -36
  84. data/lib/irb/cmd/edit.rb +0 -60
  85. data/lib/irb/cmd/help.rb +0 -23
  86. data/lib/irb/cmd/info.rb +0 -21
  87. data/lib/irb/cmd/pushws.rb +0 -45
  88. data/lib/irb/cmd/show_cmds.rb +0 -53
  89. data/lib/irb/cmd/show_doc.rb +0 -48
  90. data/lib/irb/cmd/show_source.rb +0 -61
  91. data/lib/irb/extend-command.rb +0 -354
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 332023cd842d367c49ca245616a926f8f8df1f724c16b22d18447f1456710290
4
- data.tar.gz: c6b7ab4d628a6fb766bed6f93b124490b1c364ba79b7ce8c1e4e21d67df64545
3
+ metadata.gz: b57e45ef4cb7d58489abeda8131ed81a1625b05fd139e00082bf3011fc0c2fdc
4
+ data.tar.gz: 411b92eee70de798e94c0c9c30801467cdf240a43eff4da9e46230374fa8504f
5
5
  SHA512:
6
- metadata.gz: 8962b3e7359c4292bb09c75f3a5f1548b5dd53c3053a4a736a0a295c83126b065eca7578a185a0bf218468053399a3f029e47a06860ac69713756fb346945d08
7
- data.tar.gz: '0109b52f17e50b944d5fb3e9e40b432a3a3bafbf45ed9b0dd5725de43527e5ca3926db65b44bf39c646f76c38c4dee07cd2eb8fcb33690dc071dcd4a66b99b87'
6
+ metadata.gz: '0919ac233b97abb80a9d34cad9be792e85bce261cc4c29c36eac8d7ba81bd99c4592b5b8c1bdbdc7e96d778ccf20b5374987eef0224e9fb6583639633e3c2bb0'
7
+ data.tar.gz: 89dad0bbdebdee60a3f08ca2cf918293bffac4db7b183a45ab93f6cc4906ca7a62437286a08291ba76fae8e2bba31f3b6a28be3cd13a141f451a5c4e1b09041d
data/.document CHANGED
@@ -1,4 +1,4 @@
1
1
  LICENSE.txt
2
2
  README.md
3
- doc
3
+ doc/irb/indexes.md
4
4
  lib/**/*.rb
data/Gemfile CHANGED
@@ -16,4 +16,12 @@ gem "reline", github: "ruby/reline" if ENV["WITH_LATEST_RELINE"] == "true"
16
16
  gem "rake"
17
17
  gem "test-unit"
18
18
  gem "test-unit-ruby-core"
19
- gem "debug", github: "ruby/debug"
19
+
20
+ gem "rubocop"
21
+
22
+ gem "tracer" if !is_truffleruby
23
+ gem "debug", github: "ruby/debug", platforms: [:mri, :mswin]
24
+
25
+ if RUBY_VERSION >= "3.0.0" && !is_truffleruby
26
+ gem "repl_type_completor"
27
+ end
data/README.md CHANGED
@@ -15,6 +15,10 @@ The `irb` command from your shell will start the interpreter.
15
15
  - [Debugging with IRB](#debugging-with-irb)
16
16
  - [More about `debug.gem`](#more-about-debuggem)
17
17
  - [Advantages Over `debug.gem`'s Console](#advantages-over-debuggems-console)
18
+ - [Type Based Completion](#type-based-completion)
19
+ - [How to Enable IRB::TypeCompletor](#how-to-enable-irbtypecompletor)
20
+ - [Advantage over Default IRB::RegexpCompletor](#advantage-over-default-irbregexpcompletor)
21
+ - [Difference between Steep's Completion](#difference-between-steeps-completion)
18
22
  - [Configuration](#configuration)
19
23
  - [Environment Variables](#environment-variables)
20
24
  - [Documentation](#documentation)
@@ -26,7 +30,7 @@ The `irb` command from your shell will start the interpreter.
26
30
 
27
31
  ## Installation
28
32
 
29
- > **Note**
33
+ > [!Note]
30
34
  >
31
35
  > IRB is a default gem of Ruby so you shouldn't need to install it separately.
32
36
  >
@@ -52,6 +56,10 @@ $ gem install irb
52
56
 
53
57
  ## Usage
54
58
 
59
+ > [!Note]
60
+ >
61
+ > We're working hard to match Pry's variety of powerful features in IRB, and you can track our progress or find contribution ideas in [this document](https://github.com/ruby/irb/blob/master/COMPARED_WITH_PRY.md).
62
+
55
63
  ### The `irb` Executable
56
64
 
57
65
  You can start a fresh IRB session by typing `irb` in your terminal.
@@ -99,22 +107,27 @@ Hello World
99
107
 
100
108
  ## Commands
101
109
 
102
- The following commands are available on IRB. You can get the same output from the `show_cmds` command.
110
+ The following commands are available on IRB. You can get the same output from the `help` command.
103
111
 
104
- ```
105
- Workspace
106
- cwws Show the current workspace.
107
- chws Change the current workspace to an object.
108
- workspaces Show workspaces.
109
- pushws Push an object to the workspace stack.
110
- popws Pop a workspace from the workspace stack.
112
+ ```txt
113
+ Help
114
+ help List all available commands. Use `help <command>` to get information about a specific command.
111
115
 
112
116
  IRB
117
+ exit Exit the current irb session.
118
+ exit! Exit the current process.
113
119
  irb_load Load a Ruby file.
114
120
  irb_require Require a Ruby file.
115
121
  source Loads a given file in the current session.
116
122
  irb_info Show information about IRB.
117
- show_cmds List all available commands and their description.
123
+ history Shows the input history. `-g [query]` or `-G [query]` allows you to filter the output.
124
+
125
+ Workspace
126
+ cwws Show the current workspace.
127
+ chws Change the current workspace to an object.
128
+ workspaces Show workspaces.
129
+ pushws Push an object to the workspace stack.
130
+ popws Pop a workspace from the workspace stack.
118
131
 
119
132
  Multi-irb (DEPRECATED)
120
133
  irb Start a child IRB.
@@ -135,15 +148,18 @@ Debugging
135
148
  info Start the debugger of debug.gem and run its `info` command.
136
149
 
137
150
  Misc
138
- edit Open a file with the editor command defined with `ENV["VISUAL"]` or `ENV["EDITOR"]`.
151
+ edit Open a file or source location.
139
152
  measure `measure` enables the mode to measure processing time. `measure :off` disables it.
140
153
 
141
154
  Context
142
- help [DEPRECATED] Enter the mode to look up RI documents.
143
155
  show_doc Enter the mode to look up RI documents.
144
- ls Show methods, constants, and variables. `-g [query]` or `-G [query]` allows you to filter out the output.
156
+ ls Show methods, constants, and variables.
145
157
  show_source Show the source code of a given method or constant.
146
158
  whereami Show the source code around binding.irb again.
159
+
160
+ Aliases
161
+ $ Alias for `show_source`
162
+ @ Alias for `whereami`
147
163
  ```
148
164
 
149
165
  ## Debugging with IRB
@@ -213,7 +229,7 @@ end
213
229
 
214
230
  To learn about these features, please refer to `debug.gem`'s [commands list](https://github.com/ruby/debug#debug-command-on-the-debug-console).
215
231
 
216
- In the `irb:rdbg` session, the `show_cmds` command will also display all commands from `debug.gem`.
232
+ In the `irb:rdbg` session, the `help` command will also display all commands from `debug.gem`.
217
233
 
218
234
  ### Advantages Over `debug.gem`'s Console
219
235
 
@@ -231,33 +247,117 @@ However, there are also some limitations to be aware of:
231
247
  2. As IRB [doesn't currently support remote-connection](https://github.com/ruby/irb/issues/672), it can't be used with `debug.gem`'s remote debugging feature.
232
248
  3. Access to the previous return value via the underscore `_` is not supported.
233
249
 
250
+ ## Type Based Completion
251
+
252
+ IRB's default completion `IRB::RegexpCompletor` uses Regexp. IRB has another experimental completion `IRB::TypeCompletor` that uses type analysis.
253
+
254
+ ### How to Enable IRB::TypeCompletor
255
+
256
+ Install [ruby/repl_type_completor](https://github.com/ruby/repl_type_completor/) with:
257
+ ```
258
+ $ gem install repl_type_completor
259
+ ```
260
+ Or add these lines to your project's Gemfile.
261
+ ```ruby
262
+ gem 'irb'
263
+ gem 'repl_type_completor', group: [:development, :test]
264
+ ```
265
+
266
+ Now you can use type based completion by:
267
+
268
+ Running IRB with the `--type-completor` option
269
+ ```
270
+ $ irb --type-completor
271
+ ```
272
+
273
+ Or writing this line to IRB's rc-file (e.g. `~/.irbrc`)
274
+ ```ruby
275
+ IRB.conf[:COMPLETOR] = :type # default is :regexp
276
+ ```
277
+
278
+ Or setting the environment variable `IRB_COMPLETOR`
279
+ ```ruby
280
+ ENV['IRB_COMPLETOR'] = 'type'
281
+ IRB.start
282
+ ```
283
+
284
+ To check if it's enabled, type `irb_info` into IRB and see the `Completion` section.
285
+ ```
286
+ irb(main):001> irb_info
287
+ ...
288
+ # Enabled
289
+ Completion: Autocomplete, ReplTypeCompletor: 0.1.0, Prism: 0.18.0, RBS: 3.3.0
290
+ # Not enabled
291
+ Completion: Autocomplete, RegexpCompletor
292
+ ...
293
+ ```
294
+ If you have `sig/` directory or `rbs_collection.lock.yaml` in current directory, IRB will load it.
295
+
296
+ ### Advantage over Default IRB::RegexpCompletor
297
+
298
+ IRB::TypeCompletor can autocomplete chained methods, block parameters and more if type information is available.
299
+ These are some examples IRB::RegexpCompletor cannot complete.
300
+
301
+ ```ruby
302
+ irb(main):001> 'Ruby'.upcase.chars.s # Array methods (sample, select, shift, size)
303
+ ```
304
+
305
+ ```ruby
306
+ irb(main):001> 10.times.map(&:to_s).each do |s|
307
+ irb(main):002> s.up # String methods (upcase, upcase!, upto)
308
+ ```
309
+
310
+ ```ruby
311
+ irb(main):001> class User < ApplicationRecord
312
+ irb(main):002> def foo
313
+ irb(main):003> sa # save, save!
314
+ ```
315
+
316
+ As a trade-off, completion calculation takes more time than IRB::RegexpCompletor.
317
+
318
+ ### Difference between Steep's Completion
319
+
320
+ Compared with Steep, IRB::TypeCompletor has some difference and limitations.
321
+ ```ruby
322
+ [0, 'a'].sample.
323
+ # Steep completes intersection of Integer methods and String methods
324
+ # IRB::TypeCompletor completes both Integer and String methods
325
+ ```
326
+
327
+ Some features like type narrowing is not implemented.
328
+ ```ruby
329
+ def f(arg = [0, 'a'].sample)
330
+ if arg.is_a?(String)
331
+ arg. # Completes both Integer and String methods
332
+ ```
333
+
334
+ Unlike other static type checker, IRB::TypeCompletor uses runtime information to provide better completion.
335
+ ```ruby
336
+ irb(main):001> a = [1]
337
+ => [1]
338
+ irb(main):002> a.first. # Completes Integer methods
339
+ ```
340
+
234
341
  ## Configuration
235
342
 
236
343
  ### Environment Variables
237
344
 
238
345
  - `NO_COLOR`: Assigning a value to it disables IRB's colorization.
239
346
  - `IRB_USE_AUTOCOMPLETE`: Setting it to `false` disables IRB's autocompletion.
347
+ - `IRB_COMPLETOR`: Configures IRB's auto-completion behavior, allowing settings for either `regexp` or `type`.
240
348
  - `VISUAL`: Its value would be used to open files by the `edit` command.
241
349
  - `EDITOR`: Its value would be used to open files by the `edit` command if `VISUAL` is unset.
242
350
  - `IRBRC`: The file specified would be evaluated as IRB's rc-file.
243
351
 
244
352
  ## Documentation
245
353
 
246
- https://docs.ruby-lang.org/en/master/IRB.html
354
+ https://ruby.github.io/irb/
247
355
 
248
356
  ## Extending IRB
249
357
 
250
- IRB is currently going through some refactoring to bring in some cool improvements and make things more flexible for developers.
251
- We know that in the past, due to a lack of public APIs and documentation, many of you have had to use IRB's private APIs
252
- and components to extend it. We also know that changes can be a bit annoying and might mess with your current setup.
253
-
254
- We're sorry if this causes a bit of a scramble. We're working hard to make IRB better and your input is super important to us.
255
- If you've been using private APIs or components in your projects, we'd love to hear about your use cases. Please feel free to file a new issue. Your feedback will be a massive help in guiding us on how to design and prioritize the development of official APIs in the future.
358
+ IRB `v1.13.0` and later versions allows users/libraries to extend its functionality through official APIs.
256
359
 
257
- Right now, we've got command extension APIs on the drawing board, as you can see in [#513](https://github.com/ruby/irb/issues/513).
258
- We've also got a prototype for helper method extension APIs in the works, as shown in [#588](https://github.com/ruby/irb/issues/588).
259
-
260
- We really appreciate your understanding and patience during this transition. We're pretty excited about the improvements these changes will bring to the IRB ecosystem and we hope you are too!
360
+ For more information, please visit [EXTEND_IRB.md](./EXTEND_IRB.md).
261
361
 
262
362
  ## Development
263
363
 
@@ -269,6 +369,30 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
269
369
 
270
370
  Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/irb.
271
371
 
372
+ ### Set up the environment
373
+
374
+ 1. Fork the project to your GithHub account
375
+ 2. Clone the fork with `git clone git@github.com:[your_username]/irb.git`
376
+ 3. Run `bundle install`
377
+ 4. Run `bundle exec rake` to make sure tests pass locally
378
+
379
+ ### Run integration tests
380
+
381
+ If your changes affect component rendering, such as the autocompletion's dialog/dropdown, you may need to run IRB's integration tests, known as `yamatanooroti`.
382
+
383
+ Before running these tests, ensure that you have `libvterm` installed. If you're using Homebrew, you can install it by running:
384
+
385
+ ```bash
386
+ brew install libvterm
387
+ ```
388
+
389
+ After installing `libvterm`, you can run the integration tests using the following commands:
390
+
391
+ ```bash
392
+ WITH_VTERM=1 bundle install
393
+ WITH_VTERM=1 bundle exec rake test test_yamatanooroti
394
+ ```
395
+
272
396
  ## Releasing
273
397
 
274
398
  ```
data/Rakefile CHANGED
@@ -1,11 +1,12 @@
1
1
  require "bundler/gem_tasks"
2
2
  require "rake/testtask"
3
+ require "rdoc/task"
3
4
 
4
5
  Rake::TestTask.new(:test) do |t|
5
6
  t.libs << "test" << "test/lib"
6
7
  t.libs << "lib"
7
8
  t.ruby_opts << "-rhelper"
8
- t.test_files = FileList["test/irb/test_*.rb"]
9
+ t.test_files = FileList["test/irb/**/test_*.rb"]
9
10
  end
10
11
 
11
12
  # To make sure they have been correctly setup for Ruby CI.
@@ -13,11 +14,11 @@ desc "Run each irb test file in isolation."
13
14
  task :test_in_isolation do
14
15
  failed = false
15
16
 
16
- FileList["test/irb/test_*.rb"].each do |test_file|
17
+ FileList["test/irb/**/test_*.rb"].each do |test_file|
17
18
  ENV["TEST"] = test_file
18
19
  begin
19
20
  Rake::Task["test"].execute
20
- rescue => e
21
+ rescue
21
22
  failed = true
22
23
  msg = "Test '#{test_file}' failed when being executed in isolation. Please make sure 'rake test TEST=#{test_file}' passes."
23
24
  separation_line = '=' * msg.length
@@ -42,3 +43,12 @@ Rake::TestTask.new(:test_yamatanooroti) do |t|
42
43
  end
43
44
 
44
45
  task :default => :test
46
+
47
+ RDoc::Task.new do |rdoc|
48
+ rdoc.title = "IRB"
49
+ rdoc.rdoc_files.include("*.md", "lib/**/*.rb")
50
+ rdoc.rdoc_files.exclude("lib/irb/xmp.rb")
51
+ rdoc.rdoc_dir = "docs"
52
+ rdoc.main = "README.md"
53
+ rdoc.options.push("--copy-files", "LICENSE.txt")
54
+ end
data/irb.gemspec CHANGED
@@ -41,6 +41,6 @@ Gem::Specification.new do |spec|
41
41
 
42
42
  spec.required_ruby_version = Gem::Requirement.new(">= 2.7")
43
43
 
44
- spec.add_dependency "reline", ">= 0.3.8"
45
- spec.add_dependency "rdoc"
44
+ spec.add_dependency "reline", ">= 0.4.2"
45
+ spec.add_dependency "rdoc", ">= 4.0.0"
46
46
  end
data/lib/irb/cmd/nop.rb CHANGED
@@ -1,53 +1,4 @@
1
- # frozen_string_literal: false
2
- #
3
- # nop.rb -
4
- # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
- #
1
+ # frozen_string_literal: true
6
2
 
7
- module IRB
8
- # :stopdoc:
9
-
10
- module ExtendCommand
11
- class CommandArgumentError < StandardError; end
12
-
13
- class Nop
14
- class << self
15
- def category(category = nil)
16
- @category = category if category
17
- @category
18
- end
19
-
20
- def description(description = nil)
21
- @description = description if description
22
- @description
23
- end
24
-
25
- private
26
-
27
- def string_literal?(args)
28
- sexp = Ripper.sexp(args)
29
- sexp && sexp.size == 2 && sexp.last&.first&.first == :string_literal
30
- end
31
- end
32
-
33
- def self.execute(irb_context, *opts, **kwargs, &block)
34
- command = new(irb_context)
35
- command.execute(*opts, **kwargs, &block)
36
- rescue CommandArgumentError => e
37
- puts e.message
38
- end
39
-
40
- def initialize(irb_context)
41
- @irb_context = irb_context
42
- end
43
-
44
- attr_reader :irb_context
45
-
46
- def execute(*opts)
47
- #nop
48
- end
49
- end
50
- end
51
-
52
- # :startdoc:
53
- end
3
+ # This file is just a placeholder for backward-compatibility.
4
+ # Please require 'irb' and inherit your command from `IRB::Command::Base` instead.
data/lib/irb/color.rb CHANGED
@@ -79,12 +79,12 @@ module IRB # :nodoc:
79
79
 
80
80
  class << self
81
81
  def colorable?
82
- supported = $stdout.tty? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
82
+ supported = $stdout.tty? && (/mswin|mingw/.match?(RUBY_PLATFORM) || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
83
83
 
84
84
  # because ruby/debug also uses irb's color module selectively,
85
85
  # irb won't be activated in that case.
86
86
  if IRB.respond_to?(:conf)
87
- supported && IRB.conf.fetch(:USE_COLORIZE, true)
87
+ supported && !!IRB.conf.fetch(:USE_COLORIZE, true)
88
88
  else
89
89
  supported
90
90
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module Command
9
+ class Backtrace < DebugCommand
10
+ def execute(arg)
11
+ execute_debug_command(pre_cmds: "backtrace #{arg}")
12
+ end
13
+ end
14
+ end
15
+
16
+ # :startdoc:
17
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # nop.rb -
4
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
+ #
6
+
7
+ module IRB
8
+ # :stopdoc:
9
+
10
+ module Command
11
+ class CommandArgumentError < StandardError; end
12
+
13
+ def self.extract_ruby_args(*args, **kwargs)
14
+ throw :EXTRACT_RUBY_ARGS, [args, kwargs]
15
+ end
16
+
17
+ class Base
18
+ class << self
19
+ def category(category = nil)
20
+ @category = category if category
21
+ @category || "No category"
22
+ end
23
+
24
+ def description(description = nil)
25
+ @description = description if description
26
+ @description || "No description provided."
27
+ end
28
+
29
+ def help_message(help_message = nil)
30
+ @help_message = help_message if help_message
31
+ @help_message
32
+ end
33
+
34
+ private
35
+
36
+ def highlight(text)
37
+ Color.colorize(text, [:BOLD, :BLUE])
38
+ end
39
+ end
40
+
41
+ def self.execute(irb_context, arg)
42
+ new(irb_context).execute(arg)
43
+ rescue CommandArgumentError => e
44
+ puts e.message
45
+ end
46
+
47
+ def initialize(irb_context)
48
+ @irb_context = irb_context
49
+ end
50
+
51
+ attr_reader :irb_context
52
+
53
+ def execute(arg)
54
+ #nop
55
+ end
56
+ end
57
+
58
+ Nop = Base
59
+ end
60
+
61
+ # :startdoc:
62
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module Command
9
+ class Break < DebugCommand
10
+ def execute(arg)
11
+ execute_debug_command(pre_cmds: "break #{arg}")
12
+ end
13
+ end
14
+ end
15
+
16
+ # :startdoc:
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "debug"
4
+
5
+ module IRB
6
+ # :stopdoc:
7
+
8
+ module Command
9
+ class Catch < DebugCommand
10
+ def execute(arg)
11
+ execute_debug_command(pre_cmds: "catch #{arg}")
12
+ end
13
+ end
14
+ end
15
+
16
+ # :startdoc:
17
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+ #
3
+ # change-ws.rb -
4
+ # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
+ #
6
+ require_relative "../ext/change-ws"
7
+
8
+ module IRB
9
+ # :stopdoc:
10
+
11
+ module Command
12
+
13
+ class CurrentWorkingWorkspace < Base
14
+ category "Workspace"
15
+ description "Show the current workspace."
16
+
17
+ def execute(_arg)
18
+ puts "Current workspace: #{irb_context.main}"
19
+ end
20
+ end
21
+
22
+ class ChangeWorkspace < Base
23
+ category "Workspace"
24
+ description "Change the current workspace to an object."
25
+
26
+ def execute(arg)
27
+ if arg.empty?
28
+ irb_context.change_workspace
29
+ else
30
+ obj = eval(arg, irb_context.workspace.binding)
31
+ irb_context.change_workspace(obj)
32
+ end
33
+
34
+ puts "Current workspace: #{irb_context.main}"
35
+ end
36
+ end
37
+ end
38
+
39
+ # :startdoc:
40
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module IRB
4
+ module Command
5
+ class Context < Base
6
+ category "IRB"
7
+ description "Displays current configuration."
8
+
9
+ def execute(_arg)
10
+ # This command just displays the configuration.
11
+ # Modifying the configuration is achieved by sending a message to IRB.conf.
12
+ Pager.page_content(IRB.CurrentContext.inspect)
13
+ end
14
+ end
15
+ end
16
+ end
@@ -5,10 +5,10 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Continue < DebugCommand
10
- def execute(*args)
11
- super(do_cmds: ["continue", *args].join(" "))
10
+ def execute(arg)
11
+ execute_debug_command(do_cmds: "continue #{arg}")
12
12
  end
13
13
  end
14
14
  end
@@ -1,20 +1,21 @@
1
- require_relative "nop"
2
1
  require_relative "../debug"
3
2
 
4
3
  module IRB
5
4
  # :stopdoc:
6
5
 
7
- module ExtendCommand
8
- class Debug < Nop
6
+ module Command
7
+ class Debug < Base
9
8
  category "Debugging"
10
9
  description "Start the debugger of debug.gem."
11
10
 
12
- BINDING_IRB_FRAME_REGEXPS = [
13
- '<internal:prelude>',
14
- binding.method(:irb).source_location.first,
15
- ].map { |file| /\A#{Regexp.escape(file)}:\d+:in `irb'\z/ }
11
+ def execute(_arg)
12
+ execute_debug_command
13
+ end
14
+
15
+ def execute_debug_command(pre_cmds: nil, do_cmds: nil)
16
+ pre_cmds = pre_cmds&.rstrip
17
+ do_cmds = do_cmds&.rstrip
16
18
 
17
- def execute(pre_cmds: nil, do_cmds: nil)
18
19
  if irb_context.with_debugger
19
20
  # If IRB is already running with a debug session, throw the command and IRB.debug_readline will pass it to the debugger.
20
21
  if cmd = pre_cmds || do_cmds
@@ -30,8 +31,8 @@ module IRB
30
31
  # 3. Insert a debug breakpoint at `Irb#debug_break` with the intended command.
31
32
  # 4. Exit the current Irb#run call via `throw :IRB_EXIT`.
32
33
  # 5. `Irb#debug_break` will be called and trigger the breakpoint, which will run the intended command.
33
- unless binding_irb?
34
- puts "`debug` command is only available when IRB is started with binding.irb"
34
+ unless irb_context.from_binding?
35
+ puts "Debugging commands are only available when IRB is started with binding.irb"
35
36
  return
36
37
  end
37
38
 
@@ -54,16 +55,6 @@ module IRB
54
55
  throw :IRB_EXIT
55
56
  end
56
57
  end
57
-
58
- private
59
-
60
- def binding_irb?
61
- caller.any? do |frame|
62
- BINDING_IRB_FRAME_REGEXPS.any? do |regexp|
63
- frame.match?(regexp)
64
- end
65
- end
66
- end
67
58
  end
68
59
 
69
60
  class DebugCommand < Debug
@@ -5,10 +5,10 @@ require_relative "debug"
5
5
  module IRB
6
6
  # :stopdoc:
7
7
 
8
- module ExtendCommand
8
+ module Command
9
9
  class Delete < DebugCommand
10
- def execute(*args)
11
- super(pre_cmds: ["delete", *args].join(" "))
10
+ def execute(arg)
11
+ execute_debug_command(pre_cmds: "delete #{arg}")
12
12
  end
13
13
  end
14
14
  end