terminal-join 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 548a3e0ae9f050dcfcf6fee502893afacef2318ce08116a3ea1f472d784341c5
4
+ data.tar.gz: e2503fc99fdfd510783ac2b01724ff02fcba50d1df1e9dac10fa7b05ff9206d2
5
+ SHA512:
6
+ metadata.gz: dbdeb30f838c087e82fed5a43b2836e2496d93d1b4fcd9f5157c92f99f67ac27ecd10334d823b25afbb6059af1d22f63ee721cc415472b9b1c8ffdc349489b34
7
+ data.tar.gz: 1ec681561df88b390eddf2a78159fdf4af569de34eaea596b6db338841d29701998cb7fd5d07745b624aff2974bf2e05e198ab5000935235b41a9be36c274d6b
data/.rubocop.yml ADDED
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.1
3
+
4
+ Layout/MultilineMethodCallIndentation:
5
+ Enabled: false
6
+
7
+ Style/MultilineBlockChain:
8
+ Enabled: false
9
+
10
+ Metrics/ParameterLists:
11
+ Enabled: false
12
+
13
+ Metrics/MethodLength:
14
+ Enabled: false
15
+
16
+ Metrics/AbcSize:
17
+ Enabled: false
18
+
19
+ Style/Documentation:
20
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## [1.0.0] - 2023-01-30
2
+
3
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at nnbnh@protonmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in terminal-join.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+
10
+ gem 'rubocop', '~> 1.21'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 NNB
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,179 @@
1
+ <img width="100%" src="https://capsule-render.vercel.app/api?type=waving&section=header&color=DC2626&fontColor=FEF2F2&height=256&text=Terminal%20Join&desc=Join%20ANSI%20strings%20horizontally%2Fvertically%20with%20style&fontAlignY=40" />
2
+
3
+ ## 💡 About
4
+
5
+ Terminal Layout let you style and join ANSI strings horizontally/vertically.
6
+
7
+ ## 📥 Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ ```sh
12
+ bundle add terminal-join
13
+ ```
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ ```sh
18
+ gem install terminal-join
19
+ ```
20
+
21
+ ## ⌨️ Usage
22
+
23
+ ### 📃 API
24
+
25
+ In Ruby do:
26
+
27
+ ```rb
28
+ require 'terminal/join'
29
+ ```
30
+
31
+ To style ANSI string:
32
+
33
+ ```rb
34
+ Terminal::Join.style(`figlet Hello, World!`)
35
+ Terminal::Join.style(
36
+ `figlet Hello, World!`,
37
+ :bold, :italic, # Paint arguments (check out https://github.com/janlelis/paint#usage)
38
+ halign: :bottom, # Horizontal alignment, available options are :top, :bottom and :center (default)
39
+ valign: :right, # Vertical alignment, available options are :left, :right and :center (default)
40
+ width: IO.console.winsize[1],
41
+ height: 6,
42
+ margin: [0, 2] # [horizontal_margin, vertical_margin]
43
+ # You can write `margin: 2` to margin on all side.
44
+ )
45
+ ```
46
+
47
+ Join ANSI strings horizontally or vertically:
48
+
49
+ ```rb
50
+ Terminal::Join.horizontal(*%w[Foo Bar].map { `figlet #{_1}` })
51
+ # =>
52
+ # _____ ____
53
+ # | ___|__ ___ | __ ) __ _ _ __
54
+ # | |_ / _ \ / _ \ | _ \ / _` | '__|
55
+ # | _| (_) | (_) || |_) | (_| | |
56
+ # |_| \___/ \___/ |____/ \__,_|_|
57
+
58
+ Terminal::Join.horizontal(
59
+ *[*'A'..'D'].map { `figlet "#{_1}\n#{_1}"` },
60
+ separator: `figlet ,`,
61
+ align: :bottom
62
+ )
63
+ # =>
64
+ # _ ____ ____ ____
65
+ # / \ | __ ) / ___| | _ \
66
+ # / _ \ | _ \ | | | | | |
67
+ # / ___ \ | |_) | | |___ | |_| |
68
+ # /_/ \_\ |____/ \____| |____/
69
+ #
70
+ # _ ____ ____ ____
71
+ # / \ | __ ) / ___| | _ \
72
+ # / _ \ | _ \ | | | | | |
73
+ # / ___ \ _ | |_) | _ | |___ _ | |_| |
74
+ # /_/ \_\( )|____/ ( ) \____|( )|____/
75
+ # |/ |/ |/
76
+
77
+ Terminal::Join.horizontal(*%w[Foo Bar].map { `figlet #{_1}` }) do |max_height|
78
+ " | \n" * max_height
79
+ end
80
+ # =>
81
+ # _____ | ____
82
+ # | ___|__ ___ | | __ ) __ _ _ __
83
+ # | |_ / _ \ / _ \ | | _ \ / _` | '__|
84
+ # | _| (_) | (_) | | | |_) | (_| | |
85
+ # |_| \___/ \___/ | |____/ \__,_|_|
86
+ # |
87
+
88
+ Terminal::Join.vertical(*[*1..3].map { `figlet #{_1}` })
89
+ # =>
90
+ # _
91
+ # / |
92
+ # | |
93
+ # | |
94
+ # |_|
95
+ #
96
+ # ____
97
+ # |___ \
98
+ # __) |
99
+ # / __/
100
+ # |_____|
101
+ #
102
+ # _____
103
+ # |___ /
104
+ # |_ \
105
+ # ___) |
106
+ # |____/
107
+
108
+ Terminal::Join.vertical(
109
+ *[*1..3].map { `figlet #{_1.to_s * _1}` },
110
+ separator: '-' * 8,
111
+ align: :right
112
+ )
113
+ # =>
114
+ # _
115
+ # / |
116
+ # | |
117
+ # | |
118
+ # |_|
119
+ #
120
+ # --------
121
+ # ____ ____
122
+ # |___ \|___ \
123
+ # __) | __) |
124
+ # / __/ / __/
125
+ # |_____|_____|
126
+ #
127
+ # --------
128
+ # _______________
129
+ # |___ /___ /___ /
130
+ # |_ \ |_ \ |_ \
131
+ # ___) |__) |__) |
132
+ # |____/____/____/
133
+
134
+ Terminal::Join.vertical(*[*1..3].map { `figlet #{_1.to_s * _1}` }) do |max_width|
135
+ '-' * max_width
136
+ end
137
+ # =>
138
+ # _
139
+ # / |
140
+ # | |
141
+ # | |
142
+ # |_|
143
+ #
144
+ # -----------------
145
+ # ____ ____
146
+ # |___ \|___ \
147
+ # __) | __) |
148
+ # / __/ / __/
149
+ # |_____|_____|
150
+ #
151
+ # -----------------
152
+ # _______________
153
+ # |___ /___ /___ /
154
+ # |_ \ |_ \ |_ \
155
+ # ___) |__) |__) |
156
+ # |____/____/____/
157
+ ```
158
+
159
+ ### ➕ String and array extensions
160
+
161
+ ```rb
162
+ require 'terminal/join/extensions'
163
+
164
+ `figlet Hello, World!`.style(:bold, margin: [4, 1])
165
+
166
+ %w[Foo Bar].map { `figlet #{_1}` }.hjoin
167
+ [*'A'..'D'].map { `figlet "#{_1}\n#{_1}"` }.hjoin(`figlet ,`, align: :bottom)
168
+ %w[Foo Bar].map { `figlet #{_1}` }.hjoin { " | \n" * _1 }
169
+
170
+ [*1..3].map { `figlet #{_1}` }.vjoin
171
+ [*1..3].map { `figlet #{_1.to_s * _1}` }.vjoin('-' * 8, align: :right)
172
+ [*1..3].map { `figlet #{_1.to_s * _1}` }.vjoin { '-' * _1 }
173
+ ```
174
+
175
+ ## 💌 Credits
176
+
177
+ - [**Gum**](https://github.com/charmbracelet/gum) by [Charm](https://github.com/charmbracelet)
178
+
179
+ <a href="https://codeberg.org/NNB"><img width="100%" src="https://capsule-render.vercel.app/api?type=waving&section=footer&color=DC2626&fontColor=FEF2F2&height=128&desc=Made%20with%20%26lt;3%20by%20NNB&descAlignY=80" /></a>
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rubocop/rake_task'
5
+
6
+ RuboCop::RakeTask.new
7
+
8
+ task default: :rubocop
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../join' unless defined? Terminal::Join
4
+
5
+ class String
6
+ def style(*ansi, halign: :center, valign: :center, width: 0, height: 0, margin: 0)
7
+ Terminal::Join.style(self, *ansi, halign:, valign:, width:, height:, margin:)
8
+ end
9
+ end
10
+
11
+ class Array
12
+ def hjoin(separator = nil, align: :center, &block)
13
+ Terminal::Join.horizontal(*self, separator:, align:, &block)
14
+ end
15
+
16
+ def vjoin(separator = nil, align: :center, &block)
17
+ Terminal::Join.vertical(*self, separator:, align:, &block)
18
+ end
19
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Terminal
4
+ class Join
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'paint'
4
+ require 'unicode/display_width'
5
+
6
+ require_relative 'join/version'
7
+
8
+ module Terminal
9
+ class Join
10
+ def self.style(string, *ansi, halign: :center, valign: :center, width: 0, height: 0, margin: 0)
11
+ margin = [margin, margin] unless margin.is_a?(Array)
12
+ widths = Paint.unpaint(string).lines.map { Unicode::DisplayWidth.of _1.chomp }
13
+ max_width = [width, *widths].max
14
+ pad_width = max_width - widths.max + margin[0] * 2
15
+ pad_height = [(height - string.lines.size), 0].max + margin[1] * 2
16
+
17
+ string
18
+ .lines
19
+ .map.with_index do |line, index|
20
+ (' ' * pad_width)
21
+ .insert(
22
+ {
23
+ left: margin[0],
24
+ right: -1 - margin[0],
25
+ center: pad_width / 2
26
+ }[valign],
27
+ Paint[line.chomp, *ansi] +
28
+ Paint[' ' * (widths.max - widths[index]), *ansi || nil]
29
+ )
30
+ end
31
+ .then do
32
+ ([' ' * max_width] * pad_height)
33
+ .insert(
34
+ {
35
+ top: margin[1],
36
+ bottom: -1 - margin[1],
37
+ center: pad_height / 2
38
+ }[halign],
39
+ *_1
40
+ )
41
+ end
42
+ .join("\n")
43
+ end
44
+
45
+ def self.horizontal(*strings, separator: nil, align: :center, &block)
46
+ max_height = strings.flatten.map { _1.to_s.lines.size }.max
47
+ separator = block.call max_height if block
48
+
49
+ if separator.nil?
50
+ strings.flatten
51
+ else
52
+ strings.flat_map { [_1, separator] }[0...-1]
53
+ end
54
+ .map { self.style _1.to_s, halign: align, height: max_height }
55
+ .map { _1.lines.map(&:chomp) }
56
+ .transpose.map(&:join).join("\n")
57
+ end
58
+
59
+ def self.vertical(*strings, separator: nil, align: :center, &block)
60
+ Paint.unpaint(strings.flatten.join("\n"))
61
+ .lines.map { Unicode::DisplayWidth.of _1 }.max => max_width
62
+ separator = block.call max_width if block
63
+
64
+ if separator.nil?
65
+ strings.flatten
66
+ else
67
+ strings.flat_map { [_1, separator] }[0...-1]
68
+ end
69
+ .map { self.style _1.to_s, valign: align, width: max_width }
70
+ .join("\n")
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,6 @@
1
+ module Terminal
2
+ class Join
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: terminal-join
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - NNB
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: paint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: unicode-display_width
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.4'
34
+ - - ">="
35
+ - !ruby/object:Gem::Version
36
+ version: 2.4.2
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '2.4'
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: 2.4.2
47
+ description: Terminal Layout let you style and join ANSI strings horizontally/vertically.
48
+ email:
49
+ - nnbnh@protonmail.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files:
53
+ - README.md
54
+ - CHANGELOG.md
55
+ - LICENSE.txt
56
+ files:
57
+ - ".rubocop.yml"
58
+ - CHANGELOG.md
59
+ - CODE_OF_CONDUCT.md
60
+ - Gemfile
61
+ - LICENSE.txt
62
+ - README.md
63
+ - Rakefile
64
+ - lib/terminal/join.rb
65
+ - lib/terminal/join/extensions.rb
66
+ - lib/terminal/join/version.rb
67
+ - sig/ansi_layout.rbs
68
+ homepage: https://codeberg.org/NNB/terminal-join.rb
69
+ licenses:
70
+ - MIT
71
+ metadata:
72
+ homepage_uri: https://codeberg.org/NNB/terminal-join.rb
73
+ source_code_uri: https://codeberg.org/NNB/terminal-join.rb
74
+ changelog_uri: https://codeberg.org/NNB/terminal-join.rb/src/branch/main/CHANGELOG.md
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: 3.1.3
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.4.5
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Join ANSI strings horizontally/vertically with style.
94
+ test_files: []