irb 1.3.5 → 1.3.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7a7034e210074f2c31db1369ffe0d5203cd7d2d35a1b9df36cbabfe6d52109e
4
- data.tar.gz: c22c2ea2a1fb878c0b96d194c8b5af832c07d4b53173ebec07cfcadb04ac4d33
3
+ metadata.gz: 7071322837c419efbce74bd5aa91c9b83a9a3fd31e893e72376b763b2bbf4409
4
+ data.tar.gz: fa4e508771f91e4da313913592a7caa713cb82069f57d4dab059426baa764fc4
5
5
  SHA512:
6
- metadata.gz: 9017a414d09dc360a6846aa23917133f57145bdc529642931912c92c1ce675c5312705a105a5098e8cec351b6997da379a745097238d98f1e18f976ed9da4594
7
- data.tar.gz: 67f3e78b20d4ea3881d6bea7deb8da4a2c9066029ffc19de9ed78b906cfae50f43e93da8b5ab306ac44b43f2555d0b3a65e3678ef10ba00f0e87221bb7f7a22d
6
+ metadata.gz: 2b040a17c30df8f8512c176acfb1884237c050d5e4dab769f08aa75a00da23dcba1be9fab15d37671e4617abee3f6279363fed80c0980687cdcbed417bf5e3f4
7
+ data.tar.gz: 0a021169f28c114aeac7b7375eda932cdd4b357056b092a8499a61da6d4d1b01d019591e94eaaf134392a8b5c92cd632d0dfc7bf4b243831df93cc0514cd2eb1
data/Gemfile CHANGED
@@ -3,3 +3,13 @@ source "https://rubygems.org"
3
3
  git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  gemspec
6
+
7
+ group :development do
8
+ gem "bundler"
9
+ is_unix = RUBY_PLATFORM =~ /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
10
+ is_truffleruby = RUBY_DESCRIPTION =~ /truffleruby/
11
+ gem 'vterm', '>= 0.0.5' if is_unix && ENV['WITH_VTERM']
12
+ gem 'yamatanooroti', '>= 0.0.6'
13
+ gem "rake"
14
+ gem "stackprof" if is_unix && !is_truffleruby
15
+ end
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ 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.test_files = FileList["test/**/test_*.rb"]
7
+ t.test_files = FileList["test/irb/test_*.rb"]
8
8
  end
9
9
 
10
10
  Rake::TestTask.new(:test_yamatanooroti) do |t|
data/irb.gemspec CHANGED
@@ -36,7 +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.1.5"
40
- spec.add_development_dependency "bundler"
41
- spec.add_development_dependency "rake"
39
+ spec.add_dependency "reline", ">= 0.2.5"
42
40
  end
data/lib/irb.rb CHANGED
@@ -590,9 +590,15 @@ module IRB
590
590
  end
591
591
  end
592
592
 
593
- def convert_invalid_byte_sequence(str)
594
- str = str.force_encoding(Encoding::ASCII_8BIT)
595
- conv = Encoding::Converter.new(Encoding::ASCII_8BIT, Encoding::UTF_8)
593
+ def convert_invalid_byte_sequence(str, enc)
594
+ str.force_encoding(enc)
595
+ str.scrub { |c|
596
+ c.bytes.map{ |b| "\\x#{b.to_s(16).upcase}" }.join
597
+ }
598
+ end
599
+
600
+ def encode_with_invalid_byte_sequence(str, enc)
601
+ conv = Encoding::Converter.new(str.encoding, enc)
596
602
  dst = String.new
597
603
  begin
598
604
  ret = conv.primitive_convert(str, dst)
@@ -640,7 +646,8 @@ module IRB
640
646
  message = exc.full_message(order: :top)
641
647
  order = :top
642
648
  end
