terminal-join 1.0.1 → 1.0.3

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: af4f77b2eedaa198dd5276fd1b44e2906ad53f2425111441b09003c9f0993827
4
- data.tar.gz: ca825fc10dedb431f3c4b1e0b301ce0af35560068078a2ed46765fa488947cb7
3
+ metadata.gz: 4632ed70f1e9f11fd27622d9a3275adc5620d42feb6f756d517bf06e71450664
4
+ data.tar.gz: 9d4c892f9f18caa6169fd335fffcac2ca21c7225d101265244d36448486e3866
5
5
  SHA512:
6
- metadata.gz: 2528e5cbdf18dba398b877dbb0f762d911280765d15964b616c84d2cb0587b54616cadcfd69aa56f29591d8f1c795c471bf355edc170499c45fc97fb394ef098
7
- data.tar.gz: 217f084bb96ef62fa5fd7db87f31144878e2efbf5fc35153ca41ca511cdc0fcbff4ddff7e38c5d213d28f4ae32204ab59b1d96b26fffd1a68c58a80636f7e213
6
+ metadata.gz: 52a73493b0b3e6a07ab821cc5c475395ad4029ac80a878e2f0ad43b6e3ddde97453b01928ce1666b1c1f3aad1caf309eb8ced68f6f4e51a3f19702d22bf93122
7
+ data.tar.gz: 3e61d912fb3feaa607a270b45810bb75dfb8336fec8d9405fef166c92aeaf511b04053e23add74d7a91157e4c7fe1c246933ac5e7a18844a513f0f04c82ac2cf
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.0.2] - 2023-08-14
2
+
3
+ - Change `Terminal::Join` from class to module.
4
+ - Added `.rbs`.
5
+
6
+ ## [1.0.2] - 2023-08-08
7
+
8
+ - Fixed `style` bug when string have ansi code after last newline.
9
+
1
10
  ## [1.0.1] - 2023-01-30
2
11
 
3
12
  - Downgrade required Ruby version from `3.1.3` to `3.1.2`.
data/Gemfile CHANGED
@@ -8,3 +8,5 @@ gemspec
8
8
  gem 'rake', '~> 13.0'
9
9
 
10
10
  gem 'rubocop', '~> 1.21'
11
+
12
+ gem 'rbs'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Terminal
4
- class Join
5
- VERSION = '1.0.1'
4
+ module Join
5
+ VERSION = '1.0.3'
6
6
  end
7
7
  end
data/lib/terminal/join.rb CHANGED
@@ -6,10 +6,13 @@ require 'unicode/display_width'
6
6
  require_relative 'join/version'
7
7
 
8
8
  module Terminal
9
- class Join
10
- def self.style(string, *ansi, halign: :center, valign: :center, width: 0, height: 0, margin: 0)
9
+ module Join
10
+ module_function
11
+
12
+ def style(string, *ansi, halign: :center, valign: :center, width: 0, height: 0, margin: 0)
11
13
  margin = [margin, margin] unless margin.is_a?(Array)
12
14
  widths = Paint.unpaint(string).lines.map { Unicode::DisplayWidth.of _1.chomp }
15
+ widths = [0] if widths.empty?
13
16
  max_width = [width, *widths].max
14
17
  pad_width = max_width - widths.max + margin[0] * 2
15
18
  pad_height = [(height - string.lines.size), 0].max + margin[1] * 2
@@ -25,7 +28,7 @@ module Terminal
25
28
  center: pad_width / 2
26
29
  }[valign],
27
30
  Paint[line.chomp, *ansi] +
28
- Paint[' ' * (widths.max - widths[index]), *ansi || nil]
31
+ Paint[' ' * (widths.max - (widths[index] || 0)), *ansi || nil]
29
32
  )
30
33
  end
31
34
  .then do
@@ -42,7 +45,7 @@ module Terminal
42
45
  .join("\n")
43
46
  end
44
47
 
45
- def self.horizontal(*strings, separator: nil, align: :center, &block)
48
+ def horizontal(*strings, separator: nil, align: :center, &block)
46
49
  max_height = strings.flatten.map { _1.to_s.lines.size }.max
47
50
  separator = block.call max_height if block
48
51
 
@@ -51,12 +54,12 @@ module Terminal
51
54
  else
52
55
  strings.flat_map { [_1, separator] }[0...-1]
53
56
  end
54
- .map { self.style _1.to_s, halign: align, height: max_height }
57
+ .map { style _1.to_s, halign: align, height: max_height }
55
58
  .map { _1.lines.map(&:chomp) }
56
59
  .transpose.map(&:join).join("\n")
57
60
  end
58
61
 
59
- def self.vertical(*strings, separator: nil, align: :center, &block)
62
+ def vertical(*strings, separator: nil, align: :center, &block)
60
63
  Paint.unpaint(strings.flatten.join("\n"))
61
64
  .lines.map { Unicode::DisplayWidth.of _1 }.max => max_width
62
65
  separator = block.call max_width if block
@@ -66,7 +69,7 @@ module Terminal
66
69
  else
67
70
  strings.flat_map { [_1, separator] }[0...-1]
68
71
  end
69
- .map { self.style _1.to_s, valign: align, width: max_width }
72
+ .map { style _1.to_s, valign: align, width: max_width }
70
73
  .join("\n")
71
74
  end
72
75
  end
data/sig/ansi_layout.rbs CHANGED
@@ -1,6 +1,9 @@
1
1
  module Terminal
2
- class Join
3
- VERSION: String
4
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
2
+ module Join
3
+ def self?.style: (untyped string, *untyped ansi, ?halign: Symbol, ?valign: Symbol, ?width: Integer, ?height: Integer, ?margin: Integer) -> untyped
4
+
5
+ def self?.horizontal: (*untyped strings, ?separator: untyped?, ?align: Symbol) ?{ () -> untyped } -> untyped
6
+
7
+ def self?.vertical: (*untyped strings, ?separator: untyped?, ?align: Symbol) ?{ () -> untyped } -> untyped
5
8
  end
6
9
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal-join
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - NNB
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-29 00:00:00.000000000 Z
11
+ date: 2023-08-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paint
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.3.20
90
+ rubygems_version: 3.4.10
91
91
  signing_key:
92
92
  specification_version: 4
93
93
  summary: Join ANSI strings horizontally/vertically with style.