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
data/man/irb.1 CHANGED
@@ -140,6 +140,13 @@ Use autocompletion.
140
140
  Don't use autocompletion.
141
141
  .Pp
142
142
  .Pp
143
+ .It Fl -regexp-completor
144
+ Use regexp based completion.
145
+ .Pp
146
+ .It Fl -type-completor
147
+ Use type based completion.
148
+ .Pp
149
+ .Pp
143
150
  .It Fl -verbose
144
151
  Show details.
145
152
  .Pp
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - aycabta
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2023-07-02 00:00:00.000000000 Z
12
+ date: 2024-06-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: reline
@@ -17,14 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: 0.3.0
20
+ version: 0.4.2
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: 0.3.0
27
+ version: 0.4.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: rdoc
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 4.0.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: 4.0.0
28
42
  description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
29
43
  email:
30
44
  - aycabta@gmail.com
@@ -46,46 +60,58 @@ files:
46
60
  - exe/irb
47
61
  - irb.gemspec
48
62
  - lib/irb.rb
49
- - lib/irb/cmd/backtrace.rb
50
- - lib/irb/cmd/break.rb
51
- - lib/irb/cmd/catch.rb
52
- - lib/irb/cmd/chws.rb
53
- - lib/irb/cmd/continue.rb
54
- - lib/irb/cmd/debug.rb
55
- - lib/irb/cmd/delete.rb
56
- - lib/irb/cmd/edit.rb
57
- - lib/irb/cmd/finish.rb
58
- - lib/irb/cmd/help.rb
59
- - lib/irb/cmd/info.rb
60
- - lib/irb/cmd/irb_info.rb
61
- - lib/irb/cmd/load.rb
62
- - lib/irb/cmd/ls.rb
63
- - lib/irb/cmd/measure.rb
64
- - lib/irb/cmd/next.rb
65
63
  - lib/irb/cmd/nop.rb
66
- - lib/irb/cmd/pushws.rb
67
- - lib/irb/cmd/show_cmds.rb
68
- - lib/irb/cmd/show_doc.rb
69
- - lib/irb/cmd/show_source.rb
70
- - lib/irb/cmd/step.rb
71
- - lib/irb/cmd/subirb.rb
72
- - lib/irb/cmd/whereami.rb
73
64
  - lib/irb/color.rb
74
65
  - lib/irb/color_printer.rb
66
+ - lib/irb/command.rb
67
+ - lib/irb/command/backtrace.rb
68
+ - lib/irb/command/base.rb
69
+ - lib/irb/command/break.rb
70
+ - lib/irb/command/catch.rb
71
+ - lib/irb/command/chws.rb
72
+ - lib/irb/command/context.rb
73
+ - lib/irb/command/continue.rb
74
+ - lib/irb/command/debug.rb
75
+ - lib/irb/command/delete.rb
76
+ - lib/irb/command/disable_irb.rb
77
+ - lib/irb/command/edit.rb
78
+ - lib/irb/command/exit.rb
79
+ - lib/irb/command/finish.rb
80
+ - lib/irb/command/force_exit.rb
81
+ - lib/irb/command/help.rb
82
+ - lib/irb/command/history.rb
83
+ - lib/irb/command/info.rb
84
+ - lib/irb/command/internal_helpers.rb
85
+ - lib/irb/command/irb_info.rb
86
+ - lib/irb/command/load.rb
87
+ - lib/irb/command/ls.rb
88
+ - lib/irb/command/measure.rb
89
+ - lib/irb/command/next.rb
90
+ - lib/irb/command/pushws.rb
91
+ - lib/irb/command/show_doc.rb
92
+ - lib/irb/command/show_source.rb
93
+ - lib/irb/command/step.rb
94
+ - lib/irb/command/subirb.rb
95
+ - lib/irb/command/whereami.rb
75
96
  - lib/irb/completion.rb
76
97
  - lib/irb/context.rb
98
+ - lib/irb/debug.rb
99
+ - lib/irb/debug/ui.rb
100
+ - lib/irb/default_commands.rb
77
101
  - lib/irb/easter-egg.rb