643
- message = convert_invalid_byte_sequence(message)
649
+ message = convert_invalid_byte_sequence(message, exc.message.encoding)
650
+ message = encode_with_invalid_byte_sequence(message, IRB.conf[:LC_MESSAGES].encoding) unless message.encoding.to_s.casecmp?(IRB.conf[:LC_MESSAGES].encoding.to_s)
644
651
  message = message.gsub(/((?:^\t.+$\n)+)/) { |m|
645
652
  case order
646
653
  when :top
data/lib/irb/cmd/ls.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "reline"
4
+ require 'set'
4
5
  require_relative "nop"
5
6
  require_relative "../color"
6
7
 
@@ -16,13 +17,36 @@ module IRB
16
17
  klass = (obj.class == Class || obj.class == Module ? obj : obj.class)
17
18
 
18
19
  o.dump("constants", obj.constants) if obj.respond_to?(:constants)
19
- o.dump("#{klass}.methods", obj.singleton_methods(false))
20
- o.dump("#{klass}#methods", klass.public_instance_methods(false))
20
+ dump_singleton_methods(o, klass, obj)
21
+ dump_instance_methods(o, klass)
21
22
  o.dump("instance variables", obj.instance_variables)
22
23
  o.dump("class variables", klass.class_variables)
23
24
  o.dump("locals", locals)
24
25
  end
25
26
 
27
+ def dump_singleton_methods(o, klass, obj)
28
+ maps = class_method_map(obj.singleton_class.ancestors.take_while { |c| c != klass })
29
+ maps.each do |mod, methods|
30
+ name = mod == obj.singleton_class ? "#{klass}.methods" : "#{mod}#methods"
31
+ o.dump(name, methods)
32
+ end
33
+ end
34
+
35
+ def dump_instance_methods(o, klass)
36
+ maps = class_method_map(klass.ancestors)
37
+ maps.each do |mod, methods|
38
+ o.dump("#{mod}#methods", methods)
39
+ end
40
+ end
41
+
42
+ def class_method_map(classes)
43
+ dumped = Set.new
44
+ classes.reject { |mod| mod >= Object }.map do |mod|
45
+ methods = mod.public_instance_methods(false).select { |m| dumped.add?(m) }
46
+ [mod, methods]
47
+ end.reverse
48
+ end
49
+
26
50
  class Output
27
51
  MARGIN = " "
28
52
 
data/lib/irb/color.rb CHANGED
@@ -77,7 +77,7 @@ module IRB # :nodoc:
77
77
 
78
78
  class << self
79
79
  def colorable?
80
- $stdout.tty? && supported? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
80
+ $stdout.tty? && (/mswin|mingw/ =~ RUBY_PLATFORM || (ENV.key?('TERM') && ENV['TERM'] != 'dumb'))
81
81
  end
82
82
 
83
83
  def inspect_colorable?(obj, seen: {}.compare_by_identity)
@@ -101,22 +101,22 @@ module IRB # :nodoc:
101
101
  end
102
102
  end
103
103
 
104
- def clear
105
- return '' unless colorable?
104
+ def clear(colorable: colorable?)
105
+ return '' unless colorable
106
106
  "\e[#{CLEAR}m"
107
107
  end
108
108
 
109
- def colorize(text, seq)
110
- return text unless colorable?
109
+ def colorize(text, seq, colorable: colorable?)
110
+ return text unless colorable
111
111
  seq = seq.map { |s| "\e[#{const_get(s)}m" }.join('')
112
- "#{seq}#{text}#{clear}"
112
+ "#{seq}#{text}#{clear(colorable: colorable)}"
113
113
  end
114
114
 
115
115
  # If `complete` is false (code is incomplete), this does not warn compile_error.
116
116
  # This option is needed to avoid warning a user when the compile_error is happening
117
117
  # because the input is not wrong but just incomplete.
118
- def colorize_code(code, complete: true, ignore_error: false)
119
- return code unless colorable?
118
+ def colorize_code(code, complete: true, ignore_error: false, colorable: colorable?)
119
+ return code unless colorable
120
120
 
121
121
  symbol_state = SymbolState.new
122
122
  colored = +''
@@ -134,7 +134,7 @@ module IRB # :nodoc:
134
134
  line = Reline::Unicode.escape_for_print(line)
135
135
  if seq = dispatch_seq(token, expr, line, in_symbol: in_symbol)
136
136
  colored << seq.map { |s| "\e[#{s}m" }.join('')
137
- colored << line.sub(/\Z/, clear)
137
+ colored << line.sub(/\Z/, clear(colorable: colorable))
138
138
  else
139
139
  colored << line
140
140
  end
@@ -161,11 +161,6 @@ module IRB # :nodoc:
161
161
  seen.delete(obj)
162
162
  end
163
163
 
164
- def supported?
165
- return @supported if defined?(@supported)
166
- @supported = Ripper::Lexer::Elem.method_defined?(:state)
167
- end
168
-
169
164
  def scan(code, allow_last_error:)
170
165
  pos = [1, 0]
171
166
 
data/lib/irb/init.rb CHANGED
@@ -44,7 +44,7 @@ module IRB # :nodoc:
44
44
  @CONF[:IRB_RC] = nil
45
45
 
46
46
  @CONF[:USE_SINGLELINE] = false unless defined?(ReadlineInputMethod)
47
- @CONF[:USE_COLORIZE] = true
47
+ @CONF[:USE_COLORIZE] = !ENV['NO_COLOR']
48
48
  @CONF[:INSPECT_MODE] = true
49
49
  @CONF[:USE_TRACER] = false
50
50
  @CONF[:USE_LOADER] = false
@@ -120,7 +120,11 @@ module IRB # :nodoc:
120
120
  puts 'processing time: %fs' % (now - time) if IRB.conf[:MEASURE]
121
121
  result
122
122
  }
