tty-table 0.11.0 → 0.12.0
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/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/README.md +104 -98
- data/lib/tty-table.rb +1 -1
- data/lib/tty/table.rb +70 -34
- data/lib/tty/table/alignment_set.rb +1 -3
- data/lib/tty/table/border.rb +50 -57
- data/lib/tty/table/border/ascii.rb +16 -16
- data/lib/tty/table/border/null.rb +19 -22
- data/lib/tty/table/border/row_line.rb +3 -2
- data/lib/tty/table/border/unicode.rb +16 -16
- data/lib/tty/table/border_dsl.rb +24 -22
- data/lib/tty/table/border_options.rb +32 -27
- data/lib/tty/table/column_constraint.rb +12 -9
- data/lib/tty/table/columns.rb +6 -6
- data/lib/tty/table/field.rb +46 -28
- data/lib/tty/table/header.rb +5 -5
- data/lib/tty/table/indentation.rb +7 -4
- data/lib/tty/table/operation/alignment.rb +1 -1
- data/lib/tty/table/operation/escape.rb +1 -2
- data/lib/tty/table/operation/padding.rb +1 -1
- data/lib/tty/table/operation/truncation.rb +1 -1
- data/lib/tty/table/operation/wrapped.rb +1 -1
- data/lib/tty/table/options.rb +1 -1
- data/lib/tty/table/orientation.rb +4 -4
- data/lib/tty/table/renderer.rb +8 -8
- data/lib/tty/table/renderer/ascii.rb +2 -2
- data/lib/tty/table/renderer/basic.rb +37 -40
- data/lib/tty/table/renderer/unicode.rb +1 -1
- data/lib/tty/table/row.rb +7 -7
- data/lib/tty/table/validatable.rb +23 -7
- data/lib/tty/table/version.rb +1 -1
- metadata +23 -272
- data/Rakefile +0 -10
- data/examples/alignment.rb +0 -10
- data/examples/basic.rb +0 -6
- data/examples/orientation.rb +0 -13
- data/examples/padding.rb +0 -15
- data/examples/resize.rb +0 -15
- data/spec/spec_helper.rb +0 -50
- data/spec/unit/access_spec.rb +0 -84
- data/spec/unit/add_row_spec.rb +0 -26
- data/spec/unit/alignment_set/each_spec.rb +0 -15
- data/spec/unit/alignment_set/new_spec.rb +0 -25
- data/spec/unit/alignment_set/to_ary_spec.rb +0 -12
- data/spec/unit/alignment_spec.rb +0 -69
- data/spec/unit/border/ascii/rendering_spec.rb +0 -88
- data/spec/unit/border/new_spec.rb +0 -25
- data/spec/unit/border/null/rendering_spec.rb +0 -128
- data/spec/unit/border/options/from_spec.rb +0 -36
- data/spec/unit/border/options/new_spec.rb +0 -12
- data/spec/unit/border/unicode/rendering_spec.rb +0 -61
- data/spec/unit/border_options/new_spec.rb +0 -18
- data/spec/unit/border_options/update_spec.rb +0 -16
- data/spec/unit/column_constraint/enforce_spec.rb +0 -68
- data/spec/unit/column_constraint/widths_spec.rb +0 -33
- data/spec/unit/columns/extract_widths_spec.rb +0 -41
- data/spec/unit/columns/total_width_spec.rb +0 -11
- data/spec/unit/columns/widths_from_spec.rb +0 -49
- data/spec/unit/data_spec.rb +0 -10
- data/spec/unit/each_spec.rb +0 -24
- data/spec/unit/each_with_index_spec.rb +0 -49
- data/spec/unit/empty_spec.rb +0 -21
- data/spec/unit/eql_spec.rb +0 -32
- data/spec/unit/field/equality_spec.rb +0 -49
- data/spec/unit/field/length_spec.rb +0 -33
- data/spec/unit/field/lines_spec.rb +0 -19
- data/spec/unit/field/new_spec.rb +0 -27
- data/spec/unit/field/width_spec.rb +0 -21
- data/spec/unit/filter_spec.rb +0 -20
- data/spec/unit/header/call_spec.rb +0 -28
- data/spec/unit/header/color_spec.rb +0 -17
- data/spec/unit/header/equality_spec.rb +0 -49
- data/spec/unit/header/height_spec.rb +0 -25
- data/spec/unit/header/new_spec.rb +0 -13
- data/spec/unit/header/set_spec.rb +0 -18
- data/spec/unit/header/to_ary_spec.rb +0 -12
- data/spec/unit/header_spec.rb +0 -11
- data/spec/unit/indentation/indent_spec.rb +0 -15
- data/spec/unit/new_spec.rb +0 -71
- data/spec/unit/operation/alignment/call_spec.rb +0 -37
- data/spec/unit/operation/escape/call_spec.rb +0 -13
- data/spec/unit/operation/filter/call_spec.rb +0 -14
- data/spec/unit/operation/truncation/call_spec.rb +0 -28
- data/spec/unit/operation/wrapped/call_spec.rb +0 -38
- data/spec/unit/operations/new_spec.rb +0 -28
- data/spec/unit/options/access_spec.rb +0 -12
- data/spec/unit/options_spec.rb +0 -23
- data/spec/unit/orientation_spec.rb +0 -143
- data/spec/unit/padding_spec.rb +0 -115
- data/spec/unit/properties_spec.rb +0 -23
- data/spec/unit/render_repeat_spec.rb +0 -39
- data/spec/unit/render_spec.rb +0 -61
- data/spec/unit/render_with_spec.rb +0 -104
- data/spec/unit/renderer/ascii/coloring_spec.rb +0 -83
- data/spec/unit/renderer/ascii/indentation_spec.rb +0 -39
- data/spec/unit/renderer/ascii/multiline_spec.rb +0 -99
- data/spec/unit/renderer/ascii/padding_spec.rb +0 -115
- data/spec/unit/renderer/ascii/render_spec.rb +0 -66
- data/spec/unit/renderer/ascii/resizing_spec.rb +0 -112
- data/spec/unit/renderer/ascii/separator_spec.rb +0 -38
- data/spec/unit/renderer/basic/alignment_spec.rb +0 -86
- data/spec/unit/renderer/basic/coloring_spec.rb +0 -59
- data/spec/unit/renderer/basic/extract_column_widths_spec.rb +0 -26
- data/spec/unit/renderer/basic/filter_spec.rb +0 -51
- data/spec/unit/renderer/basic/indentation_spec.rb +0 -46
- data/spec/unit/renderer/basic/multiline_spec.rb +0 -72
- data/spec/unit/renderer/basic/new_spec.rb +0 -24
- data/spec/unit/renderer/basic/options_spec.rb +0 -50
- data/spec/unit/renderer/basic/padding_spec.rb +0 -74
- data/spec/unit/renderer/basic/render_spec.rb +0 -55
- data/spec/unit/renderer/basic/resizing_spec.rb +0 -94
- data/spec/unit/renderer/basic/separator_spec.rb +0 -41
- data/spec/unit/renderer/basic/single_row_separator_spec.rb +0 -80
- data/spec/unit/renderer/basic/truncation_spec.rb +0 -33
- data/spec/unit/renderer/basic/wrapping_spec.rb +0 -38
- data/spec/unit/renderer/border_spec.rb +0 -102
- data/spec/unit/renderer/render_spec.rb +0 -34
- data/spec/unit/renderer/select_spec.rb +0 -20
- data/spec/unit/renderer/unicode/coloring_spec.rb +0 -68
- data/spec/unit/renderer/unicode/indentation_spec.rb +0 -39
- data/spec/unit/renderer/unicode/padding_spec.rb +0 -59
- data/spec/unit/renderer/unicode/render_spec.rb +0 -66
- data/spec/unit/renderer/unicode/separator_spec.rb +0 -36
- data/spec/unit/renderer_spec.rb +0 -17
- data/spec/unit/rotate_spec.rb +0 -84
- data/spec/unit/row/access_spec.rb +0 -23
- data/spec/unit/row/call_spec.rb +0 -43
- data/spec/unit/row/data_spec.rb +0 -24
- data/spec/unit/row/each_spec.rb +0 -29
- data/spec/unit/row/equality_spec.rb +0 -71
- data/spec/unit/row/height_spec.rb +0 -25
- data/spec/unit/row/new_spec.rb +0 -39
- data/spec/unit/row/to_ary_spec.rb +0 -12
- data/spec/unit/to_s_spec.rb +0 -56
- data/spec/unit/transformation/extract_tuples_spec.rb +0 -33
- data/spec/unit/utf_spec.rb +0 -31
- data/spec/unit/validatable/validate_options_spec.rb +0 -31
- data/spec/unit/validatable_spec.rb +0 -30
- data/tasks/console.rake +0 -11
- data/tasks/coverage.rake +0 -11
- data/tasks/spec.rake +0 -29
- data/tty-table.gemspec +0 -41
data/lib/tty-table.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "tty/table"
|
data/lib/tty/table.rb
CHANGED
@@ -1,24 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative
|
11
|
-
require_relative
|
12
|
-
require_relative
|
13
|
-
require_relative 'table/validatable'
|
14
|
-
require_relative 'table/version'
|
3
|
+
require "forwardable"
|
4
|
+
|
5
|
+
require_relative "table/columns"
|
6
|
+
require_relative "table/header"
|
7
|
+
require_relative "table/orientation"
|
8
|
+
require_relative "table/row"
|
9
|
+
require_relative "table/renderer"
|
10
|
+
require_relative "table/transformation"
|
11
|
+
require_relative "table/validatable"
|
12
|
+
require_relative "table/version"
|
15
13
|
|
16
14
|
module TTY
|
17
15
|
# A core class intended for storing data in a structured, tabular form.
|
18
16
|
# Once the data is stored in a TTY::Table various operations can be performed
|
19
17
|
# before the information is dumped into a stdout.
|
20
18
|
class Table
|
21
|
-
include Comparable, Enumerable, Validatable
|
19
|
+
include Comparable, Enumerable, Validatable
|
22
20
|
extend Forwardable
|
23
21
|
|
24
22
|
# The table header
|
@@ -64,7 +62,7 @@ module TTY
|
|
64
62
|
# Create a new Table where each argument is a row
|
65
63
|
#
|
66
64
|
# @example
|
67
|
-
# table = TTY::Table[[
|
65
|
+
# table = TTY::Table[["a1", "a2"], ["b1", "b2"]]
|
68
66
|
#
|
69
67
|
# @api public
|
70
68
|
def self.[](*rows)
|
@@ -74,18 +72,18 @@ module TTY
|
|
74
72
|
# Instantiate a new Table
|
75
73
|
#
|
76
74
|
# @example of no header
|
77
|
-
# table = Table.new [[
|
75
|
+
# table = Table.new [["a1", "a2"], ["b1", "b2"]]
|
78
76
|
#
|
79
77
|
# @example of direct parameters
|
80
|
-
# rows = [[
|
81
|
-
# table = Table.new [
|
78
|
+
# rows = [["a1", "a2"], ["b1", "b2"]]
|
79
|
+
# table = Table.new ["Header 1", "Header 2"], rows
|
82
80
|
#
|
83
81
|
# @example of parameters passed as options
|
84
|
-
# rows = [[
|
85
|
-
# table = Table.new header: [
|
82
|
+
# rows = [["a1", "a2"], ["b1", "b2"]]
|
83
|
+
# table = Table.new header: ["Header 1", "Header 2"], rows: rows
|
86
84
|
#
|
87
85
|
# @example of parameters passed as hash
|
88
|
-
# Table.new [{
|
86
|
+
# Table.new [{"Header1" => ["a1","a2"], "Header2" => ["b1", "b2"] }]}
|
89
87
|
#
|
90
88
|
# @param [Array[Symbol], Hash] args
|
91
89
|
#
|
@@ -115,7 +113,6 @@ module TTY
|
|
115
113
|
# @api private
|
116
114
|
def initialize(options = {}, &block)
|
117
115
|
validate_options! options
|
118
|
-
@converter = Necromancer.new
|
119
116
|
@header = (value = options[:header]) ? Header.new(value) : nil
|
120
117
|
@rows = coerce(options.fetch(:rows) { Row.new([]) })
|
121
118
|
@rotated = false
|
@@ -204,10 +201,10 @@ module TTY
|
|
204
201
|
# @param [Integer] column_index
|
205
202
|
#
|
206
203
|
# @example
|
207
|
-
# table = TTY::Table.new [[
|
208
|
-
# table[0] # => [
|
209
|
-
# table[0,0] # =>
|
210
|
-
# table[-1] # => [
|
204
|
+
# table = TTY::Table.new [["a1","a2"], ["b1","b2"]]
|
205
|
+
# table[0] # => ["a1","a2"]
|
206
|
+
# table[0,0] # => "a1"
|
207
|
+
# table[-1] # => ["b1","b2"]
|
211
208
|
#
|
212
209
|
# @api public
|
213
210
|
def [](row_index, column_index = false)
|
@@ -215,12 +212,12 @@ module TTY
|
|
215
212
|
if row_index >= 0 && column_index >= 0
|
216
213
|
rows.fetch(row_index) { return nil }[column_index]
|
217
214
|
else
|
218
|
-
|
215
|
+
raise TTY::Table::TupleMissing.new(row_index, column_index)
|
219
216
|
end
|
220
217
|
end
|
221
|
-
|
222
|
-
|
223
|
-
|
218
|
+
alias at []
|
219
|
+
alias element []
|
220
|
+
alias component []
|
224
221
|
|
225
222
|
# Set table value at row(i) and column(j)
|
226
223
|
#
|
@@ -234,7 +231,7 @@ module TTY
|
|
234
231
|
# When a block is given, the elements of that Array are iterated over.
|
235
232
|
#
|
236
233
|
# @example
|
237
|
-
# rows = [[
|
234
|
+
# rows = [["a1", "a2"], ["b1", "b2"]]
|
238
235
|
# table = TTY::Table.new rows: rows
|
239
236
|
# table.row(1) { |row| ... }
|
240
237
|
#
|
@@ -261,7 +258,7 @@ module TTY
|
|
261
258
|
#
|
262
259
|
# @example
|
263
260
|
# header = [:h1, :h2]
|
264
|
-
# rows = [ [
|
261
|
+
# rows = [ ["a1", "a2"], ["b1", "b2"] ]
|
265
262
|
# table = TTY::Table.new :rows => rows, :header => header
|
266
263
|
# table.column(1)
|
267
264
|
# table.column(1) { |element| ... }
|
@@ -298,8 +295,7 @@ module TTY
|
|
298
295
|
if row == Border::SEPARATOR
|
299
296
|
separators << columns_size - (header ? 0 : 2)
|
300
297
|
else
|
301
|
-
|
302
|
-
assert_row_sizes rows_copy << row
|
298
|
+
assert_row_size(row, rows)
|
303
299
|
rows << to_row(row)
|
304
300
|
end
|
305
301
|
self
|
@@ -480,7 +476,7 @@ module TTY
|
|
480
476
|
# @api public
|
481
477
|
def coerce(rows)
|
482
478
|
coerced_rows = []
|
483
|
-
|
479
|
+
Array(rows).each do |row|
|
484
480
|
if row == Border::SEPARATOR
|
485
481
|
separators << coerced_rows.length - (header ? 0 : 1)
|
486
482
|
else
|
@@ -490,6 +486,46 @@ module TTY
|
|
490
486
|
coerced_rows
|
491
487
|
end
|
492
488
|
|
489
|
+
# Compare table for equality of header and rows attributes
|
490
|
+
#
|
491
|
+
# @return [Boolean]
|
492
|
+
#
|
493
|
+
# @api public
|
494
|
+
def eql?(other)
|
495
|
+
instance_of?(other.class) &&
|
496
|
+
header.eql?(other.header) && rows.eql?(other.rows)
|
497
|
+
end
|
498
|
+
|
499
|
+
# Compare table for equivalence of header and rows attributes
|
500
|
+
#
|
501
|
+
# @return [Boolean]
|
502
|
+
#
|
503
|
+
# @api public
|
504
|
+
def ==(other)
|
505
|
+
other.is_a?(self.class) &&
|
506
|
+
header == other.header && rows == other.rows
|
507
|
+
end
|
508
|
+
|
509
|
+
# Inspect this instance attributes
|
510
|
+
#
|
511
|
+
# @return [String]
|
512
|
+
#
|
513
|
+
# @api public
|
514
|
+
def inspect
|
515
|
+
"#<#{self.class.name} header=#{header.inspect} rows=#{rows.inspect} " \
|
516
|
+
"original_rows=#{original_rows.inspect} " \
|
517
|
+
"original_columns=#{original_columns.inspect}>"
|
518
|
+
end
|
519
|
+
|
520
|
+
# Hash for this instance and its attributes
|
521
|
+
#
|
522
|
+
# @return [Numeric]
|
523
|
+
#
|
524
|
+
# @api public
|
525
|
+
def hash
|
526
|
+
[self.class, header, rows].hash
|
527
|
+
end
|
528
|
+
|
493
529
|
private
|
494
530
|
|
495
531
|
# Evaluate block
|
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'necromancer'
|
4
|
-
|
5
3
|
module TTY
|
6
4
|
class Table
|
7
5
|
# A class responsible for column alignments
|
@@ -19,7 +17,7 @@ module TTY
|
|
19
17
|
#
|
20
18
|
# @api private
|
21
19
|
def initialize(alignments)
|
22
|
-
@alignments =
|
20
|
+
@alignments = Array(alignments).map(&:to_sym)
|
23
21
|
end
|
24
22
|
|
25
23
|
# Iterate over each element in the alignment set
|
data/lib/tty/table/border.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require 'strings'
|
3
|
+
require "pastel"
|
4
|
+
require "strings"
|
6
5
|
|
7
|
-
require_relative
|
8
|
-
require_relative
|
9
|
-
require_relative
|
10
|
-
require_relative 'error'
|
6
|
+
require_relative "border_dsl"
|
7
|
+
require_relative "border/row_line"
|
8
|
+
require_relative "error"
|
11
9
|
|
12
10
|
module TTY
|
13
11
|
class Table
|
14
12
|
# Abstract base class that is responsible for building the table border.
|
15
13
|
class Border
|
16
|
-
|
14
|
+
EMPTY_CHAR = ""
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
SPACE_CHAR = ' '.freeze
|
16
|
+
SPACE_CHAR = " "
|
21
17
|
|
22
18
|
# Represent a separtor on each row
|
23
19
|
EACH_ROW = :each_row
|
@@ -32,39 +28,40 @@ module TTY
|
|
32
28
|
attr_accessor :characters
|
33
29
|
end
|
34
30
|
|
31
|
+
# Define border characters
|
32
|
+
#
|
33
|
+
# @param [Hash] characters
|
34
|
+
# the border characters
|
35
|
+
#
|
36
|
+
# @return [Hash]
|
37
|
+
#
|
38
|
+
# @api public
|
39
|
+
def self.def_border(characters = (not_set = true), &block)
|
40
|
+
return self.characters = characters unless not_set
|
41
|
+
|
42
|
+
dsl = BorderDSL.new(&block)
|
43
|
+
self.characters = dsl.characters
|
44
|
+
end
|
45
|
+
|
35
46
|
# Instantiate a new object
|
36
47
|
#
|
37
48
|
# @param [Array] column_widths
|
38
49
|
# the table column widths
|
39
50
|
#
|
40
|
-
# @param [BorderOptions]
|
51
|
+
# @param [BorderOptions] border_opts
|
41
52
|
#
|
42
53
|
# @return [Object]
|
43
54
|
#
|
44
55
|
# @api private
|
45
|
-
def initialize(column_widths,
|
56
|
+
def initialize(column_widths, border_opts = nil)
|
46
57
|
if self.class == Border
|
47
|
-
|
48
|
-
else
|
49
|
-
@widths = column_widths
|
50
|
-
@border_options = TTY::Table::BorderOptions.from options
|
51
|
-
@color = Pastel.new
|
58
|
+
raise NotImplementedError, "#{self} is an abstract class"
|
52
59
|
end
|
53
|
-
end
|
54
|
-
|
55
|
-
# Define border characters
|
56
|
-
#
|
57
|
-
# @param [Hash] characters
|
58
|
-
# the border characters
|
59
|
-
#
|
60
|
-
# @return [Hash]
|
61
|
-
#
|
62
|
-
# @api public
|
63
|
-
def self.def_border(characters=(not_set=true), &block)
|
64
|
-
return self.characters = characters unless not_set
|
65
60
|
|
66
|
-
|
67
|
-
|
61
|
+
@widths = column_widths
|
62
|
+
@dsl = BorderDSL.new(border_opts)
|
63
|
+
@characters = self.class.characters.merge(@dsl.characters)
|
64
|
+
@color = Pastel.new
|
68
65
|
end
|
69
66
|
|
70
67
|
# Retrive individual character by type
|
@@ -76,13 +73,7 @@ module TTY
|
|
76
73
|
#
|
77
74
|
# @api private
|
78
75
|
def [](type)
|
79
|
-
characters
|
80
|
-
chars = if border_options.nil?
|
81
|
-
characters
|
82
|
-
else
|
83
|
-
characters.merge(border_options.characters)
|
84
|
-
end
|
85
|
-
chars[type] || EMPTY_CHAR
|
76
|
+
@characters[type] || EMPTY_CHAR
|
86
77
|
end
|
87
78
|
|
88
79
|
# Check if border color is set
|
@@ -91,7 +82,7 @@ module TTY
|
|
91
82
|
#
|
92
83
|
# @api public
|
93
84
|
def color?
|
94
|
-
|
85
|
+
!!@dsl.style
|
95
86
|
end
|
96
87
|
|
97
88
|
# A line spanning all columns marking top of a table.
|
@@ -117,7 +108,7 @@ module TTY
|
|
117
108
|
# @return [String]
|
118
109
|
#
|
119
110
|
# @api private
|
120
|
-
def
|
111
|
+
def middle_line
|
121
112
|
(result = render(:mid)).empty? ? nil : result
|
122
113
|
end
|
123
114
|
|
@@ -130,30 +121,27 @@ module TTY
|
|
130
121
|
#
|
131
122
|
# @api public
|
132
123
|
def row_line(row)
|
133
|
-
line = RowLine.new(self[
|
134
|
-
line.colorize(self,
|
124
|
+
line = RowLine.new(self["left"], self["center"], self["right"])
|
125
|
+
line.colorize(self, @dsl.style) if color?
|
135
126
|
|
136
127
|
result = row_heights(row, line)
|
137
128
|
result.empty? ? EMPTY_CHAR : result
|
138
129
|
end
|
139
130
|
|
140
|
-
# Set color
|
131
|
+
# Set color for a string
|
141
132
|
#
|
142
133
|
# @param [Symbol] color
|
143
134
|
#
|
144
|
-
# @param [
|
135
|
+
# @param [String] string
|
136
|
+
# the string to color
|
145
137
|
#
|
146
|
-
# @return [
|
138
|
+
# @return [String]
|
147
139
|
#
|
148
140
|
# @api public
|
149
|
-
def set_color(color,
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
else
|
154
|
-
@color.decorate(string, color)
|
155
|
-
end
|
156
|
-
end
|
141
|
+
def set_color(color, string)
|
142
|
+
return string if string.gsub(/\s+/, EMPTY_CHAR).empty?
|
143
|
+
|
144
|
+
@color.decorate(string, color)
|
157
145
|
end
|
158
146
|
|
159
147
|
protected
|
@@ -166,7 +154,9 @@ module TTY
|
|
166
154
|
# The table custom border options including styling
|
167
155
|
#
|
168
156
|
# @api private
|
169
|
-
|
157
|
+
def border_options
|
158
|
+
@dsl.options
|
159
|
+
end
|
170
160
|
|
171
161
|
# Separate multiline string into individual rows with border.
|
172
162
|
#
|
@@ -210,7 +200,9 @@ module TTY
|
|
210
200
|
# Generate particular border type
|
211
201
|
#
|
212
202
|
# @param [String] type
|
213
|
-
# border type one of
|
203
|
+
# border type one of :top, :bottom and :mid
|
204
|
+
#
|
205
|
+
# @return [String]
|
214
206
|
#
|
215
207
|
# @api private
|
216
208
|
def render(type)
|
@@ -222,7 +214,8 @@ module TTY
|
|
222
214
|
self["#{type}_mid"])
|
223
215
|
|
224
216
|
return line unless color?
|
225
|
-
|
217
|
+
|
218
|
+
set_color(@dsl.style, line)
|
226
219
|
end
|
227
220
|
|
228
221
|
# Generate a border string
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../border"
|
4
4
|
|
5
5
|
module TTY
|
6
6
|
class Table
|
@@ -11,21 +11,21 @@ module TTY
|
|
11
11
|
class ASCII < Border
|
12
12
|
|
13
13
|
def_border do
|
14
|
-
top
|
15
|
-
top_mid
|
16
|
-
top_left
|
17
|
-
top_right
|
18
|
-
bottom
|
19
|
-
bottom_mid
|
20
|
-
bottom_left
|
21
|
-
bottom_right
|
22
|
-
mid
|
23
|
-
mid_mid
|
24
|
-
mid_left
|
25
|
-
mid_right
|
26
|
-
left
|
27
|
-
center
|
28
|
-
right
|
14
|
+
top "-"
|
15
|
+
top_mid "+"
|
16
|
+
top_left "+"
|
17
|
+
top_right "+"
|
18
|
+
bottom "-"
|
19
|
+
bottom_mid "+"
|
20
|
+
bottom_left "+"
|
21
|
+
bottom_right "+"
|
22
|
+
mid "-"
|
23
|
+
mid_mid "+"
|
24
|
+
mid_left "+"
|
25
|
+
mid_right "+"
|
26
|
+
left "|"
|
27
|
+
center "|"
|
28
|
+
right "|"
|
29
29
|
end
|
30
30
|
|
31
31
|
end # ASCII
|
@@ -1,38 +1,35 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "../border"
|
4
4
|
|
5
5
|
module TTY
|
6
6
|
class Table
|
7
7
|
class Border
|
8
8
|
# A class that represents no border.
|
9
9
|
class Null < Border
|
10
|
-
|
11
10
|
def_border do
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
# how could border_options ever be nil, if we just did border_options.separator
|
28
|
-
border_options ? super : nil
|
11
|
+
top EMPTY_CHAR
|
12
|
+
top_mid EMPTY_CHAR
|
13
|
+
top_left EMPTY_CHAR
|
14
|
+
top_right EMPTY_CHAR
|
15
|
+
bottom EMPTY_CHAR
|
16
|
+
bottom_mid EMPTY_CHAR
|
17
|
+
bottom_left EMPTY_CHAR
|
18
|
+
bottom_right EMPTY_CHAR
|
19
|
+
mid EMPTY_CHAR
|
20
|
+
mid_mid EMPTY_CHAR
|
21
|
+
mid_left EMPTY_CHAR
|
22
|
+
mid_right EMPTY_CHAR
|
23
|
+
left EMPTY_CHAR
|
24
|
+
center SPACE_CHAR
|
25
|
+
right EMPTY_CHAR
|
29
26
|
end
|
30
27
|
|
31
|
-
# A stub
|
28
|
+
# A stub middle line
|
32
29
|
#
|
33
30
|
# @api private
|
34
|
-
def
|
35
|
-
border_options ?
|
31
|
+
def middle_line
|
32
|
+
border_options.separator ? "" : super
|
36
33
|
end
|
37
34
|
end # Null
|
38
35
|
end # Border
|