console_table 0.1.4 → 0.1.5
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/console_table.rb +6 -6
- data/test/test_console_table.rb +34 -7
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ad359bbbe8957d51f799ac7761138ce6298c242
|
4
|
+
data.tar.gz: 33e4d6d67e2405a9915d7368b32d572e27f4575a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca996310196d283a334171530e68b93922bff9bf2e4ac5bf2a00870a469f597ebcd8cd3cb9273e21c32add989513808df3e913270a28e3f4398eb00e1ca77414
|
7
|
+
data.tar.gz: 69d0c16af724898caa200b825b3ea4c0c2fd92fe1809b969649120002f59a662bac0c16c1857c777ebe84a34ca379902da00eda03335eda328976c41dcfae7ae
|
data/lib/console_table.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'terminfo'
|
2
2
|
|
3
3
|
module ConsoleTable
|
4
|
-
VERSION = "0.1.
|
4
|
+
VERSION = "0.1.5"
|
5
5
|
|
6
6
|
def self.define(layout, options={}, &block)
|
7
7
|
table = ConsoleTableClass.new(layout, options)
|
@@ -223,10 +223,10 @@ module ConsoleTable
|
|
223
223
|
require 'pp'
|
224
224
|
normalized = string.to_s
|
225
225
|
|
226
|
-
normalized = normalized.sub(/^(\e\[\d
|
227
|
-
normalized = normalized.sub(/(\s+)(\e\[\d
|
228
|
-
|
229
|
-
normalized
|
226
|
+
normalized = normalized.sub(/^(\e\[\d[^m]*?m)(\s+)/, '\2\1') #Any leading spaces preceeded by a color code should be swapped with the color code itself, so the spaces themselves aren't colored
|
227
|
+
normalized = normalized.sub(/(\s+)(\e\[\d[^m]*?m)$/, '\2\1')
|
228
|
+
normalized = normalized.gsub(/\s+/, " ").strip #Primarily to remove any tabs or newlines
|
229
|
+
normalized
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
@@ -284,7 +284,7 @@ module ConsoleTable
|
|
284
284
|
|
285
285
|
|
286
286
|
def uncolorize(string)
|
287
|
-
string.gsub(/\e\[\d
|
287
|
+
string.gsub(/\e\[\d[^m]*?m/m, "")
|
288
288
|
end
|
289
289
|
|
290
290
|
#TODO: if you're doing center or right-justification, should it trim from the sides or from the left, respectively?
|
data/test/test_console_table.rb
CHANGED
@@ -160,15 +160,44 @@ Bl ah 1234
|
|
160
160
|
==========================
|
161
161
|
END
|
162
162
|
|
163
|
-
require 'pp'
|
164
|
-
puts @mock_out.string
|
165
|
-
|
166
163
|
assert_includes @mock_out.string, "\e[0;34;49mBl ah\e[0m" #ensure the color got reset
|
167
164
|
assert_includes @mock_out.string, "\e[0;31;49m1234 \e[0m" #ensure the color got reset
|
168
165
|
|
169
166
|
assert_output_equal expected, @mock_out.string
|
170
167
|
end
|
171
168
|
|
169
|
+
def test_spacing_after_colors_is_preserved
|
170
|
+
table_config = [
|
171
|
+
{:key=>:col1, :size=>60, :title=>"Column 1"},
|
172
|
+
]
|
173
|
+
|
174
|
+
ConsoleTable.define(table_config, :width=> 60, :output=>@mock_out) do |table|
|
175
|
+
table << [
|
176
|
+
"hello - \e[0;34;49mTest\e[0m - this is a test"
|
177
|
+
]
|
178
|
+
|
179
|
+
table << [
|
180
|
+
"\e[0;34;49mTest\e[0m - this is a test"
|
181
|
+
]
|
182
|
+
|
183
|
+
table << [
|
184
|
+
"blah and stuff - \e[0;34;49mTest\e[0m"
|
185
|
+
]
|
186
|
+
end
|
187
|
+
|
188
|
+
expected=<<-END
|
189
|
+
============================================================
|
190
|
+
Column 1
|
191
|
+
------------------------------------------------------------
|
192
|
+
hello - Test - this is a test
|
193
|
+
Test - this is a test
|
194
|
+
blah and stuff - Test
|
195
|
+
============================================================
|
196
|
+
END
|
197
|
+
|
198
|
+
assert_output_equal expected, @mock_out.string
|
199
|
+
end
|
200
|
+
|
172
201
|
def test_can_ellipsize_at_column_level
|
173
202
|
table_config = [
|
174
203
|
{:key=>:col1, :size=>20, :title=>"Column 1", :ellipsize=>true},
|
@@ -232,8 +261,6 @@ Short
|
|
232
261
|
====================
|
233
262
|
END
|
234
263
|
|
235
|
-
puts @mock_out.string
|
236
|
-
|
237
264
|
assert_output_equal expected, @mock_out.string
|
238
265
|
end
|
239
266
|
|
@@ -256,13 +283,13 @@ Short
|
|
256
283
|
==============================================================
|
257
284
|
Column 1 Column 2 Column 3
|
258
285
|
--------------------------------------------------------------
|
259
|
-
Right
|
286
|
+
Right Center Left
|
260
287
|
==============================================================
|
261
288
|
END
|
262
289
|
|
263
290
|
assert_includes @mock_out.string, " \e[0;34;49mRight\e[0m" #space is on outside of coor
|
264
291
|
assert_includes @mock_out.string, " \e[0;35;49mLeft\e[0m " #space is on outside of color
|
265
|
-
|
292
|
+
assert_includes @mock_out.string, " \e[0;31;49mCenter\e[0m" #this assert fails due to what I'm pretty sure is a bug in gsub(), but it's not the end of the world so I'm not doing a workaround
|
266
293
|
|
267
294
|
assert_output_equal expected, @mock_out.string
|
268
295
|
end
|