tty-box 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a9daceddbaca9658a170dde1ce447aebc05af9972015cc71aa003de5e120b2c8
4
- data.tar.gz: d9ba3ea634b244a7b6044d1060a1cb38a2164646a6ff7bc9c716000bd49e78cd
3
+ metadata.gz: 5b0c9524c939271bcc5168d3cc467b790657109218f53284a6328db8173225b8
4
+ data.tar.gz: cfe75b8c4b2f3567e03bd511ecd5a914fcda3180ab4339fb82412255cfd24206
5
5
  SHA512:
6
- metadata.gz: b7d43320b77c1edb2164684e90f5a2431e58f48f31838170b20b16349f2d0074c4274fe92348457546bafd2ad29874ca5b889c9c7a40c7271721fa599a0ae2cf
7
- data.tar.gz: 422d8dc8a0b7eaa183e2f7db40a3e2c0d89dae5bdfde98181919109bdc86555de82a957f3855fe73338f285d40df118fdf82a2622a87831dc50899ad3e9fcea2
6
+ metadata.gz: 0c5988a4893aa1c2411429c40d88445ad51a3a3306ecde927125868aa2741686835eabbebe538ea8338639981cf0985318d48e27f586057eb73b492b7797996d
7
+ data.tar.gz: ce051a4e7751ecd3a8caaa50ff626fb4d7929bdb348025c41ed2324c74cd5b055225112d85bb2ffdb90420d05c36b8308131e4756f652eefb4755781e7bd94bc
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.2.1] - 2018-09-10
4
+
5
+ ### Fixed
6
+ * Fix content alignment by @DannyBen
7
+
3
8
  ## [v0.2.0] - 2018-07-31
4
9
 
5
10
  ### Changed
@@ -10,5 +15,6 @@
10
15
 
11
16
  * Initial implementation and release
12
17
 
18
+ [v0.2.1]: https://github.com/piotrmurach/tty-box/compare/v0.2.0...v0.2.1
13
19
  [v0.2.0]: https://github.com/piotrmurach/tty-box/compare/v0.1.0...v0.2.0
14
20
  [v0.1.0]: https://github.com/piotrmurach/tty-box/compare/v0.1.0
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ <div align="center">
2
+ <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://cdn.rawgit.com/piotrmurach/tty/master/images/tty.png" alt="tty logo" /></a>
3
+ </div>
4
+
1
5
  # TTY::Box [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
2
6
 
