text-ui 0.2.2 → 0.2.3
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/lib/tui/format.rb +24 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d91e3529649ba6f00b7bb088f402babfc220c0689988513409f6f6c09d62f723
|
|
4
|
+
data.tar.gz: 7064c994012ba786930f774d1b3fde673e07255222c1d77d7c75020e468081cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5b897cf1fc75f04e76d536430549c87717cbc95d38e3a600df8c33f4ca1eb00f2b6a58ff80d04e2101be9dd6036ad78ce9011e9903e088665f713698c46cedb0
|
|
7
|
+
data.tar.gz: fa3341f2470449d78251d5ec0807b57d6424e21ce8c4976c6d64a6e981b4d0a4c2b01ce20d846fd27da4423e209a2d231ed37cb268b91923a8e9e4a6c38302a5
|
data/lib/tui/format.rb
CHANGED
|
@@ -132,19 +132,33 @@ module Tui
|
|
|
132
132
|
end
|
|
133
133
|
end
|
|
134
134
|
unless width.nil?
|
|
135
|
-
collect! { |line|
|
|
136
|
-
if line.size > width
|
|
137
|
-
"#{line[...(width - 1)]}░"
|
|
138
|
-
elsif fill && line.size < width
|
|
139
|
-
extra = (width - line.size)
|
|
140
|
-
"#{' ' * (extra/2)}#{line}#{' ' * (extra/2 + (extra.odd? ? 1 : 0))}"
|
|
141
|
-
else
|
|
142
|
-
line
|
|
143
|
-
end
|
|
144
|
-
}
|
|
135
|
+
collect! { |line| crop_line line, width }
|
|
145
136
|
end
|
|
146
137
|
self
|
|
147
138
|
end
|
|
148
139
|
|
|
140
|
+
private
|
|
141
|
+
|
|
142
|
+
# Crop line to fit the width
|
|
143
|
+
def crop_line line, width
|
|
144
|
+
line_width = Tools.calc_width(line)
|
|
145
|
+
if line_width > width
|
|
146
|
+
cut_line = "#{line[...(width - 1)]}"
|
|
147
|
+
if Tools.calc_width(cut_line) > width - 1
|
|
148
|
+
# happens if there're chars for 2+ cells
|
|
149
|
+
while Tools.calc_width(cut_line) > width - 1
|
|
150
|
+
cut_line.chop!
|
|
151
|
+
end
|
|
152
|
+
extra_spaces = width - Tools.calc_width(cut_line) - 1
|
|
153
|
+
cut_line << ' ' * extra_spaces
|
|
154
|
+
end
|
|
155
|
+
cut_line << '░'
|
|
156
|
+
elsif fill && line_width < width
|
|
157
|
+
extra = (width - line_width)
|
|
158
|
+
"#{' ' * (extra/2)}#{line}#{' ' * (extra/2 + (extra.odd? ? 1 : 0))}"
|
|
159
|
+
else
|
|
160
|
+
line
|
|
161
|
+
end
|
|
162
|
+
end
|
|
149
163
|
end
|
|
150
164
|
end
|