rex-text 0.2.47 → 0.2.49
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
- checksums.yaml.gz.sig +2 -3
- data/.github/workflows/verify.yml +6 -5
- data/lib/rex/text/version.rb +1 -1
- data/lib/rex/text/wrapped_table.rb +56 -31
- data/lib/rex/text.rb +2 -0
- data.tar.gz.sig +0 -0
- metadata +2 -2
- 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: 2dbca3eaa8e600c95598ce2e14261052aec73785652853b57ad9474f90d1e1b1
|
4
|
+
data.tar.gz: 1e9dd3118f755430e2605f31baa00fe89833827922ff6724ee500a30d9f2b815
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d88703aa90f25147e9a01ae1451af03f73a2eb42a026b3eb048d8b186f2ef5c7ed97c97b6f67f39c8c1ebef99292924177d2f50c9a3f67ee085ec0c8ce6bb9b7
|
7
|
+
data.tar.gz: 484fb54c5e7a289c4450cc165bb28d9ba53c85f2d471e0c1f60c87dc68ad99475e100243c734213358dfccf47a6fef9c563b6b832fbbb4d21d142b98fdb51c1b
|
checksums.yaml.gz.sig
CHANGED
@@ -1,3 +1,2 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
~�#�k[r��|�/��yq�ݓ�ߛ�N�
|
1
|
+
�ai�ħ���{r�XZ,[CG�w���E�C�ӑ�U7)�09-��*��ų�XE��&��������LKv@��2�o�_��DK����.�~��*G��^�IOl����^�,��e��BF\F�r�h>�d$M�Z����8F�b`V��[y��y۾
|
2
|
+
1�Q"���H���dЕ�8��K s�xh.�՟yrU�fR來����p@T������F7{����:��Rֳ땒_K0��%���)��
|
@@ -33,15 +33,16 @@ jobs:
|
|
33
33
|
fail-fast: true
|
34
34
|
matrix:
|
35
35
|
ruby:
|
36
|
-
- 2.7
|
37
|
-
- 3.0
|
38
|
-
- 3.1
|
36
|
+
- '2.7'
|
37
|
+
- '3.0'
|
38
|
+
- '3.1'
|
39
|
+
- '3.2'
|
39
40
|
os:
|
40
41
|
- ubuntu-20.04
|
41
42
|
- ubuntu-latest
|
42
43
|
exclude:
|
43
|
-
- { os: ubuntu-latest, ruby: 2.7 }
|
44
|
-
- { os: ubuntu-latest, ruby: 3.0 }
|
44
|
+
- { os: ubuntu-latest, ruby: '2.7' }
|
45
|
+
- { os: ubuntu-latest, ruby: '3.0' }
|
45
46
|
test_cmd:
|
46
47
|
- bundle exec rspec
|
47
48
|
|
data/lib/rex/text/version.rb
CHANGED
@@ -56,13 +56,13 @@ class WrappedTable
|
|
56
56
|
#
|
57
57
|
# The text to affix to the end of the table.
|
58
58
|
#
|
59
|
-
#
|
59
|
+
# SortIndex
|
60
60
|
#
|
61
61
|
# The column to sort the table on, -1 disables sorting.
|
62
62
|
#
|
63
63
|
# ColProps
|
64
64
|
#
|
65
|
-
# A hash specifying column
|
65
|
+
# A hash specifying column Width, Stylers, and Formatters.
|
66
66
|
#
|
67
67
|
def initialize(opts = {})
|
68
68
|
self.header = opts['Header']
|
@@ -85,10 +85,11 @@ class WrappedTable
|
|
85
85
|
# Default column properties
|
86
86
|
self.columns.length.times { |idx|
|
87
87
|
self.colprops[idx] = {}
|
88
|
-
self.colprops[idx]['
|
88
|
+
self.colprops[idx]['Width'] = nil
|
89
89
|
self.colprops[idx]['WordWrap'] = true
|
90
90
|
self.colprops[idx]['Stylers'] = []
|
91
91
|
self.colprops[idx]['Formatters'] = []
|
92
|
+
self.colprops[idx]['ColumnStylers'] = []
|
92
93
|
}
|
93
94
|
|
94
95
|
# ensure all our internal state gets updated with the given rows by
|
@@ -112,20 +113,28 @@ class WrappedTable
|
|
112
113
|
# Converts table contents to a string.
|
113
114
|
#
|
114
115
|
def to_s
|
116
|
+
sort_rows
|
117
|
+
|
118
|
+
# Loop over and style columns
|
119
|
+
styled_columns = columns.map.with_index { |col, idx| style_table_column_headers(col, idx) }
|
120
|
+
# Loop over and style rows that are visible to the user
|
121
|
+
styled_rows = rows.select { |row| row_visible(row) }
|
122
|
+
.map! { |row| row.map.with_index { |cell, index| style_table_field(cell, index) } }
|
123
|
+
|
124
|
+
optimal_widths = calculate_optimal_widths(styled_columns, styled_rows)
|
125
|
+
|
115
126
|
str = prefix.dup
|
116
127
|
str << header_to_s || ''
|
117
|
-
str << columns_to_s || ''
|
128
|
+
str << columns_to_s(styled_columns, optimal_widths) || ''
|
118
129
|
str << hr_to_s || ''
|
119
130
|
|
120
|
-
|
121
|
-
|
122
|
-
if (is_hr(row))
|
131
|
+
styled_rows.each { |row|
|
132
|
+
if is_hr(row)
|
123
133
|
str << hr_to_s
|
124
134
|
else
|
125
|
-
str << row_to_s(row
|
135
|
+
str << row_to_s(row, optimal_widths)
|
126
136
|
end
|
127
137
|
}
|
128
|
-
|
129
138
|
str << postfix
|
130
139
|
|
131
140
|
return str
|
@@ -185,11 +194,6 @@ class WrappedTable
|
|
185
194
|
formatted_fields = fields.map.with_index { |field, idx|
|
186
195
|
field = format_table_field(field, idx)
|
187
196
|
|
188
|
-
if (colprops[idx]['MaxWidth'] < display_width(field))
|
189
|
-
old = colprops[idx]['MaxWidth']
|
190
|
-
colprops[idx]['MaxWidth'] = display_width(field)
|
191
|
-
end
|
192
|
-
|
193
197
|
field
|
194
198
|
}
|
195
199
|
|
@@ -333,7 +337,7 @@ protected
|
|
333
337
|
#
|
334
338
|
def row_visible(row)
|
335
339
|
return true if self.scterm.nil?
|
336
|
-
|
340
|
+
row.join(' ').match(self.scterm)
|
337
341
|
end
|
338
342
|
|
339
343
|
#
|
@@ -354,8 +358,7 @@ protected
|
|
354
358
|
#
|
355
359
|
# Converts the columns to a string.
|
356
360
|
#
|
357
|
-
def columns_to_s # :nodoc:
|
358
|
-
optimal_widths = calculate_optimal_widths
|
361
|
+
def columns_to_s(columns, optimal_widths) # :nodoc:
|
359
362
|
values_as_chunks = chunk_values(columns, optimal_widths)
|
360
363
|
result = chunks_to_s(values_as_chunks, optimal_widths)
|
361
364
|
|
@@ -389,9 +392,7 @@ protected
|
|
389
392
|
#
|
390
393
|
# Converts a row to a string.
|
391
394
|
#
|
392
|
-
def row_to_s(row) # :nodoc:
|
393
|
-
row = row.each_with_index.map { |cell, index| style_table_field(cell, index) }
|
394
|
-
optimal_widths = calculate_optimal_widths
|
395
|
+
def row_to_s(row, optimal_widths) # :nodoc:
|
395
396
|
values_as_chunks = chunk_values(row, optimal_widths)
|
396
397
|
chunks_to_s(values_as_chunks, optimal_widths)
|
397
398
|
end
|
@@ -567,12 +568,26 @@ protected
|
|
567
568
|
without_extra_column
|
568
569
|
end
|
569
570
|
|
570
|
-
def calculate_optimal_widths
|
571
|
-
|
571
|
+
def calculate_optimal_widths(styled_columns, styled_rows)
|
572
|
+
total_columns = self.colprops.length
|
573
|
+
# Calculate the display width metadata, i.e. the size of the longest strings in the table
|
574
|
+
display_width_metadata = Array.new(total_columns) { {} }
|
575
|
+
[[styled_columns], styled_rows].each do |group|
|
576
|
+
group.each do |row|
|
577
|
+
row.each.with_index do |cell, column_index|
|
578
|
+
metadata = display_width_metadata[column_index]
|
579
|
+
cell_display_width = display_width(cell)
|
580
|
+
if cell_display_width > (metadata[:max_display_width] || 0)
|
581
|
+
metadata[:max_display_width] = cell_display_width
|
582
|
+
end
|
583
|
+
end
|
584
|
+
end
|
585
|
+
end
|
586
|
+
|
587
|
+
# Calculate the sizes set by the user
|
572
588
|
user_influenced_column_widths = colprops.map do |colprop|
|
573
|
-
if colprop['
|
574
|
-
colprop['
|
575
|
-
raise 'Not implemented'
|
589
|
+
if colprop['Width']
|
590
|
+
colprop['Width']
|
576
591
|
else
|
577
592
|
nil
|
578
593
|
end
|
@@ -583,15 +598,16 @@ protected
|
|
583
598
|
remaining_column_calculations = user_influenced_column_widths.select(&:nil?).count
|
584
599
|
|
585
600
|
# Calculate the initial widths, which will need an additional refinement to reallocate surplus space
|
586
|
-
naive_optimal_width_calculations =
|
601
|
+
naive_optimal_width_calculations = display_width_metadata.map.with_index do |display_size, index|
|
587
602
|
shared_column_width = available_space / [remaining_column_calculations, 1].max
|
588
603
|
remaining_column_calculations -= 1
|
589
604
|
|
605
|
+
# Preference the user defined widths first
|
590
606
|
if user_influenced_column_widths[index]
|
591
607
|
{ width: user_influenced_column_widths[index], wrapped: false }
|
592
|
-
elsif
|
593
|
-
available_space -=
|
594
|
-
{ width:
|
608
|
+
elsif display_size[:max_display_width] < shared_column_width
|
609
|
+
available_space -= display_size[:max_display_width]
|
610
|
+
{ width: display_size[:max_display_width], wrapped: false }
|
595
611
|
else
|
596
612
|
available_space -= shared_column_width
|
597
613
|
{ width: shared_column_width, wrapped: true }
|
@@ -608,7 +624,7 @@ protected
|
|
608
624
|
revisiting_column_counts -= 1
|
609
625
|
|
610
626
|
if naive_width[:wrapped]
|
611
|
-
max_width =
|
627
|
+
max_width = display_width_metadata[index][:max_display_width]
|
612
628
|
if max_width < (naive_width[:width] + additional_column_width)
|
613
629
|
surplus_width -= max_width - naive_width[:width]
|
614
630
|
max_width
|
@@ -638,6 +654,16 @@ protected
|
|
638
654
|
str_cp
|
639
655
|
end
|
640
656
|
|
657
|
+
def style_table_column_headers(str, idx)
|
658
|
+
str_cp = str.dup
|
659
|
+
|
660
|
+
colprops[idx]['ColumnStylers'].each do |s|
|
661
|
+
str_cp = s.style(str_cp)
|
662
|
+
end
|
663
|
+
|
664
|
+
str_cp
|
665
|
+
end
|
666
|
+
|
641
667
|
def style_table_field(str, idx)
|
642
668
|
str_cp = str.dup
|
643
669
|
|
@@ -652,4 +678,3 @@ end
|
|
652
678
|
|
653
679
|
end
|
654
680
|
end
|
655
|
-
|
data/lib/rex/text.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rex-text
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.49
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Metasploit Hackers
|
@@ -93,7 +93,7 @@ cert_chain:
|
|
93
93
|
EknWpNgVhohbot1lfVAMmIhdtOVaRVcQQixWPwprDj/ydB8ryDMDosIMcw+fkoXU
|
94
94
|
9GJsSaSRRYQ9UUkVL27b64okU8D48m8=
|
95
95
|
-----END CERTIFICATE-----
|
96
|
-
date:
|
96
|
+
date: 2023-02-02 00:00:00.000000000 Z
|
97
97
|
dependencies:
|
98
98
|
- !ruby/object:Gem::Dependency
|
99
99
|
name: rake
|
metadata.gz.sig
CHANGED
Binary file
|