nazar 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.md +3 -2
- data/lib/nazar/base_table.rb +1 -1
- data/lib/nazar/horizontal_table.rb +7 -1
- data/lib/nazar/version.rb +1 -1
- data/lib/nazar/vertical_table.rb +48 -1
- data/lib/nazar.rb +5 -0
- data.tar.gz.sig +0 -0
- metadata +1 -1
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29342461f59fd102beeb9253deb00b6f54086d855a2a62a11c1e108933f72600
|
4
|
+
data.tar.gz: 758f662b5a103a244beea03963ebb79d658ae6e076874cba2cadea66c14869df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0fcbdca62c72558c2ae5278efc603dbe30ef4a08ea7966a198a4f53ce58227cec71b36bdf5acc37954b47f7c379e460947c6ab8e12c804b38e74b08610aa1d9
|
7
|
+
data.tar.gz: 07e02b611b902f7736ff1936b80b285da36e3fcacfc1492832eaf1b9ae307eaaa274d12f407d7cbbac4abc22a250a723943b449955dcb764c393b0a8d3650803
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/README.md
CHANGED
@@ -240,9 +240,10 @@ You can also configure behaviour of Nazar:
|
|
240
240
|
| `Nazar.config.formatter.layout` | `:auto` | Determines which layout should be used. See <a href="#layouts">Layouts</a> for more details |
|
241
241
|
| `Nazar.config.formatter.paginate` | `true` | Determines if results too long/wide should be printed directly, or paginated with `less`. Horizontal layout is always paginated.
|
242
242
|
| `Nazar.config.formatter.boolean` | ['✓', '✗'] | First item in array is a character for `true`, second for `false` |
|
243
|
-
| `Nazar.config.formatter.resize` | `true` | Determines if the table should always be resized to take full width |
|
244
243
|
| `Nazar.config.enable_shorthand_method` | true | Determines if shorthand method should be defined. See <a href="#opt-in-setup">Opt-in setup</a> for more details |
|
245
|
-
|
244
|
+
| `Nazar.config.table.resize` | `true` | Determines if the table should always be resized to take full width |
|
245
|
+
| `Nazar.config.table.min_width` | `nil` | Sets minimum width. By default uses the longest header length |
|
246
|
+
| `Nazar.config.table.max_width` | `nil` | Determines maximum table width. If `resize` is set to true, uses terminal width by default, otherwise uses content length |
|
246
247
|
## Contributing
|
247
248
|
|
248
249
|
Bug reports and pull requests are welcome on GitHub at https://github.com/krzyzak/nazar.
|
data/lib/nazar/base_table.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
module Nazar
|
4
4
|
class HorizontalTable < BaseTable
|
5
5
|
def render
|
6
|
-
table.render(:unicode,
|
6
|
+
table.render(:unicode, options)
|
7
7
|
end
|
8
8
|
|
9
9
|
private
|
@@ -11,5 +11,11 @@ module Nazar
|
|
11
11
|
def summary_row(value)
|
12
12
|
super.fill(nil, 3, table.columns_size - 3)
|
13
13
|
end
|
14
|
+
|
15
|
+
def options
|
16
|
+
{ border: { separator: :each_row }, multiline: true, resize: resize }.tap do |hash|
|
17
|
+
hash[:width] = Nazar.config.table.max_width if Nazar.config.table.max_width
|
18
|
+
end
|
19
|
+
end
|
14
20
|
end
|
15
21
|
end
|
data/lib/nazar/version.rb
CHANGED
data/lib/nazar/vertical_table.rb
CHANGED
@@ -23,7 +23,7 @@ module Nazar
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def render
|
26
|
-
table.render_with(VerticalBorder,
|
26
|
+
table.render_with(VerticalBorder, options) do |renderer|
|
27
27
|
renderer.border.style = :green if Nazar.config.colors.enabled
|
28
28
|
renderer.border.separator = separators_around_each_item
|
29
29
|
end
|
@@ -37,6 +37,15 @@ module Nazar
|
|
37
37
|
@table ||= TTY::Table.new(rows: cells)
|
38
38
|
end
|
39
39
|
|
40
|
+
def options
|
41
|
+
{
|
42
|
+
multiline: true,
|
43
|
+
resize: resize,
|
44
|
+
column_widths: column_widths,
|
45
|
+
width: max_width
|
46
|
+
}
|
47
|
+
end
|
48
|
+
|
40
49
|
def cells
|
41
50
|
@cells.flat_map do |cell|
|
42
51
|
cell.map.with_index do |item, index|
|
@@ -50,5 +59,43 @@ module Nazar
|
|
50
59
|
(i % headers.size).zero? || ((i + 1) % headers.size).zero?
|
51
60
|
end
|
52
61
|
end
|
62
|
+
|
63
|
+
def column_widths
|
64
|
+
[headers_width, values_width]
|
65
|
+
end
|
66
|
+
|
67
|
+
def max_width
|
68
|
+
Nazar.config.table.max_width || default_width
|
69
|
+
end
|
70
|
+
|
71
|
+
def default_width
|
72
|
+
Nazar.config.table.resize ? TTY::Screen.width : natural_width + padding
|
73
|
+
end
|
74
|
+
|
75
|
+
def natural_width
|
76
|
+
content_size = headers_width + content_width
|
77
|
+
|
78
|
+
[content_size, TTY::Screen.width].min
|
79
|
+
end
|
80
|
+
|
81
|
+
def content_width
|
82
|
+
cells.flatten.map(&:size).max
|
83
|
+
end
|
84
|
+
|
85
|
+
def headers_width
|
86
|
+
[headers.map(&:size).max + 1, Nazar.config.table.min_width].compact.min
|
87
|
+
end
|
88
|
+
|
89
|
+
def values_width
|
90
|
+
if Nazar.config.table.resize
|
91
|
+
TTY::Screen.width - headers_width
|
92
|
+
else
|
93
|
+
[content_width, TTY::Screen.width - headers_width].min
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def padding
|
98
|
+
3
|
99
|
+
end
|
53
100
|
end
|
54
101
|
end
|
data/lib/nazar.rb
CHANGED
@@ -24,7 +24,12 @@ module Nazar # rubocop:disable Metrics/ModuleLength
|
|
24
24
|
setting :boolean, default: ['✓', '✗']
|
25
25
|
setting :layout, default: :auto
|
26
26
|
setting :paginate, default: true
|
27
|
+
end
|
28
|
+
|
29
|
+
setting :table do
|
27
30
|
setting :resize, default: true
|
31
|
+
setting :min_width, default: nil
|
32
|
+
setting :max_width, default: nil
|
28
33
|
end
|
29
34
|
|
30
35
|
setting :colors do
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
metadata.gz.sig
CHANGED
Binary file
|