3
7
  [![Gem Version](https://badge.fury.io/rb/tty-box.svg)][gem]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module Box
5
- VERSION = "0.2.0"
5
+ VERSION = "0.2.1"
6
6
  end # Box
7
7
  end # TTY
@@ -0,0 +1,29 @@
1
+ if ENV['COVERAGE'] || ENV['TRAVIS']
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
+
10
+ SimpleCov.start do
11
+ command_name 'spec'
12
+ add_filter 'spec'
13
+ end
14
+ end
15
+
16
+ require "bundler/setup"
17
+ require "tty/box"
18
+
19
+ RSpec.configure do |config|
20
+ # Enable flags like --only-failures and --next-failure
21
+ config.example_status_persistence_file_path = ".rspec_status"
22
+
23
+ # Disable RSpec exposing methods globally on `Module` and `main`
24
+ config.disable_monkey_patching!
25
+
26
+ config.expect_with :rspec do |c|
27
+ c.syntax = :expect
28
+ end
29
+ end
@@ -0,0 +1,27 @@
1
+ RSpec.describe TTY::Box, ':align option' do
2
+ it "aligns content without positioning" do
3
+ box = TTY::Box.frame(width: 26, height: 4, align: :center) do
4
+ "Drawing a box in terminal emulator"
5
+ end
6
+
7
+ expect(box).to eq([
8
+ "┌────────────────────────┐\n",
9
+ "│ Drawing a box in │\n",
10
+ "│ terminal emulator │\n",
11
+ "└────────────────────────┘\n"
12
+ ].join)
13
+ end
14
+
15
+ it "aligns content with the option" do
16
+ box = TTY::Box.frame(top: 0, left: 0, width: 26, height: 4, align: :center) do
17
+ "Drawing a box in terminal emulator"
18
+ end
19
+
20
+ expect(box).to eq([
21
+ "\e[1;1H┌────────────────────────┐",
22
+ "\e[2;1H│ Drawing a box in \e[2;26H│",
23
+ "\e[3;1H│ terminal emulator \e[3;26H│",
24
+ "\e[4;1H└────────────────────────┘"
25
+ ].join)
26
+ end
27
+ end
@@ -0,0 +1,70 @@
1
+ RSpec.describe TTY::Box, ':border option' do
2
+ it "creates frame with double lines and no position" do
3
+ box = TTY::Box.frame(
4
+ width: 35, height: 4,
5
+ border: :thick
6
+ )
7
+
8
+ expect(box).to eq([
9
+ "╔═════════════════════════════════╗\n",
10
+ "║ ║\n",
11
+ "║ ║\n",
12
+ "╚═════════════════════════════════╝\n"
13
+ ].join)
14
+ end
15
+
16
+ it "creates frame with double lines" do
17
+ box = TTY::Box.frame(
18
+ top: 0, left: 0,
19
+ width: 35, height: 4,
20
+ border: :thick
21
+ )
22
+
23
+ expect(box).to eq([
24
+ "\e[1;1H╔═════════════════════════════════╗",
25
+ "\e[2;1H║\e[2;35H║",
26
+ "\e[3;1H║\e[3;35H║",
27
+ "\e[4;1H╚═════════════════════════════════╝"
28
+ ].join)
29
+ end
30
+
31
+ it "creates frame with without top & bottom borders" do
32
+ box = TTY::Box.frame(
33
+ top: 0, left: 0,
34
+ width: 35, height: 4,
35
+ border: {
36
+ type: :thick,
37
+ top: false,
38
+ bottom: false
39
+ }
40
+ ) { "Hello Piotr!" }
41
+
42
+ expect(box).to eq([
43
+ "\e[2;1H║Hello Piotr! \e[2;35H║",
44
+ "\e[3;1H║\e[3;35H║",
45
+ ].join)
46
+ end
47
+
48
+ it "creates frame without left & right borders" do
49
+ box = TTY::Box.frame(
50
+ top: 0, left: 0,
51
+ width: 35, height: 4,
52
+ border: {
53
+ left: false,
54
+ right: false
55
+ }
56
+ ) { "Hello Piotr!" }
57
+
58
+ expect(box).to eq([
59
+ "\e[1;1H┌─────────────────────────────────┐",
60
+ "Hello Piotr! ",
61
+ "\e[4;1H└─────────────────────────────────┘"
62
+ ].join)
63
+ end
64
+
65
+ it "fails to recognise border option" do
66
+ expect {
67
+ TTY::Box.frame(width: 35, height: 4, border: [:unknown])
68
+ }.to raise_error(ArgumentError, "Wrong value `[:unknown]` for :border configuration option")
69
+ end
70
+ end
@@ -0,0 +1,49 @@
1
+ RSpec.describe TTY::Box, '#frame' do
2
+ it "creates frame with only width & height values" do
3
+ output = TTY::Box.frame(width: 35, height: 4)
4
+
5
+ expect(output).to eq([
6
+ "┌─────────────────────────────────┐\n",
7
+ "│ │\n",
8
+ "│ │\n",
9
+ "└─────────────────────────────────┘\n"
10
+ ].join)
11
+ end
12
+
13
+ it "creates frame at a position with direct width & height values" do
14
+ output = TTY::Box.frame(top: 0, left: 0, width: 35, height: 4)
15
+
16
+ expect(output).to eq([
17
+ "\e[1;1H┌─────────────────────────────────┐",
18
+ "\e[2;1H│\e[2;35H│",
19
+ "\e[3;1H│\e[3;35H│",
20
+ "\e[4;1H└─────────────────────────────────┘"
21
+ ].join)
22
+ end
23
+
24
+ it "displays content when block provided" do
25
+ output = TTY::Box.frame(top: 0, left: 0, width: 35, height: 4) do
26
+ "Hello world!"
27
+ end
28
+
29
+ expect(output).to eq([
30
+ "\e[1;1H┌─────────────────────────────────┐",
31
+ "\e[2;1H│Hello world! \e[2;35H│",
32
+ "\e[3;1H│\e[3;35H│",
33
+ "\e[4;1H└─────────────────────────────────┘"
34
+ ].join)
35
+ end
36
+
37
+ it "wraps content when exceeding width" do
38
+ box = TTY::Box.frame(top: 0, left: 0, width: 20, height: 4) do
39
+ "Drawing a box in terminal emulator"
40
+ end
41
+
42
+ expect(box).to eq([
43
+ "\e[1;1H┌──────────────────┐",
44
+ "\e[2;1H│Drawing a box in \e[2;20H│",
45
+ "\e[3;1H│terminal emulator \e[3;20H│",
46
+ "\e[4;1H└──────────────────┘"
47
+ ].join)
48
+ end
49
+ end
@@ -0,0 +1,46 @@
1
+ RSpec.describe TTY::Box, ':padding option' do
2
+ it "padds internal content without position arguments" do
3
+ box = TTY::Box.frame(width: 30, height: 6, padding: 1) do
4
+ "Drawing a box in terminal emulator"
5
+ end
6
+
7
+ expect(box).to eq([
8
+ "┌────────────────────────────┐\n",
9
+ "│ │\n",
10
+ "│ Drawing a box in terminal │\n",
11
+ "│ emulator │\n",
12
+ "│ │\n",
13
+ "└────────────────────────────┘\n"
14
+ ].join)
15
+ end
16
+
17
+ it "padds internal content with with padding as integer" do
18
+ box = TTY::Box.frame(top: 0, left: 0, width: 30, height: 6, padding: 1) do
19
+ "Drawing a box in terminal emulator"
20
+ end
21
+
22
+ expect(box).to eq([
23
+ "\e[1;1H┌────────────────────────────┐",
24
+ "\e[2;1H│ \e[2;30H│",
25
+ "\e[3;1H│ Drawing a box in terminal \e[3;30H│",
26
+ "\e[4;1H│ emulator \e[4;30H│",
27
+ "\e[5;1H│ \e[5;30H│",
28
+ "\e[6;1H└────────────────────────────┘"
29
+ ].join)
30
+ end
31
+
32
+ it "padds internal content with padding as array" do
33
+ box = TTY::Box.frame(top: 0, left: 0, width: 30, height: 6, padding: [1,3,1,3]) do
34
+ "Drawing a box in terminal emulator"
35
+ end
36
+
37
+ expect(box).to eq([
38
+ "\e[1;1H┌────────────────────────────┐",
39
+ "\e[2;1H│ \e[2;30H│",
40
+ "\e[3;1H│ Drawing a box in \e[3;30H│",
41
+ "\e[4;1H│ terminal emulator \e[4;30H│",
42
+ "\e[5;1H│ \e[5;30H│",
43
+ "\e[6;1H└────────────────────────────┘"
44
+ ].join)
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ RSpec.describe TTY::Box, ':top, :left options' do
2
+ it "skips positioning when no top & left values provided" do
3
+ output = TTY::Box.frame(width: 35, height: 4)
4
+
5
+ expect(output).to eq([
6
+ "┌─────────────────────────────────┐\n",
7
+ "│ │\n",
8
+ "│ │\n",
9
+ "└─────────────────────────────────┘\n"
10
+ ].join)
11
+ end
12
+
13
+ it "allows to absolutely position within the terminal window" do
14
+ output = TTY::Box.frame(top: 10, left: 40, width: 35, height: 4)
15
+
16
+ expect(output).to eq([
17
+ "\e[11;41H┌─────────────────────────────────┐",
18
+ "\e[12;41H│\e[12;75H│",
19
+ "\e[13;41H│\e[13;75H│",
20
+ "\e[14;41H└─────────────────────────────────┘"
21
+ ].join)
22
+ end
23
+ end
@@ -0,0 +1,31 @@
1
+ RSpec.describe TTY::Box, ":style option" do
2
+ it "applies styling to content and border" do
3
+ box = TTY::Box.frame(
4
+ top: 0,
5
+ left: 0,
6
+ width: 30,
7
+ height: 4,
8
+ border: :thick,
9
+ title: {
10
+ top_left: ' file1 '
11
+ },
12
+ style: {
13
+ fg: :bright_yellow,
14
+ bg: :blue,
15
+ border: {
16
+ fg: :bright_yellow,
17
+ bg: :blue
18
+ }
19
+ }
20
+ ) do
21
+ "Midnight Commander\nis the best"
22
+ end
23
+
24
+ expect(box).to eq([
25
+ "\e[1;1H\e[44m\e[93m╔\e[0m\e[0m\e[44m file1 \e[0m\e[44m\e[93m══════════\e[0m\e[0m\e[44m\e[93m═══════════\e[0m\e[0m\e[44m\e[93m╗\e[0m\e[0m",
26
+ "\e[2;1H\e[44m\e[93m║\e[0m\e[0m\e[44m\e[93mMidnight Commander \e[0m\e[0m\e[2;30H\e[44m\e[93m║\e[0m\e[0m",
27
+ "\e[3;1H\e[44m\e[93m║\e[0m\e[0m\e[44m\e[93mis the best \e[0m\e[0m\e[3;30H\e[44m\e[93m║\e[0m\e[0m",
28
+ "\e[4;1H\e[44m\e[93m╚\e[0m\e[0m\e[44m\e[93m══════════════\e[0m\e[0m\e[44m\e[93m══════════════\e[0m\e[0m\e[44m\e[93m╝\e[0m\e[0m"
29
+ ].join)
30
+ end
31
+ end
@@ -0,0 +1,35 @@
1
+ RSpec.describe TTY::Box, ':title option' do
2
+ it "allows to specify top border titles" do
3
+ output = TTY::Box.frame(
4
+ top: 0, left: 0,
5
+ width: 35, height: 4,
6
+ title: {
7
+ top_left: 'left',
8
+ top_right: 'right',
9
+ top_center: 'center'
10
+ })
11
+
12
+ expect(output).to eq([
13
+ "\e[1;1H┌left─────────center─────────right┐",
14
+ "\e[2;1H│\e[2;35H│\e[3;1H│\e[3;35H│",
15
+ "\e[4;1H└─────────────────────────────────┘"
16
+ ].join)
17
+ end
18
+
19
+ it "allows to specify bottom border titles" do
20
+ output = TTY::Box.frame(
21
+ top: 0, left: 0,
22
+ width: 35, height: 4,
23
+ title: {
24
+ bottom_left: 'left',
25
+ bottom_right: 'right',
26
+ bottom_center: 'center'
27
+ })
28
+
29
+ expect(output).to eq([
30
+ "\e[1;1H┌─────────────────────────────────┐",
31
+ "\e[2;1H│\e[2;35H│\e[3;1H│\e[3;35H│",
32
+ "\e[4;1H└left─────────center─────────right┘"
33
+ ].join)
34
+ end
35
+ end
data/tty-box.gemspec CHANGED
@@ -13,18 +13,15 @@ Gem::Specification.new do |spec|
13
13
  spec.homepage = "https://piotrmurach.github.io/tty"
14
14
  spec.license = "MIT"
15
15
 
16
- spec.files = Dir.glob('lib/**/*.rb') + Dir.glob('bin/*')
17
- spec.files += Dir.glob('examples/*.rb') + Dir.glob('tasks/*.rake')
18
- spec.files += Dir.glob('[A-Z]*') + Dir.glob('[a-z]*\.*')
19
- spec.files.reject! { |f| f.match(%r{.lock$}) }
20
-
21
- spec.bindir = "exe"
16
+ spec.files = Dir['{lib,spec,examples}/**/*.rb']
17
+ spec.files += Dir['{bin,tasks}/*', 'tty-box.gemspec']
18
+ spec.files += Dir['README.md', 'CHANGELOG.md', 'LICENSE.txt', 'Rakefile']
22
19
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
20
  spec.require_paths = ["lib"]
24
21
 
25
22
  spec.add_dependency 'pastel', '~> 0.7.2'
26
23
  spec.add_dependency 'tty-cursor', '~> 0.6.0'
27
- spec.add_dependency 'strings', '~> 0.1.1'
24
+ spec.add_dependency 'strings', '~> 0.1.4'
28
25
 
29
26
  spec.add_development_dependency "bundler", "~> 1.16"
30
27
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-box
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-31 00:00:00.000000000 Z
11
+ date: 2018-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.1
47
+ version: 0.1.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.1.1
54
+ version: 0.1.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -102,12 +102,9 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - CHANGELOG.md
105
- - CODE_OF_CONDUCT.md
106
- - Gemfile
107
105
  - LICENSE.txt
108
106
  - README.md
109
107
  - Rakefile
110
- - appveyor.yml
111
108
  - bin/console
112
109
  - bin/setup
113
110
  - examples/commander.rb
@@ -115,6 +112,14 @@ files:
115
112
  - lib/tty/box.rb
116
113
  - lib/tty/box/border.rb
117
114
  - lib/tty/box/version.rb
115
+ - spec/spec_helper.rb
116
+ - spec/unit/align_spec.rb
117
+ - spec/unit/border_spec.rb
118
+ - spec/unit/frame_spec.rb
119
+ - spec/unit/padding_spec.rb
120
+ - spec/unit/position_spec.rb
121
+ - spec/unit/style_spec.rb
122
+ - spec/unit/title_spec.rb
118
123
  - tasks/console.rake
119
124
  - tasks/coverage.rake
120
125
  - tasks/spec.rake
data/CODE_OF_CONDUCT.md DELETED
@@ -1,74 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- In the interest of fostering an open and welcoming environment, we as
6
- contributors and maintainers pledge to making participation in our project and
7
- our community a harassment-free experience for everyone, regardless of age, body
8
- size, disability, ethnicity, gender identity and expression, level of experience,
9
- nationality, personal appearance, race, religion, or sexual identity and
10
- orientation.
11
-
12
- ## Our Standards
13
-
14
- Examples of behavior that contributes to creating a positive environment
15
- include:
16
-
17
- * Using welcoming and inclusive language
18
- * Being respectful of differing viewpoints and experiences
19
- * Gracefully accepting constructive criticism
20
- * Focusing on what is best for the community
21
- * Showing empathy towards other community members
22
-
23
- Examples of unacceptable behavior by participants include:
24
-
25
- * The use of sexualized language or imagery and unwelcome sexual attention or
26
- advances
27
- * Trolling, insulting/derogatory comments, and personal or political attacks
28
- * Public or private harassment
29
- * Publishing others' private information, such as a physical or electronic
30
- address, without explicit permission
31
- * Other conduct which could reasonably be considered inappropriate in a
32
- professional setting
33
-
34
- ## Our Responsibilities
35
-
36
- Project maintainers are responsible for clarifying the standards of acceptable
37
- behavior and are expected to take appropriate and fair corrective action in
38
- response to any instances of unacceptable behavior.
39
-
40
- Project maintainers have the right and responsibility to remove, edit, or
41
- reject comments, commits, code, wiki edits, issues, and other contributions
42
- that are not aligned to this Code of Conduct, or to ban temporarily or
43
- permanently any contributor for other behaviors that they deem inappropriate,
44
- threatening, offensive, or harmful.
45
-
46
- ## Scope
47
-
48
- This Code of Conduct applies both within project spaces and in public spaces
49
- when an individual is representing the project or its community. Examples of
50
- representing a project or community include using an official project e-mail
51
- address, posting via an official social media account, or acting as an appointed
52
- representative at an online or offline event. Representation of a project may be
53
- further defined and clarified by project maintainers.
54
-
55
- ## Enforcement
56
-
57
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
- reported by contacting the project team at [email]. All
59
- complaints will be reviewed and investigated and will result in a response that
60
- is deemed necessary and appropriate to the circumstances. The project team is
61
- obligated to maintain confidentiality with regard to the reporter of an incident.
62
- Further details of specific enforcement policies may be posted separately.
63
-
64
- Project maintainers who do not follow or enforce the Code of Conduct in good
65
- faith may face temporary or permanent repercussions as determined by other
66
- members of the project's leadership.
67
-
68
- ## Attribution
69
-
70
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
- available at [http://contributor-covenant.org/version/1/4][version]
72
-
73
- [homepage]: http://contributor-covenant.org
74
- [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
-
5
- gemspec
6
-
7
- group :test do
8
- gem 'benchmark-ips', '~> 2.7.2'
9
- gem 'simplecov', '~> 0.14.1'
10
- gem 'coveralls', '~> 0.8.21'
11
- end
12
-
13
- group :metrics do
14
- gem 'yard', '~> 0.9.14'
15
- gem 'yardstick', '~> 0.9.9'
16
- end
data/appveyor.yml DELETED
@@ -1,23 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake ci
10
- environment:
11
- matrix:
12
- - ruby_version: "200"
13
- - ruby_version: "200-x64"
14
- - ruby_version: "21"
15
- - ruby_version: "21-x64"
16
- - ruby_version: "22"
17
- - ruby_version: "22-x64"
18
- - ruby_version: "23"
19
- - ruby_version: "23-x64"
20
- - ruby_version: "24"
21
- - ruby_version: "24-x64"
22
- - ruby_version: "25"
23
- - ruby_version: "25-x64"