terminal-table 1.4.4 → 1.4.5
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +3 -2
- data/lib/terminal-table/cell.rb +12 -6
- data/lib/terminal-table/table.rb +7 -4
- data/lib/terminal-table/version.rb +1 -1
- data/spec/cell_spec.rb +4 -4
- data/spec/table_spec.rb +9 -9
- data/terminal-table.gemspec +5 -5
- metadata +53 -54
data/History.rdoc
CHANGED
data/lib/terminal-table/cell.rb
CHANGED
@@ -58,7 +58,8 @@ module Terminal
|
|
58
58
|
def render(line = 0)
|
59
59
|
left = " " * @table.style.padding_left
|
60
60
|
right = " " * @table.style.padding_right
|
61
|
-
|
61
|
+
render_width = lines[line].to_s.size - escape(lines[line]).size + width
|
62
|
+
"#{left}#{lines[line]}#{right}".align(alignment, render_width + @table.cell_padding)
|
62
63
|
end
|
63
64
|
alias :to_s :render
|
64
65
|
|
@@ -67,10 +68,7 @@ module Terminal
|
|
67
68
|
# removes all ANSI escape sequences (e.g. color)
|
68
69
|
|
69
70
|
def value_for_column_width_recalc
|
70
|
-
|
71
|
-
str = str.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
|
72
|
-
str = str.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '')
|
73
|
-
str.gsub(/[\x03|\x1a]/, '')
|
71
|
+
lines.map{ |s| escape(s) }.max_by{ |s| s.size }
|
74
72
|
end
|
75
73
|
|
76
74
|
##
|
@@ -83,6 +81,14 @@ module Terminal
|
|
83
81
|
end
|
84
82
|
inner_width + padding
|
85
83
|
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# removes all ANSI escape sequences (e.g. color)
|
87
|
+
def escape(line)
|
88
|
+
line.to_s.gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
|
89
|
+
gsub(/\x1b(\[|\(|\))[;?0-9]*[0-9A-Za-z]/, '').
|
90
|
+
gsub(/[\x03|\x1a]/, '')
|
91
|
+
end
|
86
92
|
end
|
87
93
|
end
|
88
|
-
end
|
94
|
+
end
|
data/lib/terminal-table/table.rb
CHANGED
@@ -11,9 +11,9 @@ module Terminal
|
|
11
11
|
def initialize options = {}, &block
|
12
12
|
@column_widths = []
|
13
13
|
self.style = options.fetch :style, {}
|
14
|
-
self.title = options.fetch :title, nil
|
15
14
|
self.headings = options.fetch :headings, []
|
16
15
|
self.rows = options.fetch :rows, []
|
16
|
+
self.title = options.fetch :title, nil
|
17
17
|
yield_or_eval(&block) if block
|
18
18
|
end
|
19
19
|
|
@@ -108,8 +108,7 @@ module Terminal
|
|
108
108
|
separator = Separator.new(self)
|
109
109
|
buffer = [separator]
|
110
110
|
unless @title.nil?
|
111
|
-
|
112
|
-
buffer << Row.new(self, [opts])
|
111
|
+
buffer << Row.new(self, [title_cell_options])
|
113
112
|
buffer << separator
|
114
113
|
end
|
115
114
|
unless @headings.cells.empty?
|
@@ -144,7 +143,7 @@ module Terminal
|
|
144
143
|
|
145
144
|
def title=(title)
|
146
145
|
@title = title
|
147
|
-
recalc_column_widths Row.new(self, [
|
146
|
+
recalc_column_widths Row.new(self, [title_cell_options])
|
148
147
|
end
|
149
148
|
|
150
149
|
##
|
@@ -213,5 +212,9 @@ module Terminal
|
|
213
212
|
self.instance_eval(&block)
|
214
213
|
end
|
215
214
|
end
|
215
|
+
|
216
|
+
def title_cell_options
|
217
|
+
{:value => @title, :alignment => :center, :colspan => number_of_columns}
|
218
|
+
end
|
216
219
|
end
|
217
220
|
end
|
data/spec/cell_spec.rb
CHANGED
@@ -29,11 +29,11 @@ describe Terminal::Table do
|
|
29
29
|
end
|
30
30
|
|
31
31
|
it "should allow multiline content" do
|
32
|
-
cell = Cell.new :value => "
|
33
|
-
cell.value.should == "
|
34
|
-
cell.lines.should == ['
|
32
|
+
cell = Cell.new :value => "barrissimo\n"+"foo".yellow, :table => Terminal::Table.new, :index => 0
|
33
|
+
cell.value.should == "barrissimo\n"+"foo".yellow
|
34
|
+
cell.lines.should == ['barrissimo','foo'.yellow]
|
35
35
|
cell.value_for_column_width_recalc.should == 'barrissimo'
|
36
|
-
cell.render(
|
36
|
+
cell.render(0).should == " barrissimo "
|
37
37
|
end
|
38
38
|
|
39
39
|
it "should allow colorized content" do
|
data/spec/table_spec.rb
CHANGED
@@ -161,15 +161,15 @@ module Terminal
|
|
161
161
|
@table << ['b', 2]
|
162
162
|
@table << ['c', 3]
|
163
163
|
@table.render.should == <<-EOF.deindent
|
164
|
-
|
165
|
-
|
|
166
|
-
|
167
|
-
| Char
|
168
|
-
|
169
|
-
| a
|
170
|
-
| b
|
171
|
-
| c
|
172
|
-
|
164
|
+
+------+-----+
|
165
|
+
| Title |
|
166
|
+
+------+-----+
|
167
|
+
| Char | Num |
|
168
|
+
+------+-----+
|
169
|
+
| a | 1 |
|
170
|
+
| b | 2 |
|
171
|
+
| c | 3 |
|
172
|
+
+------+-----+
|
173
173
|
EOF
|
174
174
|
end
|
175
175
|
|
data/terminal-table.gemspec
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{terminal-table}
|
5
|
-
s.version = "1.4.
|
5
|
+
s.version = "1.4.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["TJ Holowaychuk", "Scott J. Goldman"]
|
9
|
-
s.date = %q{
|
9
|
+
s.date = %q{2012-3-15}
|
10
10
|
s.description = %q{Simple, feature rich ascii table generation library}
|
11
11
|
s.email = %q{tj@vision-media.ca}
|
12
|
-
s.extra_rdoc_files = ["README.rdoc", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/
|
13
|
-
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "Todo.rdoc", "examples/examples.rb", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/table_helper.rb", "lib/terminal-table/version.rb", "lib/terminal-table/
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/version.rb", "lib/terminal-table/row.rb", "lib/terminal-table/separator.rb", "lib/terminal-table/style.rb", "lib/terminal-table/table_helper.rb", "lib/terminal-table/version.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake"]
|
13
|
+
s.files = ["History.rdoc", "Manifest", "README.rdoc", "Rakefile", "Todo.rdoc", "examples/examples.rb", "lib/terminal-table.rb", "lib/terminal-table/cell.rb", "lib/terminal-table/core_ext.rb", "lib/terminal-table/import.rb", "lib/terminal-table/table.rb", "lib/terminal-table/table_helper.rb", "lib/terminal-table/version.rb", "lib/terminal-table/row.rb", "lib/terminal-table/separator.rb", "lib/terminal-table/style.rb", "spec/cell_spec.rb", "spec/core_ext_spec.rb", "spec/import_spec.rb", "spec/spec.opts", "spec/spec_helper.rb", "spec/table_spec.rb", "tasks/docs.rake", "tasks/gemspec.rake", "tasks/spec.rake", "terminal-table.gemspec"]
|
14
14
|
s.homepage = %q{http://github.com/visionmedia/terminal-table}
|
15
15
|
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Terminal-table", "--main", "README.rdoc"]
|
16
16
|
s.require_paths = ["lib"]
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.rubygems_version = %q{1.3.5}
|
19
19
|
s.summary = %q{Simple, feature rich ascii table generation library}
|
20
20
|
|
21
|
-
if s.respond_to? :specification_version then
|
21
|
+
if s.respond_to? :specification_version= then
|
22
22
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
23
|
s.specification_version = 3
|
24
24
|
|
metadata
CHANGED
@@ -1,37 +1,35 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
2
4
|
name: terminal-table
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
5
|
-
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 1.4.5
|
7
|
+
date: 2012-03-15 00:00:00 +00:00
|
8
|
+
summary: Simple, feature rich ascii table generation library
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: tj@vision-media.ca
|
12
|
+
homepage: http://github.com/visionmedia/terminal-table
|
13
|
+
rubyforge_project: terminal-table
|
14
|
+
description: Simple, feature rich ascii table generation library
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
6
25
|
platform: ruby
|
7
|
-
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
8
30
|
- TJ Holowaychuk
|
9
31
|
- Scott J. Goldman
|
10
|
-
|
11
|
-
bindir: bin
|
12
|
-
cert_chain: []
|
13
|
-
date: 2011-11-07 00:00:00.000000000Z
|
14
|
-
dependencies: []
|
15
|
-
description: Simple, feature rich ascii table generation library
|
16
|
-
email: tj@vision-media.ca
|
17
|
-
executables: []
|
18
|
-
extensions: []
|
19
|
-
extra_rdoc_files:
|
20
|
-
- README.rdoc
|
21
|
-
- lib/terminal-table.rb
|
22
|
-
- lib/terminal-table/cell.rb
|
23
|
-
- lib/terminal-table/core_ext.rb
|
24
|
-
- lib/terminal-table/import.rb
|
25
|
-
- lib/terminal-table/table.rb
|
26
|
-
- lib/terminal-table/table_helper.rb
|
27
|
-
- lib/terminal-table/version.rb
|
28
|
-
- lib/terminal-table/row.rb
|
29
|
-
- lib/terminal-table/separator.rb
|
30
|
-
- lib/terminal-table/style.rb
|
31
|
-
- tasks/docs.rake
|
32
|
-
- tasks/gemspec.rake
|
33
|
-
- tasks/spec.rake
|
34
|
-
files:
|
32
|
+
files:
|
35
33
|
- History.rdoc
|
36
34
|
- Manifest
|
37
35
|
- README.rdoc
|
@@ -58,34 +56,35 @@ files:
|
|
58
56
|
- tasks/gemspec.rake
|
59
57
|
- tasks/spec.rake
|
60
58
|
- terminal-table.gemspec
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
rdoc_options:
|
59
|
+
test_files: []
|
60
|
+
|
61
|
+
rdoc_options:
|
65
62
|
- --line-numbers
|
66
63
|
- --inline-source
|
67
64
|
- --title
|
68
65
|
- Terminal-table
|
69
66
|
- --main
|
70
67
|
- README.rdoc
|
71
|
-
|
72
|
-
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
68
|
+
extra_rdoc_files:
|
69
|
+
- README.rdoc
|
70
|
+
- lib/terminal-table.rb
|
71
|
+
- lib/terminal-table/cell.rb
|
72
|
+
- lib/terminal-table/core_ext.rb
|
73
|
+
- lib/terminal-table/import.rb
|
74
|
+
- lib/terminal-table/table.rb
|
75
|
+
- lib/terminal-table/version.rb
|
76
|
+
- lib/terminal-table/row.rb
|
77
|
+
- lib/terminal-table/separator.rb
|
78
|
+
- lib/terminal-table/style.rb
|
79
|
+
- lib/terminal-table/table_helper.rb
|
80
|
+
- tasks/docs.rake
|
81
|
+
- tasks/gemspec.rake
|
82
|
+
- tasks/spec.rake
|
83
|
+
executables: []
|
84
|
+
|
85
|
+
extensions: []
|
86
|
+
|
85
87
|
requirements: []
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
specification_version: 3
|
90
|
-
summary: Simple, feature rich ascii table generation library
|
91
|
-
test_files: []
|
88
|
+
|
89
|
+
dependencies: []
|
90
|
+
|