indented_io 0.9.0 → 0.10.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab6498e0cafc5162dbe8f021e5abe01d1782b103581ee6f506ad419e8d945ad7
4
- data.tar.gz: 986de84134945946db538335c1a850805a022676b9f67b7bfdcbc888a0d2f680
3
+ metadata.gz: e7d7b56c7e800172496c55f99f9dc03636488bf6c4129443a68529863dc6a172
4
+ data.tar.gz: 10d967b887989eced95e9fc7f3799d59219e4a76ca926556badf8ebb7e1c49b6
5
5
  SHA512:
6
- metadata.gz: 3b5e24b28007050283cd1c2f2903bc19524d2abaa4f9c120d7b8c48c827a5e8ac0a4a2406258743553bfa673dd298c0937cc75ea5c0b2f162bfc33ffeedd9154
7
- data.tar.gz: 660976e3894125018aaa7968a331144670d2e071e852f48702f4de4f5fc4bd5ea97df95fc6b2df91bc38ec5f77b880dea33576363a1733ed79f66a67a02099fa
6
+ metadata.gz: 0cb712cf0d9926b09d385db2a37a3d0cb6e136a36f5cbd164dccf49954b93098a4b23b0f4c60548a79267697bbdeb9adf19efd07123762f79ca43ea77860797a
7
+ data.tar.gz: a0986342ecbc58afb912146b30aefbaed2c186df34b4df5dfe8a838cdc631db51eba5524797e101471c1cfd8c5388f42a4a482bc7bbab4fd85cc0bbb765405a5
data/indented_io.gemspec CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.description = %q{
11
11
  IndentedIO extends Kernel, IO, and StringIO with an
12
12
  #indent method that redefines #print, printf, #puts,
13
- and #p to print their output indented. Indentations
13
+ and #p to print their output indented. Indentations
14
14
  are stacked so that each new indentation adds to the
15
15
  previous indendation
16
16
  }
@@ -25,4 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.bindir = "exe"
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
+
29
+ spec.add_development_dependency "string-text"
30
+
28
31
  end
@@ -13,7 +13,7 @@ module IndentedIO
13
13
  class IndentedIO
14
14
  include IndentedIOInterface
15
15
 
16
- # @!visibility private
16
+ # @!visibility private
17
17
  alias :interface_indent :indent
18
18
 
19
19
  # (see IndentedIO::IndentedIOInterface#indent)
@@ -21,6 +21,10 @@ module IndentedIO
21
21
  interface_indent(depth, string, bol: bol, &block)
22
22
  end
23
23
 
24
+ def undent
25
+ @parent
26
+ end
27
+
24
28
  # Indent and print args to the underlying device. #write has the same semantic
25
29
  # as IO#write
26
30
  def write(*args)
@@ -54,8 +58,10 @@ module IndentedIO
54
58
  end
55
59
 
56
60
  # Indent and print args to the underlying device. #p has the same semantic
57
- # as Kernel#p. Please note that even though #p is only defined on Kernel
58
- # but can be used on any IndentedIO object so you can say '$stderr.p value'
61
+ # as Kernel#p. Please note that even though #p is only defined on Kernel it
62
+ # can also be used on any IndentedIO object so you can say '$stderr.p
63
+ # value'. This also deviates from the standard ruby $stderr object that
64
+ # doesn't have a #p method defined
59
65
  def p(*args)
60
66
  if bol
61
67
  args.each { |arg| write(arg.inspect, "\n") }
@@ -70,13 +76,13 @@ module IndentedIO
70
76
  # Make IndentedIO behave like the underlying @device by only searching for
71
77
  # methods in the device
72
78
  #
73
- # @!visibility private
79
+ # @!visibility private
74
80
  def respond_to?(method, include_all = false)
75
81
  [:indent, :depth, :tab, :p].include?(method) || device.respond_to?(method, include_all)
76
82
  end
77
83
 
78
84
  # Make IndentedIO behave like the underlying @device
