terminal-join 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile +2 -0
- data/lib/terminal/join/version.rb +2 -2
- data/lib/terminal/join.rb +10 -7
- data/sig/ansi_layout.rbs +6 -3
- 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: 4632ed70f1e9f11fd27622d9a3275adc5620d42feb6f756d517bf06e71450664
|
4
|
+
data.tar.gz: 9d4c892f9f18caa6169fd335fffcac2ca21c7225d101265244d36448486e3866
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
|
-
|
10
|
-
|
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
|
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 {
|
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
|
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 {
|
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
|
-
|
3
|
-
|
4
|
-
|
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.
|
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-
|
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.
|
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.
|