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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tui/format.rb +24 -10
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e9aa7470ce1e80b3fa0c6d0de7c3c5dacd67d51e8a75b9d1609a83f63012cd09
4
- data.tar.gz: 873b51cbc60dfdb196d50a88c6e6e457a2bd6e3f4c9b8d25e0a5db1cd1ddc57d
3
+ metadata.gz: d91e3529649ba6f00b7bb088f402babfc220c0689988513409f6f6c09d62f723
4
+ data.tar.gz: 7064c994012ba786930f774d1b3fde673e07255222c1d77d7c75020e468081cd
5
5
  SHA512:
6
- metadata.gz: 84b46fe510be54628e3b8fa1ab307b7d7768c52e7fb12ddfd9491fea60a45cb5d61dcf0f8bd62a0b65d90b7a5f14e7656146735a7241a1040e27b07ba839f000
7
- data.tar.gz: 40930a3359b7583e6dfd49776866a3c87cf80f6230c0ccdb13745fbc7e63fe1a4bb8ac300ea4129cf32439799784459f1f9f3ddf72a22f1a1e6b7f76a0dcd82a
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: text-ui
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skorobogaty Dmitry