pp 0.2.1 → 0.3.0

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 (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pp.rb +41 -30
  3. data/pp.gemspec +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2faa701270cc94e8c8db4dc3ef9e142d6a6f0b35ee05dd992a030697fb2e1558
4
- data.tar.gz: 122590c50f617dc75434ed4be205c1896cd6699b33b65f98406b9f78604e6e58
3
+ metadata.gz: 0f66fc26d251e735dab9c7dcc24cbd90ec1616ac358535379358242dea131e5e
4
+ data.tar.gz: a04b828096786c7d6de187bcacda6fdb7a3bf246b7dab7399347039feb9dedac
5
5
  SHA512:
6
- metadata.gz: ec0f27ba14d0f783f64f35792be7dc2dceb7b11f3aecc7a9535968ed37f4b5659a67a038ec509f6fd9ac7d1495cf20e228df5d226b79258e1d55fd5796747455
7
- data.tar.gz: 2ff27f1c5086edbb4677e89924411b4916484c62ec1fa620e7ca59195cff7e876e8c5103d6fa55b5ebf9d7ef7c682f85ca68d09b763a99276732fab3f7aa1484
6
+ metadata.gz: a2b9327741655b4fa03bf3cd2d32113022b4164fdd48608cafdd3abe5b80e394d0fb8b3ebe2acb7818c60d68103ba5cb0900ba9e20d988baac3e311bb8424ace
7
+ data.tar.gz: 6bceee1000233e7083f9e3e87aeba7bf28a257acc48a453e88d928bffe0180f65af0c3e70a636dfc9e33e1307c51831a03182308f2f18d51f0d10d53a79bfc9c
data/lib/pp.rb CHANGED
@@ -61,6 +61,15 @@ require 'prettyprint'
61
61
  # Tanaka Akira <akr@fsij.org>
62
62
 
63
63
  class PP < PrettyPrint
64
+ def PP.width_for(out)
65
+ begin
66
+ require 'io/console'
67
+ _, width = out.winsize
68
+ rescue LoadError, NoMethodError, SystemCallError
69
+ end
70
+ (width || ENV['COLUMNS']&.to_i&.nonzero? || 80) - 1
71
+ end
72
+
64
73
  # Outputs +obj+ to +out+ in pretty printed format of
65
74
  # +width+ columns in width.
66
75
  #
@@ -68,7 +77,7 @@ class PP < PrettyPrint
68
77
  # If +width+ is omitted, 79 is assumed.
69
78
  #
70
79
  # PP.pp returns +out+.
71
- def PP.pp(obj, out=$>, width=79)
80
+ def PP.pp(obj, out=$>, width=width_for(out))
72
81
  q = PP.new(out, width)
73
82
  q.guard_inspect_key {q.pp obj}
74
83
  q.flush
@@ -424,7 +433,7 @@ end
424
433
  class File < IO # :nodoc:
425
434
  class Stat # :nodoc:
426
435
  def pretty_print(q) # :nodoc:
427
- require 'etc.so'
436
+ require 'etc'
428
437
  q.object_group(self) {
429
438
  q.breakable
430
439
  q.text sprintf("dev=0x%x", self.dev); q.comma_breakable
@@ -530,37 +539,39 @@ class MatchData # :nodoc:
530
539
  end
531
540
  end
532
541
 
533
- class RubyVM::AbstractSyntaxTree::Node
534
- def pretty_print_children(q, names = [])
535
- children.zip(names) do |c, n|
536
- if n
537
- q.breakable
538
- q.text "#{n}:"
539
- end
540
- q.group(2) do
541
- q.breakable
542
- q.pp c
542
+ if defined?(RubyVM::AbstractSyntaxTree)
543
+ class RubyVM::AbstractSyntaxTree::Node
544
+ def pretty_print_children(q, names = [])
545
+ children.zip(names) do |c, n|
546
+ if n
547
+ q.breakable
548
+ q.text "#{n}:"
549
+ end
550
+ q.group(2) do
551
+ q.breakable
552
+ q.pp c
553
+ end
543
554
  end
544
555
  end
545
- end
546
556
 
547
- def pretty_print(q)
548
- q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
549
- case type
550
- when :SCOPE
551
- pretty_print_children(q, %w"tbl args body")
552
- when :ARGS
553
- pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
554
- when :DEFN
555
- pretty_print_children(q, %w[mid body])
556
- when :ARYPTN
557
- pretty_print_children(q, %w[const pre rest post])
558
- when :HSHPTN
559
- pretty_print_children(q, %w[const kw kwrest])
560
- else
561
- pretty_print_children(q)
562
- end
563
- }
557
+ def pretty_print(q)
558
+ q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
559
+ case type
560
+ when :SCOPE
561
+ pretty_print_children(q, %w"tbl args body")
562
+ when :ARGS
563
+ pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
564
+ when :DEFN
565
+ pretty_print_children(q, %w[mid body])
566
+ when :ARYPTN
567
+ pretty_print_children(q, %w[const pre rest post])
568
+ when :HSHPTN
569
+ pretty_print_children(q, %w[const kw kwrest])
570
+ else
571
+ pretty_print_children(q)
572
+ end
573
+ }
574
+ end
564
575
  end
565
576
  end
566
577
 
data/pp.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "pp"
3
- spec.version = "0.2.1"
3
+ spec.version = "0.3.0"
4
4
  spec.authors = ["Tanaka Akira"]
5
5
  spec.email = ["akr@fsij.org"]
6
6
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tanaka Akira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-21 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: prettyprint