79
- # @!visibility private
85
+ # @!visibility private
80
86
  def method_missing(method, *args)
81
87
  device.send(method, *args)
82
88
  end
@@ -22,13 +22,13 @@ module IndentedIO
22
22
  # will pass-through all methods to the underlying device except #print,
23
23
  # #printf, #puts, and #p
24
24
  #
25
- # +level+ is the number of leves to indent and +string+ is the string used
25
+ # +level+ is the number of levels to indent and +string+ is the string used
26
26
  # for indentation. The indentation string can also be given as the keyword
27
27
  # parameter +:string+. Default is the indent string of the outer level or
28
28
  # {::IndentedIO.default_indent} if this is the first level. +:bol+ control the
29
29
  # beginning-of-line status: If true, #indent will begin writing with an
30
30
  # indentation string as if it was at the beginning of the line. If false,
31
- # it will only indent after the next newline. Default is true
31
+ # it will only indent after the first newline. Default is true
32
32
  #
33
33
  # If +level+ is negative, #indent will outdent text instead
34
34
  #
@@ -1,6 +1,8 @@
1
1
  require 'indented_io/indented_io_interface'
2
2
 
3
3
  module Kernel
4
+ @@INDENT_STACK = []
5
+
4
6
  # Like {IndentedIO::IndentedIOInterface#indent} except the underlying device is
5
7
  # not the receiver (Kernel) but $stdout. Kernel#indent also allows a block without
6
8
  # an argument. In that case it manipulates $stdout to print indented:
@@ -17,6 +19,9 @@ module Kernel
17
19
  # # Indented
18
20
  # # Even more indented
19
21
  #
22
+ # It called without a block, it indents $stdout. It should then be matched
23
+ # with a corresponding #undent
24
+ #
20
25
  def indent(levels = 1, string_ = IndentedIO.default_indent, string: string_, bol: nil, &block)
21
26
  block.nil? || block.arity <= 1 or raise IndentedIO::Error.new "Wrong number of parameters"
22
27
  obj = IndentedIO::IndentedIO.send(:new, $stdout, levels, string, bol)
@@ -32,10 +37,14 @@ module Kernel
32
37
  $stdout = saved_stdout
33
38
  end
34
39
  end
40
+ r
35
41
  else
36
- r = obj
42
+ $stdout = obj
37
43
  end
38
- r
44
+ end
45
+
46
+ def undent
47
+ $stdout = $stdout.send(:parent)
39
48
  end
40
49
  end
41
50
 
@@ -1,4 +1,4 @@
1
1
  module IndentedIO
2
2
  # Version number
3
- VERSION = '0.9.0'
3
+ VERSION = '0.10.0'
4
4
  end
metadata CHANGED
@@ -1,19 +1,32 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: indented_io
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2022-07-20 00:00:00.000000000 Z
12
- dependencies: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: string-text
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :development
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
13
26
  description: "\n IndentedIO extends Kernel, IO, and StringIO
14
27
  with an\n #indent method that redefines #print, printf,
15
- #puts,\n and #p to print their output indented. Indentations
16
- \n are stacked so that each new indentation adds to the\n
28
+ #puts,\n and #p to print their output indented. Indentations\n
29
+ \ are stacked so that each new indentation adds to the\n
17
30
  \ previous indendation\n "
18
31
  email:
19
32
  - claus.l.rasmussen@gmail.com
@@ -47,7 +60,6 @@ homepage: https://github.com/clrgit/indented_io
47
60
  licenses:
48
61
  - MIT
49
62
  metadata: {}
50
- post_install_message:
51
63
  rdoc_options: []
52
64
  require_paths:
53
65
  - lib
@@ -62,8 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
62
74
  - !ruby/object:Gem::Version
63
75
  version: '0'
64
76
  requirements: []
65
- rubygems_version: 3.3.18
66
- signing_key:
77
+ rubygems_version: 3.6.9
67
78
  specification_version: 4
68
79
  summary: Print indented text
69
80
  test_files: []