tty-box 0.2.1 → 0.6.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.
@@ -1,40 +1,80 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TTY
2
4
  module Box
3
5
  # A class reponsible for retrieving border options
4
6
  #
5
7
  # @api private
6
8
  class Border
9
+ BORDER_VALUES = [
10
+ :corner_bottom_right,
11
+ :corner_top_right,
12
+ :corner_top_left,
13
+ :corner_bottom_left,
14
+ :divider_left,
15
+ :divider_up,
16
+ :divider_down,
17
+ :divider_right,
18
+ :line,
19
+ :pipe,
20
+ :cross
21
+ ].freeze
22
+
7
23
  def self.parse(border)
8
24
  case border
9
25
  when Hash
10
- new(border.fetch(:type, :light),
11
- border.fetch(:top, true),
12
- border.fetch(:left, true),
13
- border.fetch(:right, true),
14
- border.fetch(:bottom, true))
26
+ new(**border)
15
27
  when *TTY::Box::BOX_CHARS.keys
16
- new(border, true, true, true, true)
28
+ new(type: border)
17
29
  else
18
30
  raise ArgumentError,
19
31
  "Wrong value `#{border}` for :border configuration option"
20
32
  end
21
33
  end
22
34
 
23
- attr_reader :type, :top, :left, :right, :bottom
35
+ attr_reader :type, :top, :top_left, :top_right, :left, :right,
36
+ :bottom, :bottom_left, :bottom_right
24
37
 
25
38
  alias top? top
26
39
  alias left? left
27
40
  alias right? right
28
41
  alias bottom? bottom
42
+ alias top_left? top_left
43
+ alias top_right? top_right
44
+ alias bottom_left? bottom_left
45
+ alias bottom_right? bottom_right
46
+
47
+ def initialize(type: :light,
48
+ top: :line,
49
+ top_left: :corner_top_left,
50
+ top_right: :corner_top_right,
51
+ left: :pipe,
52
+ right: :pipe,
53
+ bottom: :line,
54
+ bottom_left: :corner_bottom_left,
55
+ bottom_right: :corner_bottom_right)
56
+
57
+ @type = type
58
+ @top = check_name(:top, top)
59
+ @top_left = check_name(:top_left, top_left)
60
+ @top_right = check_name(:top_right, top_right)
61
+ @left = check_name(:left, left)
62
+ @right = check_name(:right, right)
63
+ @bottom = check_name(:bottom, bottom)
64
+ @bottom_left = check_name(:bottom_left, bottom_left)
65
+ @bottom_right = check_name(:bottom_right, bottom_right)
66
+ end
67
+
68
+ private
29
69
 
30
- def initialize(type, top, left, right, bottom)
31
- @type = type
32
- @top = top
33
- @left = left
34
- @right = right
35
- @bottom = bottom
70
+ # Check if border values name is allowed
71
+ # @api private
72
+ def check_name(key, value)
73
+ unless (BORDER_VALUES.include?(:"#{value}") || [true, false].include?(value))
74
+ raise ArgumentError, "Invalid border value: '#{value}' for #{key.inspect}"
75
+ end
76
+ value
36
77
  end
37
78
  end # Border
38
79
  end # Box
39
80
  end # TTY
40
-
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module Box
5
- VERSION = "0.2.1"
5
+ VERSION = "0.6.0"
6
6
  end # Box
7
7
  end # TTY
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.1
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-10 00:00:00.000000000 Z
11
+ date: 2020-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pastel
@@ -16,118 +16,97 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.7.2
19
+ version: '0.8'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.7.2
26
+ version: '0.8'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: tty-cursor
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.6.0
33
+ version: '0.7'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.6.0
40
+ version: '0.7'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: strings
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.1.4
47
+ version: 0.2.0
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.4
55
- - !ruby/object:Gem::Dependency
56
- name: bundler
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '1.16'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '1.16'
54
+ version: 0.2.0
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: rake
71
57
  requirement: !ruby/object:Gem::Requirement
72
58
  requirements:
73
- - - "~>"
59
+ - - ">="
74
60
  - !ruby/object:Gem::Version
75
- version: '10.0'
61
+ version: '0'
76
62
  type: :development
77
63
  prerelease: false
78
64
  version_requirements: !ruby/object:Gem::Requirement
79
65
  requirements:
80
- - - "~>"
66
+ - - ">="
81
67
  - !ruby/object:Gem::Version
82
- version: '10.0'
68
+ version: '0'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: rspec
85
71
  requirement: !ruby/object:Gem::Requirement
86
72
  requirements:
