formatador 1.1.0 → 1.2.3
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/SECURITY.md +6 -0
- data/changelog.txt +43 -0
- data/formatador.gemspec +5 -3
- data/lib/formatador/table.rb +5 -9
- data/lib/formatador.rb +73 -58
- data/tests/table_tests.rb +29 -0
- metadata +18 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5fe34f9dc5c0f7ecda25c5d1a6b486befaed871f0ea3b2d1b2811e82b3c1656b
|
|
4
|
+
data.tar.gz: 1e2580cb52975afa3a63f34e86a46b4e7c48b4d501cc0b126f21b0d60133fdc9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 37e1cef3d87ee2c5b90f781f526eea22444de15db0f8fa827eeffc790aaae3f5b935314013ebaab9bbd49f605c7057633683e6f606f503f0c978355260a29ca4
|
|
7
|
+
data.tar.gz: 24566111d7be71a3cbb6cb834f0fe439d34df11fc9e78aca14540ad54e903eabf4691c76d56ae21dab213b836e9cc4b7ad5221ca3aebe938a0a664c8558568bf
|
data/SECURITY.md
ADDED
data/changelog.txt
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
v1.2.3 11/10/25
|
|
2
|
+
===============
|
|
3
|
+
|
|
4
|
+
add set_title to set terminal title via escape sequences
|
|
5
|
+
|
|
6
|
+
v1.2.2 10/28/25
|
|
7
|
+
===============
|
|
8
|
+
|
|
9
|
+
add faint
|
|
10
|
+
|
|
11
|
+
v1.2.1 09/17/25
|
|
12
|
+
===============
|
|
13
|
+
|
|
14
|
+
add color output support for github actions
|
|
15
|
+
fix most lints
|
|
16
|
+
|
|
17
|
+
v1.2.0 08/08/25
|
|
18
|
+
===============
|
|
19
|
+
|
|
20
|
+
switch to reline for table-width calculations
|
|
21
|
+
|
|
22
|
+
v1.1.1 07/11/25
|
|
23
|
+
===============
|
|
24
|
+
|
|
25
|
+
update actions/stale
|
|
26
|
+
update actions/checkout
|
|
27
|
+
improve unicode support
|
|
28
|
+
update ruby versions in test matrix
|
|
29
|
+
add funding info
|
|
30
|
+
move scheduled CI to weekly
|
|
31
|
+
update tested ruby versions
|
|
32
|
+
more consistently use length method in tables
|
|
33
|
+
adjust expected test output for Ruby 3.4+
|
|
34
|
+
|
|
35
|
+
v1.1.0 01/24/22
|
|
36
|
+
===============
|
|
37
|
+
|
|
38
|
+
fixes to support ruby 3+
|
|
39
|
+
add options for right justifying numerics
|
|
40
|
+
drop unused gemspec directive
|
|
41
|
+
use https for rubygems.org in gemspec
|
|
42
|
+
drop duplicate bundle install from CI setup
|
|
43
|
+
|
|
1
44
|
v1.0.0 01/20/21
|
|
2
45
|
===============
|
|
3
46
|
|
data/formatador.gemspec
CHANGED
|
@@ -7,14 +7,14 @@
|
|
|
7
7
|
Gem::Specification.new do |s|
|
|
8
8
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
|
9
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
10
|
-
s.rubygems_version = '
|
|
10
|
+
s.rubygems_version = '3.6.9'
|
|
11
11
|
|
|
12
12
|
## Leave these as is they will be modified for you by the rake gemspec task.
|
|
13
13
|
## If your rubyforge_project name is different, then edit it and comment out
|
|
14
14
|
## the sub! line in the Rakefile
|
|
15
15
|
s.name = 'formatador'
|
|
16
|
-
s.version = '1.
|
|
17
|
-
s.date = '
|
|
16
|
+
s.version = '1.2.3'
|
|
17
|
+
s.date = '2025-11-10'
|
|
18
18
|
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
|
20
20
|
## as you like.
|
|
@@ -49,6 +49,7 @@ Gem::Specification.new do |s|
|
|
|
49
49
|
## List your runtime dependencies here. Runtime dependencies are those
|
|
50
50
|
## that are needed for an end user to actually USE your code.
|
|
51
51
|
# s.add_dependency('DEPNAME', [">= 1.1.0", "< 2.0.0"])
|
|
52
|
+
s.add_dependency('reline')
|
|
52
53
|
|
|
53
54
|
## List your development dependencies here. Development dependencies are
|
|
54
55
|
## those that are only needed during development
|
|
@@ -67,6 +68,7 @@ Gem::Specification.new do |s|
|
|
|
67
68
|
LICENSE.md
|
|
68
69
|
README.md
|
|
69
70
|
Rakefile
|
|
71
|
+
SECURITY.md
|
|
70
72
|
changelog.txt
|
|
71
73
|
formatador.gemspec
|
|
72
74
|
lib/formatador.rb
|
data/lib/formatador/table.rb
CHANGED
|
@@ -14,7 +14,7 @@ class Formatador
|
|
|
14
14
|
# Calculate Widths
|
|
15
15
|
if hashes.empty? && keys
|
|
16
16
|
keys.each do |key|
|
|
17
|
-
widths[key] = key
|
|
17
|
+
widths[key] = length(key)
|
|
18
18
|
end
|
|
19
19
|
else
|
|
20
20
|
hashes.each do |hash|
|
|
@@ -24,7 +24,7 @@ class Formatador
|
|
|
24
24
|
if !keys
|
|
25
25
|
headers << key
|
|
26
26
|
end
|
|
27
|
-
widths[key] = [
|
|
27
|
+
widths[key] = [length(key), widths[key] || 0, length(calculate_datum(key, hash)) || 0].max
|
|
28
28
|
end
|
|
29
29
|
headers = headers.uniq
|
|
30
30
|
end
|
|
@@ -52,7 +52,7 @@ class Formatador
|
|
|
52
52
|
# Display data row
|
|
53
53
|
columns = []
|
|
54
54
|
headers.each do |header|
|
|
55
|
-
columns << "[bold]#{header}[/]#{' ' * (widths[header] - header
|
|
55
|
+
columns << "[bold]#{header}[/]#{' ' * (widths[header] - length(header))}"
|
|
56
56
|
end
|
|
57
57
|
display_line("| #{columns.join(' | ')} |")
|
|
58
58
|
display_line(split)
|
|
@@ -70,7 +70,7 @@ class Formatador
|
|
|
70
70
|
else
|
|
71
71
|
if hash == :split
|
|
72
72
|
display_line(split)
|
|
73
|
-
end
|
|
73
|
+
end
|
|
74
74
|
end
|
|
75
75
|
nil
|
|
76
76
|
end
|
|
@@ -80,11 +80,7 @@ class Formatador
|
|
|
80
80
|
private
|
|
81
81
|
|
|
82
82
|
def length(value)
|
|
83
|
-
|
|
84
|
-
Unicode.width(value.to_s.gsub(PARSE_REGEX, ''))
|
|
85
|
-
else
|
|
86
|
-
value.to_s.gsub(PARSE_REGEX, '').chars.reduce(0) { |sum, char| sum += char.bytesize > 1 ? 2 : 1 }
|
|
87
|
-
end
|
|
83
|
+
Reline::Unicode.calculate_width(value.to_s.gsub(PARSE_REGEX, ''))
|
|
88
84
|
|
|
89
85
|
rescue NotImplementedError
|
|
90
86
|
value.to_s.gsub(PARSE_REGEX, '').chars.reduce(0) { |sum, char| sum += char.bytesize > 1 ? 2 : 1 }
|
data/lib/formatador.rb
CHANGED
|
@@ -1,60 +1,64 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require File.join(File.dirname(__FILE__), 'formatador', 'table')
|
|
2
4
|
require File.join(File.dirname(__FILE__), 'formatador', 'progressbar')
|
|
3
5
|
|
|
4
|
-
|
|
6
|
+
require 'reline' # for table char width calculations
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
class Formatador
|
|
9
|
+
VERSION = '1.2.3'
|
|
7
10
|
|
|
8
11
|
STYLES = {
|
|
9
|
-
|
|
10
|
-
:
|
|
11
|
-
:
|
|
12
|
-
:
|
|
13
|
-
:
|
|
14
|
-
:
|
|
15
|
-
:
|
|
16
|
-
:
|
|
17
|
-
:
|
|
18
|
-
:
|
|
19
|
-
:
|
|
20
|
-
:
|
|
21
|
-
:
|
|
22
|
-
:
|
|
23
|
-
:
|
|
24
|
-
:
|
|
25
|
-
:
|
|
26
|
-
:
|
|
27
|
-
:
|
|
28
|
-
:
|
|
29
|
-
:
|
|
30
|
-
:
|
|
31
|
-
:
|
|
32
|
-
:
|
|
33
|
-
:
|
|
34
|
-
:
|
|
35
|
-
:
|
|
36
|
-
:
|
|
37
|
-
:
|
|
38
|
-
:
|
|
39
|
-
:
|
|
40
|
-
:
|
|
41
|
-
:
|
|
42
|
-
:
|
|
43
|
-
:
|
|
44
|
-
:
|
|
45
|
-
:
|
|
46
|
-
:
|
|
47
|
-
:
|
|
48
|
-
:
|
|
49
|
-
:
|
|
50
|
-
:
|
|
51
|
-
:
|
|
52
|
-
:
|
|
53
|
-
:
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
12
|
+
"\/": '0',
|
|
13
|
+
reset: '0',
|
|
14
|
+
bold: '1',
|
|
15
|
+
faint: '2',
|
|
16
|
+
underline: '4',
|
|
17
|
+
blink_slow: '5',
|
|
18
|
+
blink_fast: '6',
|
|
19
|
+
negative: '7', # invert color/color
|
|
20
|
+
normal: '22',
|
|
21
|
+
underline_none: '24',
|
|
22
|
+
blink_off: '25',
|
|
23
|
+
positive: '27', # revert color/color
|
|
24
|
+
_black_: '40',
|
|
25
|
+
_red_: '41',
|
|
26
|
+
_green_: '42',
|
|
27
|
+
_yellow_: '43',
|
|
28
|
+
_blue_: '44',
|
|
29
|
+
_magenta_: '45',
|
|
30
|
+
_purple_: '45',
|
|
31
|
+
_cyan_: '46',
|
|
32
|
+
_white_: '47',
|
|
33
|
+
_light_black_: '100',
|
|
34
|
+
_light_red_: '101',
|
|
35
|
+
_light_green_: '102',
|
|
36
|
+
_light_yellow_: '103',
|
|
37
|
+
_light_blue_: '104',
|
|
38
|
+
_light_magenta_: '105',
|
|
39
|
+
_light_purple_: '105',
|
|
40
|
+
_light_cyan_: '106',
|
|
41
|
+
black: '30',
|
|
42
|
+
red: '31',
|
|
43
|
+
green: '32',
|
|
44
|
+
yellow: '33',
|
|
45
|
+
blue: '34',
|
|
46
|
+
magenta: '35',
|
|
47
|
+
purple: '35',
|
|
48
|
+
cyan: '36',
|
|
49
|
+
white: '37',
|
|
50
|
+
light_black: '90',
|
|
51
|
+
light_red: '91',
|
|
52
|
+
light_green: '92',
|
|
53
|
+
light_yellow: '93',
|
|
54
|
+
light_blue: '94',
|
|
55
|
+
light_magenta: '95',
|
|
56
|
+
light_purple: '95',
|
|
57
|
+
light_cyan: '96'
|
|
58
|
+
}.freeze
|
|
59
|
+
|
|
60
|
+
PARSE_REGEX = /\[(#{STYLES.keys.join('|')})\]/ix.freeze
|
|
61
|
+
INDENT_REGEX = /\[indent\]/ix.freeze
|
|
58
62
|
|
|
59
63
|
def initialize
|
|
60
64
|
@indent = 1
|
|
@@ -73,21 +77,21 @@ class Formatador
|
|
|
73
77
|
end
|
|
74
78
|
|
|
75
79
|
def display_lines(lines = [])
|
|
76
|
-
|
|
80
|
+
[*lines].each do |line|
|
|
77
81
|
display_line(line)
|
|
78
82
|
end
|
|
79
83
|
nil
|
|
80
84
|
end
|
|
81
85
|
|
|
82
86
|
def parse(string)
|
|
83
|
-
if
|
|
84
|
-
string.gsub(PARSE_REGEX) { "\e[#{STYLES[
|
|
87
|
+
if color_support
|
|
88
|
+
string.gsub(PARSE_REGEX) { "\e[#{STYLES[::Regexp.last_match(1).to_sym]}m" }.gsub(INDENT_REGEX) { indentation }
|
|
85
89
|
else
|
|
86
90
|
strip(string)
|
|
87
91
|
end
|
|
88
92
|
end
|
|
89
93
|
|
|
90
|
-
def indent
|
|
94
|
+
def indent
|
|
91
95
|
@indent += 1
|
|
92
96
|
yield
|
|
93
97
|
ensure
|
|
@@ -100,7 +104,7 @@ class Formatador
|
|
|
100
104
|
|
|
101
105
|
def redisplay(string = '', width = 120)
|
|
102
106
|
print("\r#{' ' * width}\r")
|
|
103
|
-
display(
|
|
107
|
+
display(string.to_s)
|
|
104
108
|
nil
|
|
105
109
|
end
|
|
106
110
|
|
|
@@ -115,11 +119,17 @@ class Formatador
|
|
|
115
119
|
nil
|
|
116
120
|
end
|
|
117
121
|
|
|
122
|
+
def set_title(title)
|
|
123
|
+
print("\033]0;#{title}\007")
|
|
124
|
+
$stdout.flush
|
|
125
|
+
nil
|
|
126
|
+
end
|
|
127
|
+
|
|
118
128
|
def strip(string)
|
|
119
129
|
string.gsub(PARSE_REGEX, '').gsub(INDENT_REGEX) { indentation }
|
|
120
130
|
end
|
|
121
131
|
|
|
122
|
-
%w
|
|
132
|
+
%w[display display_line display_lines indent parse redisplay redisplay_line new_line redisplay_progressbar set_title].each do |method|
|
|
123
133
|
eval <<-DEF
|
|
124
134
|
def self.#{method}(*args, &block)
|
|
125
135
|
Thread.current[:formatador] ||= new
|
|
@@ -128,7 +138,7 @@ class Formatador
|
|
|
128
138
|
DEF
|
|
129
139
|
end
|
|
130
140
|
|
|
131
|
-
%w
|
|
141
|
+
%w[display_table display_compact_table].each do |method|
|
|
132
142
|
eval <<-DEF
|
|
133
143
|
def self.#{method}(*args, **kwargs, &block)
|
|
134
144
|
Thread.current[:formatador] ||= new
|
|
@@ -137,4 +147,9 @@ class Formatador
|
|
|
137
147
|
DEF
|
|
138
148
|
end
|
|
139
149
|
|
|
150
|
+
private
|
|
151
|
+
|
|
152
|
+
def color_support
|
|
153
|
+
@color_support ||= $stdout.tty? || ENV['GITHUB_ACTIONS'] == 'true'
|
|
154
|
+
end
|
|
140
155
|
end
|
data/tests/table_tests.rb
CHANGED
|
@@ -64,6 +64,16 @@ output = Formatador.parse(output)
|
|
|
64
64
|
end
|
|
65
65
|
end
|
|
66
66
|
|
|
67
|
+
|
|
68
|
+
if (RUBY_VERSION.split('.').map(&:to_i) <=> [3, 4, 0]).positive?
|
|
69
|
+
output = <<-OUTPUT
|
|
70
|
+
+---+----------------+
|
|
71
|
+
| [bold]a[/] | [bold]nested[/] |
|
|
72
|
+
+---+----------------+
|
|
73
|
+
| 1 | {key: "value"} |
|
|
74
|
+
+---+----------------+
|
|
75
|
+
OUTPUT
|
|
76
|
+
else
|
|
67
77
|
output = <<-OUTPUT
|
|
68
78
|
+---+-----------------+
|
|
69
79
|
| [bold]a[/] | [bold]nested[/] |
|
|
@@ -71,6 +81,7 @@ output = <<-OUTPUT
|
|
|
71
81
|
| 1 | {:key=>"value"} |
|
|
72
82
|
+---+-----------------+
|
|
73
83
|
OUTPUT
|
|
84
|
+
end
|
|
74
85
|
output = Formatador.parse(output)
|
|
75
86
|
|
|
76
87
|
tests("#display_table([{:a => 1, :nested => {:key => 'value'}}])").returns(output) do
|
|
@@ -142,4 +153,22 @@ OUTPUT
|
|
|
142
153
|
end
|
|
143
154
|
end
|
|
144
155
|
|
|
156
|
+
output = <<-OUTPUT
|
|
157
|
+
+----+
|
|
158
|
+
| [bold]a[/] |
|
|
159
|
+
+----+
|
|
160
|
+
| 1 |
|
|
161
|
+
+----+
|
|
162
|
+
| 🤷 |
|
|
163
|
+
+----+
|
|
164
|
+
OUTPUT
|
|
165
|
+
output = Formatador.parse(output)
|
|
166
|
+
|
|
167
|
+
tests("#display_table([{:a => 1}, {:a => '🤷'}])").returns(output) do
|
|
168
|
+
capture_stdout do
|
|
169
|
+
Formatador.display_table([{:a => 1}, {:a => '🤷'}])
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
|
|
145
174
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: formatador
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- geemus (Wesley Beary)
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-11-10 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: reline
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
13
26
|
- !ruby/object:Gem::Dependency
|
|
14
27
|
name: rake
|
|
15
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -65,6 +78,7 @@ files:
|
|
|
65
78
|
- LICENSE.md
|
|
66
79
|
- README.md
|
|
67
80
|
- Rakefile
|
|
81
|
+
- SECURITY.md
|
|
68
82
|
- changelog.txt
|
|
69
83
|
- formatador.gemspec
|
|
70
84
|
- lib/formatador.rb
|
|
@@ -77,7 +91,6 @@ homepage: https://github.com/geemus/formatador
|
|
|
77
91
|
licenses:
|
|
78
92
|
- MIT
|
|
79
93
|
metadata: {}
|
|
80
|
-
post_install_message:
|
|
81
94
|
rdoc_options:
|
|
82
95
|
- "--charset=UTF-8"
|
|
83
96
|
require_paths:
|
|
@@ -93,8 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
93
106
|
- !ruby/object:Gem::Version
|
|
94
107
|
version: '0'
|
|
95
108
|
requirements: []
|
|
96
|
-
rubygems_version: 3.
|
|
97
|
-
signing_key:
|
|
109
|
+
rubygems_version: 3.6.9
|
|
98
110
|
specification_version: 2
|
|
99
111
|
summary: Ruby STDOUT text formatting
|
|
100
112
|
test_files: []
|