78
102
  - lib/irb/ext/change-ws.rb
79
- - lib/irb/ext/history.rb
103
+ - lib/irb/ext/eval_history.rb
80
104
  - lib/irb/ext/loader.rb
81
105
  - lib/irb/ext/multi-irb.rb
82
- - lib/irb/ext/save-history.rb
83
106
  - lib/irb/ext/tracer.rb
84
107
  - lib/irb/ext/use-loader.rb
85
108
  - lib/irb/ext/workspaces.rb
86
- - lib/irb/extend-command.rb
87
109
  - lib/irb/frame.rb
88
110
  - lib/irb/help.rb
111
+ - lib/irb/helper_method.rb
112
+ - lib/irb/helper_method/base.rb
113
+ - lib/irb/helper_method/conf.rb
114
+ - lib/irb/history.rb
89
115
  - lib/irb/init.rb
90
116
  - lib/irb/input-method.rb
91
117
  - lib/irb/inspector.rb
@@ -97,9 +123,11 @@ files:
97
123
  - lib/irb/nesting_parser.rb
98
124
  - lib/irb/notifier.rb
99
125
  - lib/irb/output-method.rb
126
+ - lib/irb/pager.rb
100
127
  - lib/irb/ruby-lex.rb
101
128
  - lib/irb/ruby_logo.aa
102
- - lib/irb/src_encoding.rb
129
+ - lib/irb/source_finder.rb
130
+ - lib/irb/statement.rb
103
131
  - lib/irb/version.rb
104
132
  - lib/irb/workspace.rb
105
133
  - lib/irb/ws-for-case-2.rb
@@ -129,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
157
  - !ruby/object:Gem::Version
130
158
  version: '0'
131
159
  requirements: []
132
- rubygems_version: 3.5.0.dev
160
+ rubygems_version: 3.5.11
133
161
  signing_key:
134
162
  specification_version: 4
135
163
  summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "debug"
