pp 0.2.1 → 0.4.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.
- checksums.yaml +4 -4
- data/lib/pp.rb +73 -31
- data/pp.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d57757b241b923f8c7ebf7653855a01231720617dfb2ff9588c724a4968e698
|
4
|
+
data.tar.gz: 426b5c5d3132ac1aeea3e96cd5870c72ed5f730cc244a0b9139a46681c42c278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83e186173cf60aa175b3beee1bd4d8befd5b54743ab6c08c31d3088907f0a7ba84dfb2e97a91937db45346e8831b7152cb5c85127c83cb6787a997418bbaf98b
|
7
|
+
data.tar.gz: bc302f420467a0dc34e65bccd003bc979c8a5cf69005b34ed8140d687bfc73008a2f6f76bfc4b747b530ba43a799ceabea2b7eaa0ba7e56dfad05c7448d9c7bc
|
data/lib/pp.rb
CHANGED
@@ -61,14 +61,34 @@ require 'prettyprint'
|
|
61
61
|
# Tanaka Akira <akr@fsij.org>
|
62
62
|
|
63
63
|
class PP < PrettyPrint
|
64
|
+
# Returns the usable width for +out+.
|
65
|
+
# As the width of +out+:
|
66
|
+
# 1. If +out+ is assigned to a tty device, its width is used.
|
67
|
+
# 2. Otherwise, or it could not get the value, the +COLUMN+
|
68
|
+
# environment variable is assumed to be set to the width.
|
69
|
+
# 3. If +COLUMN+ is not set to a non-zero number, 80 is assumed.
|
70
|
+
#
|
71
|
+
# And finally, returns the above width value - 1.
|
72
|
+
# * This -1 is for Windows command prompt, which moves the cursor to
|
73
|
+
# the next line if it reaches the last column.
|
74
|
+
def PP.width_for(out)
|
75
|
+
begin
|
76
|
+
require 'io/console'
|
77
|
+
_, width = out.winsize
|
78
|
+
rescue LoadError, NoMethodError, SystemCallError
|
79
|
+
end
|
80
|
+
(width || ENV['COLUMNS']&.to_i&.nonzero? || 80) - 1
|
81
|
+
end
|
82
|
+
|
64
83
|
# Outputs +obj+ to +out+ in pretty printed format of
|
65
84
|
# +width+ columns in width.
|
66
85
|
#
|
67
86
|
# If +out+ is omitted, <code>$></code> is assumed.
|
68
|
-
# If +width+ is omitted,
|
87
|
+
# If +width+ is omitted, the width of +out+ is assumed (see
|
88
|
+
# width_for).
|
69
89
|
#
|
70
90
|
# PP.pp returns +out+.
|
71
|
-
def PP.pp(obj, out=$>, width=
|
91
|
+
def PP.pp(obj, out=$>, width=width_for(out))
|
72
92
|
q = PP.new(out, width)
|
73
93
|
q.guard_inspect_key {q.pp obj}
|
74
94
|
q.flush
|
@@ -396,6 +416,26 @@ class Struct # :nodoc:
|
|
396
416
|
end
|
397
417
|
end
|
398
418
|
|
419
|
+
class Data # :nodoc:
|
420
|
+
def pretty_print(q) # :nodoc:
|
421
|
+
q.group(1, sprintf("#<data %s", PP.mcall(self, Kernel, :class).name), '>') {
|
422
|
+
q.seplist(PP.mcall(self, Data, :members), lambda { q.text "," }) {|member|
|
423
|
+
q.breakable
|
424
|
+
q.text member.to_s
|
425
|
+
q.text '='
|
426
|
+
q.group(1) {
|
427
|
+
q.breakable ''
|
428
|
+
q.pp public_send(member)
|
429
|
+
}
|
430
|
+
}
|
431
|
+
}
|
432
|
+
end
|
433
|
+
|
434
|
+
def pretty_print_cycle(q) # :nodoc:
|
435
|
+
q.text sprintf("#<data %s:...>", PP.mcall(self, Kernel, :class).name)
|
436
|
+
end
|
437
|
+
end if "3.2" <= RUBY_VERSION
|
438
|
+
|
399
439
|
class Range # :nodoc:
|
400
440
|
def pretty_print(q) # :nodoc:
|
401
441
|
q.pp self.begin
|
@@ -424,7 +464,7 @@ end
|
|
424
464
|
class File < IO # :nodoc:
|
425
465
|
class Stat # :nodoc:
|
426
466
|
def pretty_print(q) # :nodoc:
|
427
|
-
require 'etc
|
467
|
+
require 'etc'
|
428
468
|
q.object_group(self) {
|
429
469
|
q.breakable
|
430
470
|
q.text sprintf("dev=0x%x", self.dev); q.comma_breakable
|
@@ -530,37 +570,39 @@ class MatchData # :nodoc:
|
|
530
570
|
end
|
531
571
|
end
|
532
572
|
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
q.
|
542
|
-
|
573
|
+
if defined?(RubyVM::AbstractSyntaxTree)
|
574
|
+
class RubyVM::AbstractSyntaxTree::Node
|
575
|
+
def pretty_print_children(q, names = [])
|
576
|
+
children.zip(names) do |c, n|
|
577
|
+
if n
|
578
|
+
q.breakable
|
579
|
+
q.text "#{n}:"
|
580
|
+
end
|
581
|
+
q.group(2) do
|
582
|
+
q.breakable
|
583
|
+
q.pp c
|
584
|
+
end
|
543
585
|
end
|
544
586
|
end
|
545
|
-
end
|
546
587
|
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
588
|
+
def pretty_print(q)
|
589
|
+
q.group(1, "(#{type}@#{first_lineno}:#{first_column}-#{last_lineno}:#{last_column}", ")") {
|
590
|
+
case type
|
591
|
+
when :SCOPE
|
592
|
+
pretty_print_children(q, %w"tbl args body")
|
593
|
+
when :ARGS
|
594
|
+
pretty_print_children(q, %w[pre_num pre_init opt first_post post_num post_init rest kw kwrest block])
|
595
|
+
when :DEFN
|
596
|
+
pretty_print_children(q, %w[mid body])
|
597
|
+
when :ARYPTN
|
598
|
+
pretty_print_children(q, %w[const pre rest post])
|
599
|
+
when :HSHPTN
|
600
|
+
pretty_print_children(q, %w[const kw kwrest])
|
601
|
+
else
|
602
|
+
pretty_print_children(q)
|
603
|
+
end
|
604
|
+
}
|
605
|
+
end
|
564
606
|
end
|
565
607
|
end
|
566
608
|
|
data/pp.gemspec
CHANGED
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.
|
4
|
+
version: 0.4.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:
|
11
|
+
date: 2022-12-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: prettyprint
|
@@ -56,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
|
-
rubygems_version: 3.
|
59
|
+
rubygems_version: 3.4.0.dev
|
60
60
|
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: Provides a PrettyPrinter for Ruby objects
|