tty-box 0.3.0 → 0.7.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +56 -1
- data/LICENSE.txt +1 -1
- data/README.md +171 -34
- data/lib/tty-box.rb +1 -1
- data/lib/tty/box.rb +353 -59
- data/lib/tty/box/border.rb +21 -16
- data/lib/tty/box/version.rb +1 -1
- metadata +31 -55
- data/Rakefile +0 -8
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/examples/commander.rb +0 -54
- data/examples/connected.rb +0 -47
- data/spec/spec_helper.rb +0 -29
- data/spec/unit/align_spec.rb +0 -27
- data/spec/unit/border/parse_spec.rb +0 -61
- data/spec/unit/border_spec.rb +0 -149
- data/spec/unit/frame_spec.rb +0 -49
- data/spec/unit/padding_spec.rb +0 -46
- data/spec/unit/position_spec.rb +0 -23
- data/spec/unit/style_spec.rb +0 -121
- data/spec/unit/title_spec.rb +0 -35
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-box.gemspec +0 -29
@@ -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
|
data/spec/unit/border_spec.rb
DELETED
@@ -1,149 +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 and absolute position" 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 an ASCII box" do
|
32
|
-
box = TTY::Box.frame(
|
33
|
-
width: 10, height: 4,
|
34
|
-
border: :ascii
|
35
|
-
)
|
36
|
-
|
37
|
-
expect(box).to eq([
|
38
|
-
"+--------+\n",
|
39
|
-
"| |\n",
|
40
|
-
"| |\n",
|
41
|
-
"+--------+\n",
|
42
|
-
].join)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "creates frame with without top & bottom borders" do
|
46
|
-
box = TTY::Box.frame(
|
47
|
-
top: 0, left: 0,
|
48
|
-
width: 15, height: 4,
|
49
|
-
border: {
|
50
|
-
type: :thick,
|
51
|
-
top: false,
|
52
|
-
bottom: false
|
53
|
-
}
|
54
|
-
) { "Hello Piotr!" }
|
55
|
-
|
56
|
-
expect(box).to eq([
|
57
|
-
"\e[1;1H║Hello Piotr! \e[1;15H║",
|
58
|
-
"\e[2;1H║\e[2;15H║",
|
59
|
-
"\e[3;1H║\e[3;15H║",
|
60
|
-
"\e[4;1H║\e[4;15H║",
|
61
|
-
].join)
|
62
|
-
end
|
63
|
-
|
64
|
-
it "creates frame without left & right borders" do
|
65
|
-
box = TTY::Box.frame(
|
66
|
-
top: 0, left: 0,
|
67
|
-
width: 15, height: 4,
|
68
|
-
border: {
|
69
|
-
left: false,
|
70
|
-
right: false
|
71
|
-
}
|
72
|
-
) { "Hello Piotr!" }
|
73
|
-
|
74
|
-
expect(box).to eq([
|
75
|
-
"\e[1;1H───────────────",
|
76
|
-
"\e[2;1HHello Piotr! ",
|
77
|
-
"\e[3;1H",
|
78
|
-
"\e[4;1H───────────────"
|
79
|
-
].join)
|
80
|
-
end
|
81
|
-
|
82
|
-
it "creates frame without left & top borders" do
|
83
|
-
box = TTY::Box.frame(
|
84
|
-
top: 0, left: 0,
|
85
|
-
width: 15, height: 4,
|
86
|
-
border: {
|
87
|
-
left: false,
|
88
|
-
top: false
|
89
|
-
}
|
90
|
-
) { "Hello Piotr!" }
|
91
|
-
|
92
|
-
expect(box).to eq([
|
93
|
-
"\e[1;1HHello Piotr! \e[1;15H│",
|
94
|
-
"\e[2;1H\e[2;15H│",
|
95
|
-
"\e[3;1H\e[3;15H│",
|
96
|
-
"\e[4;1H──────────────┘"
|
97
|
-
].join)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "creates frame with all corners changed to cross" do
|
101
|
-
box = TTY::Box.frame(
|
102
|
-
width: 10, height: 4,
|
103
|
-
border: {
|
104
|
-
top_left: :cross,
|
105
|
-
top_right: :cross,
|
106
|
-
bottom_left: :cross,
|
107
|
-
bottom_right: :cross
|
108
|
-
}
|
109
|
-
)
|
110
|
-
|
111
|
-
expect(box).to eq([
|
112
|
-
"┼────────┼\n",
|
113
|
-
"│ │\n",
|
114
|
-
"│ │\n",
|
115
|
-
"┼────────┼\n"
|
116
|
-
].join)
|
117
|
-
end
|
118
|
-
|
119
|
-
it "creates frame with all corners changed to dividers" do
|
120
|
-
box = TTY::Box.frame(
|
121
|
-
width: 10, height: 4,
|
122
|
-
border: {
|
123
|
-
top_left: :divider_down,
|
124
|
-
top_right: :divider_left,
|
125
|
-
bottom_left: :divider_right,
|
126
|
-
bottom_right: :divider_up
|
127
|
-
}
|
128
|
-
) { "hello" }
|
129
|
-
|
130
|
-
expect(box).to eq([
|
131
|
-
"┬────────┤\n",
|
132
|
-
"│hello │\n",
|
133
|
-
"│ │\n",
|
134
|
-
"├────────┴\n"
|
135
|
-
].join)
|
136
|
-
end
|
137
|
-
|
138
|
-
it "fails to recognise border value" do
|
139
|
-
expect {
|
140
|
-
TTY::Box.frame(border: {left: :unknown})
|
141
|
-
}.to raise_error(ArgumentError, "Invalid border value: 'unknown' for :left")
|
142
|
-
end
|
143
|
-
|
144
|
-
it "fails to recognise border option" do
|
145
|
-
expect {
|
146
|
-
TTY::Box.frame(width: 35, height: 4, border: [:unknown])
|
147
|
-
}.to raise_error(ArgumentError, "Wrong value `[:unknown]` for :border configuration option")
|
148
|
-
end
|
149
|
-
end
|
data/spec/unit/frame_spec.rb
DELETED
@@ -1,49 +0,0 @@
|
|
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
|
data/spec/unit/padding_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
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
|
data/spec/unit/position_spec.rb
DELETED
@@ -1,23 +0,0 @@
|
|
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
|
data/spec/unit/style_spec.rb
DELETED
@@ -1,121 +0,0 @@
|
|
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
|
-
|
32
|
-
it "creates box without corners and only color fill" do
|
33
|
-
box = TTY::Box.frame(
|
34
|
-
width: 10, height: 4,
|
35
|
-
border: {
|
36
|
-
top_left: false,
|
37
|
-
top_right: false,
|
38
|
-
bottom_left: false,
|
39
|
-
bottom_right: false,
|
40
|
-
},
|
41
|
-
style: {
|
42
|
-
fg: :bright_yellow,
|
43
|
-
bg: :blue,
|
44
|
-
}
|
45
|
-
)
|
46
|
-
|
47
|
-
expect(box).to eq([
|
48
|
-
"──────────\n",
|
49
|
-
"│\e[44m\e[93m \e[0m\e[0m│\n",
|
50
|
-
"│\e[44m\e[93m \e[0m\e[0m│\n",
|
51
|
-
"──────────\n"
|
52
|
-
].join)
|
53
|
-
end
|
54
|
-
|
55
|
-
it "creates box without left & right borders and only color fill" do
|
56
|
-
box = TTY::Box.frame(
|
57
|
-
width: 10, height: 4,
|
58
|
-
border: {
|
59
|
-
left: false,
|
60
|
-
right: false
|
61
|
-
},
|
62
|
-
style: {
|
63
|
-
fg: :bright_yellow,
|
64
|
-
bg: :blue,
|
65
|
-
}
|
66
|
-
)
|
67
|
-
|
68
|
-
expect(box).to eq([
|
69
|
-
"──────────\n",
|
70
|
-
"\e[44m\e[93m \e[0m\e[0m\n",
|
71
|
-
"\e[44m\e[93m \e[0m\e[0m\n",
|
72
|
-
"──────────\n"
|
73
|
-
].join)
|
74
|
-
end
|
75
|
-
|
76
|
-
it "creates box without top & bottom borders and only color fill" do
|
77
|
-
box = TTY::Box.frame(
|
78
|
-
width: 10, height: 4,
|
79
|
-
border: {
|
80
|
-
top: false,
|
81
|
-
bottom: false
|
82
|
-
},
|
83
|
-
style: {
|
84
|
-
fg: :bright_yellow,
|
85
|
-
bg: :blue,
|
86
|
-
}
|
87
|
-
)
|
88
|
-
|
89
|
-
expect(box).to eq([
|
90
|
-
"│\e[44m\e[93m \e[0m\e[0m│\n",
|
91
|
-
"│\e[44m\e[93m \e[0m\e[0m│\n",
|
92
|
-
"│\e[44m\e[93m \e[0m\e[0m│\n",
|
93
|
-
"│\e[44m\e[93m \e[0m\e[0m│\n",
|
94
|
-
].join)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "creates box without top & left borders and only color fill" do
|
98
|
-
box = TTY::Box.frame(
|
99
|
-
width: 10, height: 4,
|
100
|
-
border: {
|
101
|
-
top: false,
|
102
|
-
left: false
|
103
|
-
},
|
104
|
-
style: {
|
105
|
-
fg: :bright_yellow,
|
106
|
-
bg: :blue,
|
107
|
-
border: {
|
108
|
-
fg: :bright_yellow,
|
109
|
-
bg: :blue
|
110
|
-
}
|
111
|
-
}
|
112
|
-
)
|
113
|
-
|
114
|
-
expect(box).to eq([
|
115
|
-
"\e[44m\e[93m \e[0m\e[0m\e[44m\e[93m│\e[0m\e[0m\n",
|
116
|
-
"\e[44m\e[93m \e[0m\e[0m\e[44m\e[93m│\e[0m\e[0m\n",
|
117
|
-
"\e[44m\e[93m \e[0m\e[0m\e[44m\e[93m│\e[0m\e[0m\n",
|
118
|
-
"\e[44m\e[93m────\e[0m\e[0m\e[44m\e[93m─────\e[0m\e[0m\e[44m\e[93m┘\e[0m\e[0m\n"
|
119
|
-
].join)
|
120
|
-
end
|
121
|
-
end
|