nazar 1.1.0 → 1.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2689adb3080ba628ef27ab5ce71804352ccb02b2a90dbf363a50373210f7b2bd
4
- data.tar.gz: e8a4f1954eb5d67a62e1f54d4a9983f7d2cb034903bd24d5a7d2dfed626d0808
3
+ metadata.gz: 29342461f59fd102beeb9253deb00b6f54086d855a2a62a11c1e108933f72600
4
+ data.tar.gz: 758f662b5a103a244beea03963ebb79d658ae6e076874cba2cadea66c14869df
5
5
  SHA512:
6
- metadata.gz: ee1752541ac4356428bce4298bb5a6ff011b83943784ed0727adeec0c82b9763465944324dd8672d5cfb27e0a28e05e44f2dc796a9a28d5459086804b5c1a7c4
7
- data.tar.gz: 7eb125d122b3c424251eb6ef76554d5737d24509659d12c1414cab0ad48fb59f790b63a0c8cf264273b10f3786efb7b1397db2549a3ef4dc8af6963ef4e7e62c
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.
@@ -25,7 +25,7 @@ module Nazar
25
25
  end
26
26
 
27
27
  def resize
28
- Nazar.config.formatter.resize
28
+ Nazar.config.table.resize
29
29
  end
30
30
 
31
31
  def summary_row(value)
@@ -3,7 +3,7 @@
3
3
  module Nazar
4
4
  class HorizontalTable < BaseTable
5
5
  def render
6
- table.render(:unicode, border: { separator: :each_row }, multiline: true, resize: resize)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nazar
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
@@ -23,7 +23,7 @@ module Nazar
23
23
  end
24
24
 
25
25
  def render
26
- table.render_with(VerticalBorder, multiline: true, resize: resize) do |renderer|
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
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nazar
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Krzyżanowski
metadata.gz.sig CHANGED
Binary file