4
-
5
- module IRB
6
- # :stopdoc:
7
-
8
- module ExtendCommand
9
- class Backtrace < DebugCommand
10
- def self.transform_args(args)
11
- args&.dump
12
- end
13
-
14
- def execute(*args)
15
- super(pre_cmds: ["backtrace", *args].join(" "))
16
- end
17
- end
18
- end
19
-
20
- # :startdoc:
21
- end
data/lib/irb/cmd/break.rb DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "debug"
4
-
5
- module IRB
6
- # :stopdoc:
7
-
8
- module ExtendCommand
9
- class Break < DebugCommand
10
- def self.transform_args(args)
11
- args&.dump
12
- end
13
-
14
- def execute(args = nil)
15
- super(pre_cmds: "break #{args}")
16
- end
17
- end
18
- end
19
-
20
- # :startdoc:
21
- end
data/lib/irb/cmd/catch.rb DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "debug"
4
-
5
- module IRB
6
- # :stopdoc:
7
-
8
- module ExtendCommand
9
- class Catch < DebugCommand
10
- def self.transform_args(args)
11
- args&.dump
12
- end
13
-
14
- def execute(*args)
15
- super(pre_cmds: ["catch", *args].join(" "))
16
- end
17
- end
18
- end
19
-
20
- # :startdoc:
21
- end
data/lib/irb/cmd/chws.rb DELETED
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: false
2
- #
3
- # change-ws.rb -
4
- # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
- #
6
-
7
- require_relative "nop"
8
- require_relative "../ext/change-ws"
9
-
10
- module IRB
11
- # :stopdoc:
12
-
13
- module ExtendCommand
14
-
15
- class CurrentWorkingWorkspace < Nop
16
- category "IRB"
17
- description "Show the current workspace."
18
-
19
- def execute(*obj)
20
- irb_context.main
21
- end
22
- end
23
-
24
- class ChangeWorkspace < Nop
25
- category "IRB"
26
- description "Change the current workspace to an object."
27
-
28
- def execute(*obj)
29
- irb_context.change_workspace(*obj)
30
- irb_context.main
31
- end
32
- end
33
- end
34
-
35
- # :startdoc:
36
- end
data/lib/irb/cmd/edit.rb DELETED
@@ -1,61 +0,0 @@
1
- require 'shellwords'
2
- require_relative "nop"
3
-
4
- module IRB
5
- # :stopdoc:
6
-
7
- module ExtendCommand
8
- class Edit < Nop
9
- category "Misc"
10
- description 'Open a file with the editor command defined with `ENV["EDITOR"]`.'
11
-
12
- class << self
13
- def transform_args(args)
14
- # Return a string literal as is for backward compatibility
15
- if args.nil? || args.empty? || string_literal?(args)
16
- args
17
- else # Otherwise, consider the input as a String for convenience
18
- args.strip.dump
19
- end
20
- end
21
- end
22
-
23
- def execute(*args)
24
- path = args.first
25
-
26
- if path.nil? && (irb_path = @irb_context.irb_path)
27
- path = irb_path
28
- end
29
-
30
- if !File.exist?(path)
31
- require_relative "show_source"
32
-
33
- source =
34
- begin
35
- ShowSource.find_source(path, @irb_context)
36
- rescue NameError
37
- # if user enters a path that doesn't exist, it'll cause NameError when passed here because find_source would try to evaluate it as well
38
- # in this case, we should just ignore the error
39
- end
40
-
41
- if source && File.exist?(source.file)
42
- path = source.file
43
- else
44
- puts "Can not find file: #{path}"
45
- return
46
- end
47
- end
48
-
49
- if editor = ENV['EDITOR']
50
- puts "command: '#{editor}'"
51
- puts " path: #{path}"
52
- system(*Shellwords.split(editor), path)
53
- else
54
- puts "Can not find editor setting: ENV['EDITOR']"
55
- end
56
- end
57
- end
58
- end
59
-
60
- # :startdoc:
61
- end
data/lib/irb/cmd/help.rb DELETED
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "show_doc"
4
-
5
- module IRB
6
- module ExtendCommand
7
- class Help < ShowDoc
8
- category "Context"
9
- description "[DEPRECATED] Enter the mode to look up RI documents."
10
-
11
- DEPRECATION_MESSAGE = <<~MSG
12
- [Deprecation] The `help` command will be repurposed to display command help in the future.
13
- For RI document lookup, please use the `show_doc` command instead.
14
- For command help, please use `show_cmds` for now.
15
- MSG
16
-
17
- def execute(*names)
18
- warn DEPRECATION_MESSAGE
19
- super
20
- end
21
- end
22
- end
23
- end
data/lib/irb/cmd/info.rb DELETED
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "debug"
4
-
5
- module IRB
6
- # :stopdoc:
7
-
8
- module ExtendCommand
9
- class Info < DebugCommand
10
- def self.transform_args(args)
11
- args&.dump
12
- end
13
-
14
- def execute(*args)
15
- super(pre_cmds: ["info", *args].join(" "))
16
- end
17
- end
18
- end
19
-
20
- # :startdoc:
21
- end
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: false
2
- #
3
- # change-ws.rb -
4
- # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
- #
6
-
7
- require_relative "nop"
8
- require_relative "../ext/workspaces"
9
-
10
- module IRB
11
- # :stopdoc:
12
-
13
- module ExtendCommand
14
- class Workspaces < Nop
15
- category "IRB"
16
- description "Show workspaces."
17
-
18
- def execute(*obj)
19
- irb_context.workspaces.collect{|ws| ws.main}
20
- end
21
- end
22
-
23
- class PushWorkspace < Workspaces
24
- category "IRB"
25
- description "Push an object to the workspace stack."
26
-
27
- def execute(*obj)
28
- irb_context.push_workspace(*obj)
29
- super
30
- end
31
- end
32
-
33
- class PopWorkspace < Workspaces
34
- category "IRB"
35
- description "Pop a workspace from the workspace stack."
36
-
37
- def execute(*obj)
38
- irb_context.pop_workspace(*obj)
39
- super
40
- end
41
- end
42
- end
43
-
44
- # :startdoc:
45
- end
@@ -1,39 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "stringio"
4
- require_relative "nop"
5
-
6
- module IRB
7
- # :stopdoc:
8
-
9
- module ExtendCommand
10
- class ShowCmds < Nop
11
- category "IRB"
12
- description "List all available commands and their description."
13
-
14
- def execute(*args)
15
- commands_info = IRB::ExtendCommandBundle.all_commands_info
16
- commands_grouped_by_categories = commands_info.group_by { |cmd| cmd[:category] }
17
- longest_cmd_name_length = commands_info.map { |c| c[:display_name] }.max { |a, b| a.length <=> b.length }.length
18
-
19
- output = StringIO.new
20
-
21
- commands_grouped_by_categories.each do |category, cmds|
22
- output.puts Color.colorize(category, [:BOLD])
23
-
24
- cmds.each do |cmd|
25
- output.puts " #{cmd[:display_name].to_s.ljust(longest_cmd_name_length)} #{cmd[:description]}"
26
- end
27
-
28
- output.puts
29
- end
30
-
31
- puts output.string
32
-
33
- nil
34
- end
35
- end
36
- end
37
-
38
- # :startdoc:
39
- end
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "nop"
4
-
5
- module IRB
6
- module ExtendCommand
7
- class ShowDoc < Nop
8
- class << self
9
- def transform_args(args)
10
- # Return a string literal as is for backward compatibility
11
- if args.empty? || string_literal?(args)
12
- args
13
- else # Otherwise, consider the input as a String for convenience
14
- args.strip.dump
15
- end
16
- end
17
- end
18
-
19
- category "Context"
20
- description "Enter the mode to look up RI documents."
21
-
22
- def execute(*names)
23
- require 'rdoc/ri/driver'
24
-
25
- unless ShowDoc.const_defined?(:Ri)
26
- opts = RDoc::RI::Driver.process_args([])
27
- ShowDoc.const_set(:Ri, RDoc::RI::Driver.new(opts))
28
- end
29
-
30
- if names.empty?
31
- Ri.interactive
32
- else
33
- names.each do |name|
34
- begin
35
- Ri.display_name(name.to_s)
36
- rescue RDoc::RI::Error
37
- puts $!.message
38
- end
39
- end
40
- end
41
-
42
- nil
43
- rescue LoadError, SystemExit
44
- warn "Can't display document because `rdoc` is not installed."
45
- end
46
- end
47
- end
48
- end
@@ -1,113 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "nop"
4
- require_relative "../color"
5
- require_relative "../ruby-lex"
6
-
7
- module IRB
8
- # :stopdoc:
9
-
10
- module ExtendCommand
11
- class ShowSource < Nop
12
- category "Context"
13
- description "Show the source code of a given method or constant."
14
-
15
- class << self
16
- def transform_args(args)
17
- # Return a string literal as is for backward compatibility
18
- if args.empty? || string_literal?(args)
19
- args
20
- else # Otherwise, consider the input as a String for convenience
21
- args.strip.dump
22
- end
23
- end
24
-
25
- def find_source(str, irb_context)
26
- case str
27
- when /\A[A-Z]\w*(::[A-Z]\w*)*\z/ # Const::Name
28
- eval(str, irb_context.workspace.binding) # trigger autoload
29
- base = irb_context.workspace.binding.receiver.yield_self { |r| r.is_a?(Module) ? r : Object }
30
- file, line = base.const_source_location(str)
31
- when /\A(?<owner>[A-Z]\w*(::[A-Z]\w*)*)#(?<method>[^ :.]+)\z/ # Class#method
32
- owner = eval(Regexp.last_match[:owner], irb_context.workspace.binding)
33
- method = Regexp.last_match[:method]
34
- if owner.respond_to?(:instance_method)
35
- methods = owner.instance_methods + owner.private_instance_methods
36
- file, line = owner.instance_method(method).source_location if methods.include?(method.to_sym)
37
- end
38
- when /\A((?<receiver>.+)(\.|::))?(?<method>[^ :.]+)\z/ # method, receiver.method, receiver::method
39
- receiver = eval(Regexp.last_match[:receiver] || 'self', irb_context.workspace.binding)
40
- method = Regexp.last_match[:method]
41
- file, line = receiver.method(method).source_location if receiver.respond_to?(method, true)
42
- end
43
- if file && line
44
- Source.new(file: file, first_line: line, last_line: find_end(file, line, irb_context))
45
- end
46
- end
47
-
48
- private
49
-
50
- def find_end(file, first_line, irb_context)
51
- return first_line unless File.exist?(file)
52
- lex = RubyLex.new(irb_context)
53
- lines = File.read(file).lines[(first_line - 1)..-1]
54
- tokens = RubyLex.ripper_lex_without_warning(lines.join)
55
- prev_tokens = []
56
-
57
- # chunk with line number
58
- tokens.chunk { |tok| tok.pos[0] }.each do |lnum, chunk|
59
- code = lines[0..lnum].join
60
- prev_tokens.concat chunk
61
- continue = lex.should_continue?(prev_tokens)
62
- syntax = lex.check_code_syntax(code)
63
- if !continue && syntax == :valid
64
- return first_line + lnum
65
- end
66
- end
67
- first_line
68
- end
69
- end
70
-
71
- def execute(str = nil)
72
- unless str.is_a?(String)
73
- puts "Error: Expected a string but got #{str.inspect}"
74
- return
75
- end
76
-
77
- source = self.class.find_source(str, @irb_context)
78
- if source && File.exist?(source.file)
79
- show_source(source)
80
- else
81
- puts "Error: Couldn't locate a definition for #{str}"
82
- end
83
- nil
84
- end
85
-
86
- private
87
-
88
- # @param [IRB::ExtendCommand::ShowSource::Source] source
89
- def show_source(source)
90
- puts
91
- puts "#{bold("From")}: #{source.file}:#{source.first_line}"
92
- puts
93
- code = IRB::Color.colorize_code(File.read(source.file))
94
- puts code.lines[(source.first_line - 1)...source.last_line].join
95
- puts
96
- end
97
-
98
- def bold(str)
99
- Color.colorize(str, [:BOLD])
100
- end
101
-
102
- Source = Struct.new(
103
- :file, # @param [String] - file name
104
- :first_line, # @param [String] - first line
105
- :last_line, # @param [String] - last line
106
- keyword_init: true,
107
- )
108
- private_constant :Source
109
- end
110
- end
111
-
112
- # :startdoc:
113
- end
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: false
2
- #
3
- # multi.rb -
4
- # by Keiju ISHITSUKA(keiju@ruby-lang.org)
5
- #
6
-
7
- require_relative "nop"
8
-
9
- module IRB
10
- # :stopdoc:
11
-
12
- module ExtendCommand
13
- class MultiIRBCommand < Nop
14
- def initialize(conf)
15
- super
16
- extend_irb_context
17
- end
18
-
19
- private
20
-
21
- def extend_irb_context
22
- # this extension patches IRB context like IRB.CurrentContext
23
- require_relative "../ext/multi-irb"
24
- end
25
- end
26
-
27
- class IrbCommand < MultiIRBCommand
28
- category "IRB"
29
- description "Start a child IRB."
30
-
31
- def execute(*obj)
32
- IRB.irb(nil, *obj)
33
- end
34
- end
35
-
36
- class Jobs < MultiIRBCommand
37
- category "IRB"
38
- description "List of current sessions."
39
-
40
- def execute
41
- IRB.JobManager
42
- end
43
- end
44
-
45
- class Foreground < MultiIRBCommand
46
- category "IRB"
47
- description "Switches to the session of the given number."
48
-
49
- def execute(key = nil)
50
- raise CommandArgumentError.new("Please specify the id of target IRB job (listed in the `jobs` command).") unless key
51
- IRB.JobManager.switch(key)
52
- end
53
- end
54
-
55
- class Kill < MultiIRBCommand
56
- category "IRB"
57
- description "Kills the session with the given number."
58
-
59
- def execute(*keys)
60
- IRB.JobManager.kill(*keys)
61
- end
62
- end
63
- end
64
-
65
- # :startdoc:
66
- end