tty-box 0.5.0 → 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,47 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative '../lib/tty-box'
4
-
5
- print TTY::Cursor.clear_screen
6
-
7
- box_1 = TTY::Box.frame(
8
- top: 3,
9
- left: 10,
10
- width: 15,
11
- height: 5,
12
- border: {
13
- type: :thick,
14
- right: false,
15
- },
16
- align: :center,
17
- padding: [1, 2],
18
- style: {
19
- bg: :red,
20
- border: {
21
- bg: :red
22
- }
23
- }
24
- ) { "Space" }
25
-
26
- box_2 = TTY::Box.frame(
27
- top: 3,
28
- left: 25,
29
- width: 15,
30
- height: 5,
31
- border: {
32
- type: :thick,
33
- top_left: :divider_down,
34
- bottom_left: :divider_up
35
- },
36
- align: :center,
37
- padding: [1,2],
38
- style: {
39
- bg: :red,
40
- border: {
41
- bg: :red
42
- }
43
- }
44
- ) { "Invaders!" }
45
-
46
- puts box_1 + box_2
47
- print "\n" * 5
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-box"
4
-
5
- puts TTY::Cursor.clear_screen
6
- puts TTY::Box.info "Deploying application", top: 2, left: 2
7
- puts TTY::Box.success "Deploying application", top: 2, left: 29
8
- puts TTY::Box.warn "Deploying application", top: 8, left: 2
9
- puts TTY::Box.error "Deploying application", top: 8, left: 29
10
-
11
- puts
@@ -1,14 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "../lib/tty-box"
4
-
5
- box = TTY::Box.frame(
6
- width: 29,
7
- height: 7,
8
- align: :center,
9
- padding: 1
10
- ) do
11
- "Closes #360\r\n\r\nCloses !217"
12
- end
13
-
14
- puts box
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- if ENV['COVERAGE'] || ENV['TRAVIS']
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require "bundler/setup"
19
- require "tty/box"
20
-
21
- RSpec.configure do |config|
22
- # Enable flags like --only-failures and --next-failure
23
- config.example_status_persistence_file_path = ".rspec_status"
24
-
25
- # Disable RSpec exposing methods globally on `Module` and `main`
26
- config.disable_monkey_patching!
27
-
28
- config.expect_with :rspec do |c|
29
- c.syntax = :expect
30
- end
31
- end
@@ -1,29 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Box, ':align option' do
4
- it "aligns content without positioning" do
5
- box = TTY::Box.frame(width: 26, height: 4, align: :center) do
6
- "Drawing a box in terminal emulator"
7
- end
8
-
9
- expect(box).to eq([
10
- "┌────────────────────────┐\n",
11
- "│ Drawing a box in │\n",
12
- "│ terminal emulator │\n",
13
- "└────────────────────────┘\n"
14
- ].join)
15
- end
16
-
17
- it "aligns content with the option" do
18
- box = TTY::Box.frame(top: 0, left: 0, width: 26, height: 4, align: :center) do
19
- "Drawing a box in terminal emulator"
20
- end
21
-
22
- expect(box).to eq([
23
- "\e[1;1H┌────────────────────────┐",
24
- "\e[2;1H│ Drawing a box in \e[2;26H│",
25
- "\e[3;1H│ terminal emulator \e[3;26H│",
26
- "\e[4;1H└────────────────────────┘"
27
- ].join)
28
- end
29
- end
@@ -1,61 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Box::Border, '.parse' do
4
- it "parses default border" do
5
- border = TTY::Box::Border.parse({})
6
- top_border = [border.top_left, border.top, border.top_right]
7
- bottom_border = [border.bottom_left, border.bottom, border.bottom_right]
8
-
9
- expect(border.type).to eq(:light)
10
- expect(top_border).to eq([:corner_top_left, :line, :corner_top_right])
11
- expect(bottom_border).to eq([:corner_bottom_left, :line, :corner_bottom_right])
12
- expect(border.left).to eq(:pipe)
13
- expect(border.right).to eq(:pipe)
14
- end
15
-
16
- it "parses only border type" do
17
- border = TTY::Box::Border.parse(:thick)
18
- top_border = [border.top_left, border.top, border.top_right]
19
- bottom_border = [border.bottom_left, border.bottom, border.bottom_right]
20
-
21
- expect(border.type).to eq(:thick)
22
- expect(top_border).to eq([:corner_top_left, :line, :corner_top_right])
23
- expect(bottom_border).to eq([:corner_bottom_left, :line, :corner_bottom_right])
24
- expect(border.left).to eq(:pipe)
25
- expect(border.right).to eq(:pipe)
26
- end
27
-
28
- it "parses custom border" do
29
- border = TTY::Box::Border.parse({
30
- top: true,
31
- top_left: :cross,
32
- top_right: :cross,
33
- bottom: true,
34
- bottom_left: :cross,
35
- bottom_right: :cross
36
- })
37
-
38
- top_border = [border.top_left, border.top, border.top_right]
39
- bottom_border = [border.bottom_left, border.bottom, border.bottom_right]
40
-
41
- expect(border.type).to eq(:light)
42
- expect(top_border).to eq([:cross, true, :cross])
43
- expect(bottom_border).to eq([:cross, true, :cross])
44
- end
45
-
46
- it "parses divider values" do
47
- border = TTY::Box::Border.parse({
48
- top_left: :divider_right,
49
- top_right: :divider_left,
50
- bottom_left: :divider_down,
51
- bottom_right: :divider_up
52
- })
53
-
54
- top_border = [border.top_left, border.top, border.top_right]
55
- bottom_border = [border.bottom_left, border.bottom, border.bottom_right]
56
-
57
- expect(border.type).to eq(:light)
58
- expect(top_border).to eq([:divider_right, :line, :divider_left])
59
- expect(bottom_border).to eq([:divider_down, :line, :divider_up])
60
- end
61
- end
@@ -1,151 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Box, ':border option' do
4
- it "creates frame with double lines and no position" do
5
- box = TTY::Box.frame(
6
- width: 35, height: 4,
7
- border: :thick
8
- )
9
-
10
- expect(box).to eq([
11
- "╔═════════════════════════════════╗\n",
12
- "║ ║\n",
13
- "║ ║\n",
14
- "╚═════════════════════════════════╝\n"
15
- ].join)
16
- end
17
-
18
- it "creates frame with double lines and absolute position" do
19
- box = TTY::Box.frame(
20
- top: 0, left: 0,
21
- width: 35, height: 4,
22
- border: :thick
23
- )
24
-
25
- expect(box).to eq([
26
- "\e[1;1H╔═════════════════════════════════╗",
27
- "\e[2;1H║\e[2;35H║",
28
- "\e[3;1H║\e[3;35H║",
29
- "\e[4;1H╚═════════════════════════════════╝"
30
- ].join)
31
- end
32
-
33
- it "creates an ASCII box" do
34
- box = TTY::Box.frame(
35
- width: 10, height: 4,
36
- border: :ascii
37
- )
38
-
39
- expect(box).to eq([
40
- "+--------+\n",
41
- "| |\n",
42
- "| |\n",
43
- "+--------+\n",
44
- ].join)
45
- end
46
-
47
- it "creates frame with without top & bottom borders" do
48
- box = TTY::Box.frame(
49
- top: 0, left: 0,
50
- width: 15, height: 4,
51
- border: {
52
- type: :thick,
53
- top: false,
54
- bottom: false
55
- }
56
- ) { "Hello Piotr!" }
57
-
58
- expect(box).to eq([
59
- "\e[1;1H║Hello Piotr! \e[1;15H║",
60
- "\e[2;1H║\e[2;15H║",
61
- "\e[3;1H║\e[3;15H║",
62
- "\e[4;1H║\e[4;15H║",
63
- ].join)
64
- end
65
-
66
- it "creates frame without left & right borders" do
67
- box = TTY::Box.frame(
68
- top: 0, left: 0,
69
- width: 15, height: 4,
70
- border: {
71
- left: false,
72
- right: false
73
- }
74
- ) { "Hello Piotr!" }
75
-
76
- expect(box).to eq([
77
- "\e[1;1H───────────────",
78
- "\e[2;1HHello Piotr! ",
79
- "\e[3;1H",
80
- "\e[4;1H───────────────"
81
- ].join)
82
- end
83
-
84
- it "creates frame without left & top borders" do
85
- box = TTY::Box.frame(
86
- top: 0, left: 0,
87
- width: 15, height: 4,
88
- border: {
89
- left: false,
90
- top: false
91
- }
92
- ) { "Hello Piotr!" }
93
-
94
- expect(box).to eq([
95
- "\e[1;1HHello Piotr! \e[1;15H│",
96
- "\e[2;1H\e[2;15H│",
97
- "\e[3;1H\e[3;15H│",
98
- "\e[4;1H──────────────┘"
99
- ].join)
100
- end
101
-
102
- it "creates frame with all corners changed to cross" do
103
- box = TTY::Box.frame(
104
- width: 10, height: 4,
105
- border: {
106
- top_left: :cross,
107
- top_right: :cross,
108
- bottom_left: :cross,
109
- bottom_right: :cross
110
- }
111
- )
112
-
113
- expect(box).to eq([
114
- "┼────────┼\n",
115
- "│ │\n",
116
- "│ │\n",
117
- "┼────────┼\n"
118
- ].join)
119
- end
120
-
121
- it "creates frame with all corners changed to dividers" do
122
- box = TTY::Box.frame(
123
- width: 10, height: 4,
124
- border: {
125
- top_left: :divider_down,
126
- top_right: :divider_left,
127
- bottom_left: :divider_right,
128
- bottom_right: :divider_up
129
- }
130
- ) { "hello" }
131
-
132
- expect(box).to eq([
133
- "┬────────┤\n",
134
- "│hello │\n",
135
- "│ │\n",
136
- "├────────┴\n"
137
- ].join)
138
- end
139
-
140
- it "fails to recognise border value" do
141
- expect {
142
- TTY::Box.frame(border: {left: :unknown})
143
- }.to raise_error(ArgumentError, "Invalid border value: 'unknown' for :left")
144
- end
145
-
146
- it "fails to recognise border option" do
147
- expect {
148
- TTY::Box.frame(width: 35, height: 4, border: [:unknown])
149
- }.to raise_error(ArgumentError, "Wrong value `[:unknown]` for :border configuration option")
150
- end
151
- end
@@ -1,51 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Box, "custom frames" do
4
- it "draws info type message" do
5
- box = TTY::Box.info("Hello world!")
6
-
7
- expect(box).to eq([
8
- "\e[104m\e[30m╔\e[0m\e[0m\e[104m\e[30m ℹ INFO \e[0m\e[0m\e[104m\e[30m═══\e[0m\e[0m\e[104m\e[30m═══\e[0m\e[0m\e[104m\e[30m╗\e[0m\e[0m\n",
9
- "\e[104m\e[30m║\e[0m\e[0m\e[104m\e[30m \e[0m\e[0m\e[104m\e[30m║\e[0m\e[0m\n",
10
- "\e[104m\e[30m║\e[0m\e[0m\e[104m\e[30m Hello world! \e[0m\e[0m\e[104m\e[30m║\e[0m\e[0m\n",
11
- "\e[104m\e[30m║\e[0m\e[0m\e[104m\e[30m \e[0m\e[0m\e[104m\e[30m║\e[0m\e[0m\n",
12
- "\e[104m\e[30m╚\e[0m\e[0m\e[104m\e[30m═══════\e[0m\e[0m\e[104m\e[30m═══════\e[0m\e[0m\e[104m\e[30m╝\e[0m\e[0m\n"
13
- ].join)
14
- end
15
-
16
- it "draws warning type message" do
17
- box = TTY::Box.warn("Hello world!")
18
-
19
- expect(box).to eq([
20
- "\e[103m\e[30m╔\e[0m\e[0m\e[103m\e[30m ⚠ WARNING \e[0m\e[0m\e[103m\e[30m═\e[0m\e[0m\e[103m\e[30m══\e[0m\e[0m\e[103m\e[30m╗\e[0m\e[0m\n",
21
- "\e[103m\e[30m║\e[0m\e[0m\e[103m\e[30m \e[0m\e[0m\e[103m\e[30m║\e[0m\e[0m\n",
22
- "\e[103m\e[30m║\e[0m\e[0m\e[103m\e[30m Hello world! \e[0m\e[0m\e[103m\e[30m║\e[0m\e[0m\n",
23
- "\e[103m\e[30m║\e[0m\e[0m\e[103m\e[30m \e[0m\e[0m\e[103m\e[30m║\e[0m\e[0m\n",
24
- "\e[103m\e[30m╚\e[0m\e[0m\e[103m\e[30m═══════\e[0m\e[0m\e[103m\e[30m═══════\e[0m\e[0m\e[103m\e[30m╝\e[0m\e[0m\n"
25
- ].join)
26
- end
27
-
28
- it "draws success type message" do
29
- box = TTY::Box.success("Hello world!")
30
-
31
- expect(box).to eq([
32
- "\e[102m\e[30m╔\e[0m\e[0m\e[102m\e[30m ✔ OK \e[0m\e[0m\e[102m\e[30m════\e[0m\e[0m\e[102m\e[30m════\e[0m\e[0m\e[102m\e[30m╗\e[0m\e[0m\n",
33
- "\e[102m\e[30m║\e[0m\e[0m\e[102m\e[30m \e[0m\e[0m\e[102m\e[30m║\e[0m\e[0m\n",
34
- "\e[102m\e[30m║\e[0m\e[0m\e[102m\e[30m Hello world! \e[0m\e[0m\e[102m\e[30m║\e[0m\e[0m\n",
35
- "\e[102m\e[30m║\e[0m\e[0m\e[102m\e[30m \e[0m\e[0m\e[102m\e[30m║\e[0m\e[0m\n",
36
- "\e[102m\e[30m╚\e[0m\e[0m\e[102m\e[30m═══════\e[0m\e[0m\e[102m\e[30m═══════\e[0m\e[0m\e[102m\e[30m╝\e[0m\e[0m\n"
37
- ].join)
38
- end
39
-
40
- it "draws error type message" do
41
- box = TTY::Box.error("Hello world!")
42
-
43
- expect(box).to eq([
44
- "\e[41m\e[97m╔\e[0m\e[0m\e[41m\e[97m ⨯ ERROR \e[0m\e[0m\e[41m\e[97m══\e[0m\e[0m\e[41m\e[97m═══\e[0m\e[0m\e[41m\e[97m╗\e[0m\e[0m\n",
45
- "\e[41m\e[97m║\e[0m\e[0m\e[41m\e[97m \e[0m\e[0m\e[41m\e[97m║\e[0m\e[0m\n",
46
- "\e[41m\e[97m║\e[0m\e[0m\e[41m\e[97m Hello world! \e[0m\e[0m\e[41m\e[97m║\e[0m\e[0m\n",
47
- "\e[41m\e[97m║\e[0m\e[0m\e[41m\e[97m \e[0m\e[0m\e[41m\e[97m║\e[0m\e[0m\n",
48
- "\e[41m\e[97m╚\e[0m\e[0m\e[41m\e[97m═══════\e[0m\e[0m\e[41m\e[97m═══════\e[0m\e[0m\e[41m\e[97m╝\e[0m\e[0m\n"
49
- ].join)
50
- end
51
- end
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- RSpec.describe TTY::Box, "#frame" do
4
- it "creates frame without content & width & height values" do
5
- output = TTY::Box.frame
6
-
7
- expect(output).to eq([
8
- "┌─┐\n",
9
- "└─┘\n"
10
- ].join)
11
- end
12
-
13
- it "creates frame around content without width & height values" do
14
- output = TTY::Box.frame "Hello world!"
15
-
16
- expect(output).to eq([
17
- "┌────────────┐\n",
18
- "│Hello world!│\n",
19
- "└────────────┘\n"
20
- ].join)
21
- end
22
-
23
- it "creates frame around content without width & height values" do
24
- output = TTY::Box.frame "Hello\nworld!"
25
-
26
- expect(output).to eq([
27
- "┌──────┐\n",
28
- "│Hello │\n",
29
- "│world!│\n",
30
- "└──────┘\n"
31
- ].join)
32
- end
33
-
34
- it "creates frame based on multiline content without width & height values" do
35
- output = TTY::Box.frame "Hello", "world!"
36
-
37
- expect(output).to eq([
38
- "┌──────┐\n",
39
- "│Hello │\n",
40
- "│world!│\n",
41
- "└──────┘\n"
42
- ].join)
43
- end
44
-
45
- it "creates frame around block content without width & height values" do
46
- output = TTY::Box.frame do
47
- "Hello world!"
48
- end
49
-
50
- expect(output).to eq([
51
- "┌────────────┐\n",
52
- "│Hello world!│\n",
53
- "└────────────┘\n"
54
- ].join)
55
- end
56
- it "creates frame with only width & height values" do
57
- output = TTY::Box.frame(width: 35, height: 4)
58
-
59
- expect(output).to eq([
60
- "┌─────────────────────────────────┐\n",
61
- "│ │\n",
62
- "│ │\n",
63
- "└─────────────────────────────────┘\n"
64
- ].join)
65
- end
66
-
67
- it "creates frame at a position with direct width & height values" do
68
- output = TTY::Box.frame(top: 0, left: 0, width: 35, height: 4)
69
-
70
- expect(output).to eq([
71
- "\e[1;1H┌─────────────────────────────────┐",
72
- "\e[2;1H│\e[2;35H│",
73
- "\e[3;1H│\e[3;35H│",
74
- "\e[4;1H└─────────────────────────────────┘"
75
- ].join)
76
- end
77
-
78
- it "displays content when block provided" do
79
- output = TTY::Box.frame(top: 0, left: 0, width: 35, height: 4) do
80
- "Hello world!"
81
- end
82
-
83
- expect(output).to eq([
84
- "\e[1;1H┌─────────────────────────────────┐",
85
- "\e[2;1H│Hello world! \e[2;35H│",
86
- "\e[3;1H│\e[3;35H│",
87
- "\e[4;1H└─────────────────────────────────┘"
88
- ].join)
89
- end
90
-
91
- it "wraps content when exceeding width" do
92
- box = TTY::Box.frame(top: 0, left: 0, width: 20, height: 4) do
93
- "Drawing a box in terminal emulator"
94
- end
95
-
96
- expect(box).to eq([
97
- "\e[1;1H┌──────────────────┐",
98
- "\e[2;1H│Drawing a box in \e[2;20H│",
99
- "\e[3;1H│terminal emulator \e[3;20H│",
100
- "\e[4;1H└──────────────────┘"
101
- ].join)
102
- end
103
-
104
- it "correctly displays colored content" do
105
- box = TTY::Box.frame(width: 35, height: 3) do
106
- Pastel.new.green.on_red("Hello world!")
107
- end
108
-
109
- expect(box).to eq([
110
- "┌─────────────────────────────────┐\n",
111
- "│\e[32;41mHello world!\e[0m │\n",
112
- "└─────────────────────────────────┘\n"
113
- ].join)
114
- end
115
-
116
- it "handles \r\n line breaks" do
117
- box = TTY::Box.frame(
118
- width: 29,
119
- height: 7
120
- ) do
121
- "Closes #360\r\n\r\nCloses !217"
122
- end
123
-
124
- expect(box).to eq([
125
- "┌───────────────────────────┐\r\n",
126
- "│Closes #360 │\r\n",
127
- "│ │\r\n",
128
- "│Closes !217 │\r\n",
129
- "│ │\r\n",
130
- "│ │\r\n",
131
- "└───────────────────────────┘\r\n"
132
- ].join)
133
- end
134
- end