console_table 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d31ea023e41a11349f456744423ec4ebf540102c
4
- data.tar.gz: cba32a643b607437ece928dbed1dd818ea64d0ac
3
+ metadata.gz: 0fed2d92f9592e9ed2fe3f687550473f783c6982
4
+ data.tar.gz: c3d516293086bcc3734d8e21710c879225bbb5ae
5
5
  SHA512:
6
- metadata.gz: b607321df3045b48f45ca3e77570def4fa316d221d853a594c62b6bd689d9b93b493bc7a50ca420214d63f4cca97f96d7d674ce4e08b4463c0749f102daee9b8
7
- data.tar.gz: 9382b05787a3453d447d00dc8e83a0a6bd5ec09d55553d69ae31af8409058640b61086ac90a9ffc75575ff9abac35ed254cd33db27422ae3cb2cfc5ab7dd11ac
6
+ metadata.gz: 3561143d5ced3c2bbb9464519c84f86f9aad36f8b17658202d4eaf4e49818a5583db8430af311dbb51a4fb11dcab31fc571b25100ea91c0f81997c6505cf4856
7
+ data.tar.gz: 57be1e70ba595a59f7b4eb1b987f3aade12b7643462d09ae631359ca7d8a8a605a8b8688c450bb9c8afac0320ea445f2f5a0e32952223e37b136c3c7f0edf97c
@@ -1,11 +1,10 @@
1
1
  # coding: utf-8
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- # require 'console_table'
5
4
 
6
5
  Gem::Specification.new do |spec|
7
6
  spec.name = "console_table"
8
- spec.version = "0.2.0"
7
+ spec.version = "0.2.1"
9
8
  spec.authors = ["Rod Hilton"]
10
9
  spec.email = ["consoletable@rodhilton.com"]
11
10
  spec.summary = %q{Simplifies printing tables of information to commandline consoles}
@@ -4,18 +4,7 @@
4
4
  #
5
5
  # Author:: Rod Hilton
6
6
  # License:: MIT
7
- #
8
- #--
9
- # TODO: it's a little weird how, if a footer is too long, it simply doesn't print at all.
10
- # This seems like not what someone would want to have happen.
11
- # Could we take footer lines and split them every X characters where X is the working
12
- # width, then use those? Long lines effectively wrap, but not on word boundaries
13
- # TODO: if you're doing center or right-justification, should it trim from the sides or
14
- # from the left, respectively?
15
- #++
16
-
17
7
  module ConsoleTable
18
- VERSION = "0.1.8"
19
8
 
20
9
  # Define a console table. Requires a table layout which specifies column information
21
10
  # like sizes, titles, and key names.
@@ -103,7 +92,7 @@ module ConsoleTable
103
92
  print_line("=", "*", true)
104
93
  end if @outline
105
94
 
106
- if not @title.nil? and @title.length <= @working_width
95
+ unless @title.nil?
107
96
  @out.print " "*@left_margin
108
97
  @out.print "|" if @borders
109
98
  @out.print format(@working_width, @title, false, :center)
@@ -119,13 +108,11 @@ module ConsoleTable
119
108
  end
120
109
 
121
110
  footer_lines.each do |line|
122
- if uncolorize(line).length <= @working_width
123
111
  @out.print " " * @left_margin
124
112
  @out.print "|" if @borders
125
113
  @out.print format(@working_width, line, false, :right)
126
114
  @out.print "|" if @borders
127
115
  @out.print "\n"
128
- end
129
116
  end
130
117
 
131
118
  if should_print_footer
@@ -183,7 +170,7 @@ module ConsoleTable
183
170
  end
184
171
 
185
172
  def should_print_footer
186
- footer_lines.length > 0 && footer_lines.any? { |l| uncolorize(l).length <= @working_width }
173
+ footer_lines.length > 0
187
174
  end
188
175
 
189
176
  def footer_lines
@@ -4,9 +4,12 @@ SimpleCov.start
4
4
 
5
5
  require 'minitest/autorun'
6
6
 
7
+ #--
8
+ # TODO: if you're doing center or right-justification, should it trim from the sides or
9
+ # from the left, respectively?
10
+ #++
7
11
  class ConsoleTableTest < Minitest::Test
8
12
 
9
-
10
13
  def setup
11
14
  require 'console_table'
12
15
  require 'colorize'
@@ -658,6 +661,28 @@ This is way too l...
658
661
  assert_output_equal expected, @mock_out.string
659
662
  end
660
663
 
664
+ def test_can_truncate_titles
665
+ table_config = [
666
+ {:key => :col1, :size => 20, :title => "This column title is too long"}
667
+ ]
668
+
669
+ ConsoleTable.define(table_config, :width => 100, :title=>"Hello world this is too long", :output => @mock_out) do |table|
670
+ table << ["This is short"]
671
+
672
+ end
673
+
674
+ expected=<<-END
675
+ ====================
676
+ Hello world this is
677
+ This column title is
678
+ --------------------
679
+ This is short
680
+ ====================
681
+ END
682
+
683
+ assert_output_equal expected, @mock_out.string
684
+ end
685
+
661
686
  def test_can_justify_columns_and_override_in_rows
662
687
  table_config = [
663
688
  {:key => :col1, :size => 20, :title => "Column 1"},
@@ -774,6 +799,32 @@ This is just a string, it should ignore c
774
799
  assert_output_equal expected, @mock_out.string
775
800
  end
776
801
 
802
+ #TODO: Really don't love how this works.. truncate from right? Auto word-wrap? something..
803
+ def test_printing_a_single_string_truncates_footer
804
+ table_config = [
805
+ {:key => :col1, :size => 20, :title => "Column 1"},
806
+ ]
807
+
808
+ ConsoleTable.define(table_config, :width => 100, :output => @mock_out) do |table|
809
+ table << "Blah"
810
+
811
+ table.footer << "This is a really long footer that should automatically be truncated"
812
+ table.footer << "This is a really long footer \n that should automatically be truncated"
813
+ end
814
+
815
+ expected=<<-END
816
+ ====================
817
+ Blah
818
+ --------------------
819
+ This is a really lon
820
+ This is a really lon
821
+ that should automati
822
+ ====================
823
+ END
824
+
825
+ assert_output_equal expected, @mock_out.string
826
+ end
827
+
777
828
  def test_printing_a_single_after_data_makes_headings_show_up
778
829
  table_config = [
779
830
  {:key => :col1, :size => 20, :title => "Column 1"},
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: console_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rod Hilton