nazar 1.0.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: 2f577a21e50d8bf8606ed8e8bf115a2c2fb0909b2ee7c1fae72fb4ef871064d0
4
- data.tar.gz: '0609ff110d8ce48f3df2fd297ccd02e047d6730985b2698f9592c8f68e39df1b'
3
+ metadata.gz: 2689adb3080ba628ef27ab5ce71804352ccb02b2a90dbf363a50373210f7b2bd
4
+ data.tar.gz: e8a4f1954eb5d67a62e1f54d4a9983f7d2cb034903bd24d5a7d2dfed626d0808
5
5
  SHA512:
6
- metadata.gz: fbf98c584b508c82a19e69730403dda91e54b3f5d6c6a833ba535149591647445c14222b4bda7440090565c5b97a5e777c0b33d331c6a90194b3f32ac5962d03
7
- data.tar.gz: da49a17743f2676d1178eb76df8e17c93752f6ad4d22dbe6195398a59f34ec4121315ffb4007c87ee704ed2d9fc4507fd9d9ac87ef72fbafb98eb933f8e1725d
6
+ metadata.gz: ee1752541ac4356428bce4298bb5a6ff011b83943784ed0727adeec0c82b9763465944324dd8672d5cfb27e0a28e05e44f2dc796a9a28d5459086804b5c1a7c4
7
+ data.tar.gz: 7eb125d122b3c424251eb6ef76554d5737d24509659d12c1414cab0ad48fb59f790b63a0c8cf264273b10f3786efb7b1397db2549a3ef4dc8af6963ef4e7e62c
checksums.yaml.gz.sig CHANGED
Binary file
data/.rubocop.yml CHANGED
@@ -12,4 +12,6 @@ Metrics/BlockLength:
12
12
  Layout/CaseIndentation:
13
13
  EnforcedStyle: end
14
14
  Layout/EndAlignment:
15
- EnforcedStyleAlignWith: variable
15
+ EnforcedStyleAlignWith: variable
16
+ Layout/FirstArrayElementIndentation:
17
+ EnforcedStyle: consistent
data/README.md CHANGED
@@ -240,6 +240,7 @@ 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 |
243
244
  | `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 |
244
245
 
245
246
  ## Contributing
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nazar
4
+ class BaseTable
5
+ def initialize(headers, cells)
6
+ @headers = headers
7
+ @cells = cells
8
+ end
9
+
10
+ def render
11
+ table.render
12
+ end
13
+
14
+ def add_summary(value)
15
+ table << :separator
16
+ table << summary_row(value)
17
+ end
18
+
19
+ private
20
+
21
+ attr_reader :headers, :cells
22
+
23
+ def table
24
+ @table ||= TTY::Table.new(header: headers, rows: cells)
25
+ end
26
+
27
+ def resize
28
+ Nazar.config.formatter.resize
29
+ end
30
+
31
+ def summary_row(value)
32
+ [pastel.bold('Total'), value]
33
+ end
34
+
35
+ def pastel
36
+ @pastel ||= Pastel.new(enabled: Nazar.config.colors.enabled)
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nazar
4
+ class HorizontalTable < BaseTable
5
+ def render
6
+ table.render(:unicode, border: { separator: :each_row }, multiline: true, resize: resize)
7
+ end
8
+
9
+ private
10
+
11
+ def summary_row(value)
12
+ super.fill(nil, 3, table.columns_size - 3)
13
+ end
14
+ end
15
+ 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.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nazar
4
+ class VerticalTable < BaseTable
5
+ class VerticalBorder < TTY::Table::Border
6
+ def_border do
7
+ top '─'
8
+ top_mid '─'
9
+ top_left '─'
10
+ top_right '─'
11
+ bottom '─'
12
+ bottom_mid '─'
13
+ bottom_left '─'
14
+ bottom_right '─'
15
+ mid '─'
16
+ mid_mid '─'
17
+ mid_left '─'
18
+ mid_right '─'
19
+ left ''
20
+ center ''
21
+ right ''
22
+ end
23
+ end
24
+
25
+ def render
26
+ table.render_with(VerticalBorder, multiline: true, resize: resize) do |renderer|
27
+ renderer.border.style = :green if Nazar.config.colors.enabled
28
+ renderer.border.separator = separators_around_each_item
29
+ end
30
+ end
31
+
32
+ private_constant :VerticalBorder
33
+
34
+ private
35
+
36
+ def table
37
+ @table ||= TTY::Table.new(rows: cells)
38
+ end
39
+
40
+ def cells
41
+ @cells.flat_map do |cell|
42
+ cell.map.with_index do |item, index|
43
+ ["#{headers[index]} ", item]
44
+ end
45
+ end
46
+ end
47
+
48
+ def separators_around_each_item
49
+ (0...cells.size).select do |i|
50
+ (i % headers.size).zero? || ((i + 1) % headers.size).zero?
51
+ end
52
+ end
53
+ end
54
+ end
data/lib/nazar/view.rb CHANGED
@@ -4,7 +4,7 @@ module Nazar
4
4
  class View
5
5
  extend Forwardable
6
6
 
7
- def_delegators :formatter, :headers, :summary
7
+ def_delegators :formatter, :headers, :cells, :summary
8
8
 
9
9
  def initialize(data, layout:, use_generic_formatter: false)
10
10
  @data = data
@@ -15,9 +15,9 @@ module Nazar
15
15
  def render
16
16
  return unless supported_data?
17
17
 
18
- table.tap do
19
- add_summary if summary
20
- end
18
+ table.add_summary(summary) if summary
19
+
20
+ table.render
21
21
  end
22
22
 
23
23
  def supported_data?
@@ -52,7 +52,7 @@ module Nazar
52
52
  def table_width
53
53
  [
54
54
  headers.map(&:size).sum,
55
- horizontal_cells.map { |row| row.map(&:size).sum }.max
55
+ *cells.map { |row| row.map(&:size).sum }
56
56
  ].max
57
57
  end
58
58
 
@@ -70,48 +70,8 @@ module Nazar
70
70
  @formatter ||= formatter_klass.new(data)
71
71
  end
72
72
 
73
- def add_summary
74
- colspan = horizontal? ? headers.size - 1 : 1
75
-
76
- table.add_separator
77
- table.add_row [pastel.bold('Total'), { value: summary, colspan: colspan }]
78
- end
79
-
80
73
  def table
81
- @table ||= Terminal::Table.new(
82
- headings: display_headers,
83
- rows: display_cells,
84
- style: { border: :unicode_thick_edge }
85
- )
86
- end
87
-
88
- def display_headers
89
- horizontal? ? formatter.headers : []
90
- end
91
-
92
- def display_cells
93
- horizontal? ? horizontal_cells : vertical_cells
94
- end
95
-
96
- def horizontal_cells
97
- formatter.cells
98
- end
99
-
100
- def vertical_cells
101
- data = horizontal_cells.inject([]) do |output, items|
102
- items.each.with_index do |item, index|
103
- output << [headers[index], item]
104
- end
105
-
106
- output << :separator
107
- end
108
-
109
- data.pop # remove last separator
110
- data
111
- end
112
-
113
- def pastel
114
- @pastel ||= Pastel.new(enabled: Nazar.config.colors.enabled)
74
+ @table ||= horizontal? ? HorizontalTable.new(headers, cells) : VerticalTable.new(headers, cells)
115
75
  end
116
76
  end
117
77
  end
data/lib/nazar.rb CHANGED
@@ -1,11 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dry-configurable'
4
- require 'terminal-table'
4
+ require 'tty-table'
5
5
  require 'pastel'
6
6
  require 'tty-pager'
7
7
 
8
8
  require 'nazar/version'
9
+ require 'nazar/base_table'
10
+ require 'nazar/horizontal_table'
11
+ require 'nazar/vertical_table'
9
12
  require 'nazar/cell_formatter'
10
13
  require 'nazar/headers_formatter'
11
14
  require 'nazar/renderer'
@@ -21,6 +24,7 @@ module Nazar # rubocop:disable Metrics/ModuleLength
21
24
  setting :boolean, default: ['✓', '✗']
22
25
  setting :layout, default: :auto
23
26
  setting :paginate, default: true
27
+ setting :resize, default: true
24
28
  end
25
29
 
26
30
  setting :colors do
data/nazar.gemspec CHANGED
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
36
36
 
37
37
  spec.add_runtime_dependency 'dry-configurable', '~> 0.12'
38
38
  spec.add_runtime_dependency 'pastel', '~> 0.8'
39
- spec.add_runtime_dependency 'terminal-table', '~> 3.0'
40
39
  spec.add_runtime_dependency 'tty-pager', '~> 0.14'
41
40
  spec.add_runtime_dependency 'tty-screen', '~> 0.8'
41
+ spec.add_runtime_dependency 'tty-table', '~> 0.12'
42
42
  end
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.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michał Krzyżanowski
@@ -36,7 +36,7 @@ cert_chain:
36
36
  WXVb638bzH4OYBIYuGcw50jqBK1SyDx4exzThr6KxSiGwhAKj2xFqy51MIQjfUN0
37
37
  TL5B7Buq
38
38
  -----END CERTIFICATE-----
39
- date: 2022-09-19 00:00:00.000000000 Z
39
+ date: 2022-10-12 00:00:00.000000000 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: activerecord
@@ -143,47 +143,47 @@ dependencies:
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0.8'
145
145
  - !ruby/object:Gem::Dependency
146
- name: terminal-table
146
+ name: tty-pager
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '3.0'
151
+ version: '0.14'
152
152
  type: :runtime
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '3.0'
158
+ version: '0.14'
159
159
  - !ruby/object:Gem::Dependency
160
- name: tty-pager
160
+ name: tty-screen
161
161
  requirement: !ruby/object:Gem::Requirement
162
162
  requirements:
163
163
  - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: '0.14'
165
+ version: '0.8'
166
166
  type: :runtime
167
167
  prerelease: false
168
168
  version_requirements: !ruby/object:Gem::Requirement
169
169
  requirements:
170
170
  - - "~>"
171
171
  - !ruby/object:Gem::Version
172
- version: '0.14'
172
+ version: '0.8'
173
173
  - !ruby/object:Gem::Dependency
174
- name: tty-screen
174
+ name: tty-table
175
175
  requirement: !ruby/object:Gem::Requirement
176
176
  requirements:
177
177
  - - "~>"
178
178
  - !ruby/object:Gem::Version
179
- version: '0.8'
179
+ version: '0.12'
180
180
  type: :runtime
181
181
  prerelease: false
182
182
  version_requirements: !ruby/object:Gem::Requirement
183
183
  requirements:
184
184
  - - "~>"
185
185
  - !ruby/object:Gem::Version
186
- version: '0.8'
186
+ version: '0.12'
187
187
  description:
188
188
  email:
189
189
  - michal.krzyzanowski+github@gmail.com
@@ -203,6 +203,7 @@ files:
203
203
  - bin/setup
204
204
  - certs/krzyzak.pem
205
205
  - lib/nazar.rb
206
+ - lib/nazar/base_table.rb
206
207
  - lib/nazar/cell_formatter.rb
207
208
  - lib/nazar/formatter.rb
208
209
  - lib/nazar/formatter/active_record_collection.rb
@@ -214,8 +215,10 @@ files:
214
215
  - lib/nazar/formatter/sequel_interface.rb
215
216
  - lib/nazar/formatter/sequel_item.rb
216
217
  - lib/nazar/headers_formatter.rb
218
+ - lib/nazar/horizontal_table.rb
217
219
  - lib/nazar/renderer.rb
218
220
  - lib/nazar/version.rb
221
+ - lib/nazar/vertical_table.rb
219
222
  - lib/nazar/view.rb
220
223
  - nazar.gemspec
221
224
  homepage: https://github.com/krzyzak/nazar
metadata.gz.sig CHANGED
Binary file