123
+ # arg can be either a symbol for the mode (:cpu, :wall, ..) or a hash for
124
+ # a more complete configuration.
125
+ # See https://github.com/tmm1/stackprof#all-options.
123
126
  @CONF[:MEASURE_PROC][:STACKPROF] = proc { |context, code, line_no, arg, &block|
127
+ return block.() unless IRB.conf[:MEASURE]
124
128
  success = false
125
129
  begin
126
130
  require 'stackprof'
@@ -130,10 +134,18 @@ module IRB # :nodoc:
130
134
  end
131
135
  if success
132
136
  result = nil
133
- stackprof_result = StackProf.run(mode: arg ? arg : :cpu) do
137
+ arg = { mode: arg || :cpu } unless arg.is_a?(Hash)
138
+ stackprof_result = StackProf.run(**arg) do
134
139
  result = block.()
135
140
  end
136
- StackProf::Report.new(stackprof_result).print_text if IRB.conf[:MEASURE]
141
+ case stackprof_result
142
+ when File
143
+ puts "StackProf report saved to #{stackprof_result.path}"
144
+ when Hash
145
+ StackProf::Report.new(stackprof_result).print_text
146
+ else
147
+ puts "Stackprof ran with #{arg.inspect}"
148
+ end
137
149
  result
138
150
  else
139
151
  block.()
@@ -301,11 +313,11 @@ module IRB # :nodoc:
301
313
  break
302
314
  end
303
315
  end
316
+
304
317
  load_path.collect! do |path|
305
318
  /\A\.\// =~ path ? path : File.expand_path(path)
306
319
  end
307
320
  $LOAD_PATH.unshift(*load_path)
308
-
309
321
  end
310
322
 
311
323
  # running config
data/lib/irb/ruby-lex.rb CHANGED
@@ -339,7 +339,7 @@ class RubyLex
339
339
  # "syntax error, unexpected end-of-input, expecting keyword_end"
340
340
  #
341
341
  # example:
342
- # if ture
342
+ # if true
343
343
  # hoge
344
344
  # if false
345
345
  # fuga
data/lib/irb/version.rb CHANGED
@@ -11,7 +11,7 @@
11
11
  #
12
12
 
13
13
  module IRB # :nodoc:
14
- VERSION = "1.3.5"
14
+ VERSION = "1.3.6"
15
15
  @RELEASE_VERSION = VERSION
16
- @LAST_UPDATE_DATE = "2021-04-03"
16
+ @LAST_UPDATE_DATE = "2021-06-19"
17
17
  end
metadata CHANGED
@@ -1,57 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: irb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.5
4
+ version: 1.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keiju ISHITSUKA
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-04-02 00:00:00.000000000 Z
11
+ date: 2021-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: reline
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.1.5
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.1.5
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
15
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
16
  requirement: !ruby/object:Gem::Requirement
44
17
  requirements:
45
18
  - - ">="
46
19
  - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
20
+ version: 0.2.5
21
+ type: :runtime
50
22
  version_requirements: !ruby/object:Gem::Requirement
51
23
  requirements:
52
24
  - - ">="
53
25
  - !ruby/object:Gem::Version
54
- version: '0'
26
+ version: 0.2.5
55
27
  description: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
56
28
  email:
57
29
  - keiju@ruby-lang.org
@@ -125,7 +97,7 @@ licenses:
125
97
  - Ruby
126
98
  - BSD-2-Clause
127
99
  metadata: {}
128
- post_install_message:
100
+ post_install_message:
129
101
  rdoc_options: []
130
102
  require_paths:
131
103
  - lib
@@ -141,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
113
  version: '0'
142
114
  requirements: []
143
115
  rubygems_version: 3.1.4
144
- signing_key:
116
+ signing_key:
145
117
  specification_version: 4
146
118
  summary: Interactive Ruby command-line tool for REPL (Read Eval Print Loop).
147
119
  test_files: []