text-ui 0.2.2 → 0.2.4

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: c93ee321c5505fc92c51f866aa5c31c799be70385e44a0c77c2762453aa43580
4
+ data.tar.gz: d07fe013128dc1896ce3ea3392d1672c5161b7cea9f5e52692e24918f91da779
5
5
  SHA512:
6
- metadata.gz: 84b46fe510be54628e3b8fa1ab307b7d7768c52e7fb12ddfd9491fea60a45cb5d61dcf0f8bd62a0b65d90b7a5f14e7656146735a7241a1040e27b07ba839f000
7
- data.tar.gz: 40930a3359b7583e6dfd49776866a3c87cf80f6230c0ccdb13745fbc7e63fe1a4bb8ac300ea4129cf32439799784459f1f9f3ddf72a22f1a1e6b7f76a0dcd82a
6
+ metadata.gz: 442daa6554d8d4e3cb6097997d53f64b3e1134195f90786465f1849f9962df93304128f252f2cb7832fc49ecd615bed4bde7c0cd740be0a22f08ad415724652d
7
+ data.tar.gz: 18400f508ce127cee81a0504a521ed689e602b004d69886dab3c8a3bec0783b13186b960c44ef854f92318b296ed084adcf2118e9cd4eb94e9ba8ae243b99538
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, fill }
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, fill
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.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Skorobogaty Dmitry