87
- - - "~>"
73
+ - - ">="
88
74
  - !ruby/object:Gem::Version
89
75
  version: '3.0'
90
76
  type: :development
91
77
  prerelease: false
92
78
  version_requirements: !ruby/object:Gem::Requirement
93
79
  requirements:
94
- - - "~>"
80
+ - - ">="
95
81
  - !ruby/object:Gem::Version
96
82
  version: '3.0'
97
- description: Draw various frames and boxes in your terminal interface.
83
+ description: Draw various frames and boxes in the terminal window.
98
84
  email:
99
- - ''
85
+ - piotr@piotrmurach.com
100
86
  executables: []
101
87
  extensions: []
102
- extra_rdoc_files: []
88
+ extra_rdoc_files:
89
+ - README.md
90
+ - CHANGELOG.md
91
+ - LICENSE.txt
103
92
  files:
104
93
  - CHANGELOG.md
105
94
  - LICENSE.txt
106
95
  - README.md
107
- - Rakefile
108
- - bin/console
109
- - bin/setup
110
- - examples/commander.rb
111
96
  - lib/tty-box.rb
112
97
  - lib/tty/box.rb
113
98
  - lib/tty/box/border.rb
114
99
  - 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
123
- - tasks/console.rake
124
- - tasks/coverage.rake
125
- - tasks/spec.rake
126
- - tty-box.gemspec
127
- homepage: https://piotrmurach.github.io/tty
100
+ homepage: https://ttytoolkit.org
128
101
  licenses:
129
102
  - MIT
130
- metadata: {}
103
+ metadata:
104
+ allowed_push_host: https://rubygems.org
105
+ bug_tracker_uri: https://github.com/piotrmurach/tty-box/issues
106
+ changelog_uri: https://github.com/piotrmurach/tty-box/blob/master/CHANGELOG.md
107
+ documentation_uri: https://www.rubydoc.info/gems/tty-box
108
+ homepage_uri: https://ttytoolkit.org
109
+ source_code_uri: https://github.com/piotrmurach/tty-box
131
110
  post_install_message:
132
111
  rdoc_options: []
133
112
  require_paths:
@@ -136,16 +115,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
136
115
  requirements:
137
116
  - - ">="
138
117
  - !ruby/object:Gem::Version
139
- version: '0'
118
+ version: 2.0.0
140
119
  required_rubygems_version: !ruby/object:Gem::Requirement
141
120
  requirements:
142
121
  - - ">="
143
122
  - !ruby/object:Gem::Version
144
123
  version: '0'
145
124
  requirements: []
146
- rubyforge_project:
147
- rubygems_version: 2.7.3
125
+ rubygems_version: 3.1.2
148
126
  signing_key:
149
127
  specification_version: 4
150
- summary: Draw various frames and boxes in your terminal interface.
128
+ summary: Draw various frames and boxes in the terminal window.
151
129
  test_files: []
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- require "bundler/gem_tasks"
2
-
3
- FileList['tasks/**/*.rake'].each(&method(:import))
4
-
5
- desc 'Run all specs'
6
- task ci: %w[ spec ]
7
-
8
- task default: :spec
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "tty/box"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
data/bin/setup DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,52 +0,0 @@
1
- require 'tty-box'
2
-
3
- print TTY::Cursor.clear_screen
4
-
5
- box_1 = TTY::Box.frame(
6
- top: 2,
7
- left: 10,
8
- width: 30,
9
- height: 10,
10
- border: :thick,
11
- align: :center,
12
- padding: 3,
13
- title: {
14
- top_left: ' file1 '
15
- },
16
- style: {
17
- fg: :bright_yellow,
18
- bg: :blue,
19
- border: {
20
- fg: :bright_yellow,
21
- bg: :blue
22
- }
23
- }
24
- ) do
25
- "Drawing a box in terminal emulator"
26
- end
27
-
28
- box_2 = TTY::Box.frame(
29
- top: 8,
30
- left: 34,
31
- width: 30,
32
- height: 10,
33
- border: :thick,
34
- align: :center,
35
- padding: 3,
36
- title: {
37
- top_left: ' file2 '
38
- },
39
- style: {
40
- fg: :bright_yellow,
41
- bg: :blue,
42
- border: {
43
- fg: :bright_yellow,
44
- bg: :blue
45
- }
46
- }
47
- ) do
48
- "Drawing a box in terminal emulator"
49
- end
50
-
51
- puts box_1 + box_2
52
- print "\n" * 5
@@ -1,29 +0,0 @@
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
@@ -1,27 +0,0 @@
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
@@ -1,70 +0,0 @@
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