formatador 1.2.0 → 1.2.2
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/changelog.txt +11 -0
- data/formatador.gemspec +3 -3
- data/lib/formatador.rb +65 -58
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 979f3f1634d89f9407a8409589b9d6a1d8edff7684851b0990c520fa89c92019
|
|
4
|
+
data.tar.gz: d976da618e69016c3d567f7b8ace3619e14effd3ec85b15a45e69481499a7a0d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 408843aac667785e14869ef4acc64905803490337b654b15c3f7609fde0c10f8f0afa4aaef2194731a3cc3111865ca12f4b3539f511b9bfed63f2e8a7278f7d5
|
|
7
|
+
data.tar.gz: 793ea9a1eb0b08cb7623de23184be9b1c687331e65340efc0502fe9b08ba5e9c44f66d881c5a321e27ed5136c9bf11079568bda228cf2d98f9a8552f6223083b
|
data/changelog.txt
CHANGED
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.2.
|
|
17
|
-
s.date = '2025-
|
|
16
|
+
s.version = '1.2.2'
|
|
17
|
+
s.date = '2025-10-28'
|
|
18
18
|
|
|
19
19
|
## Make sure your summary is short. The description may be as long
|
|
20
20
|
## as you like.
|
data/lib/formatador.rb
CHANGED
|
@@ -1,62 +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
|
|
7
|
-
|
|
8
|
-
VERSION = '1.2.0'
|
|
9
|
+
VERSION = '1.2.2'
|
|
9
10
|
|
|
10
11
|
STYLES = {
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
|
60
62
|
|
|
61
63
|
def initialize
|
|
62
64
|
@indent = 1
|
|
@@ -75,21 +77,21 @@ class Formatador
|
|
|
75
77
|
end
|
|
76
78
|
|
|
77
79
|
def display_lines(lines = [])
|
|
78
|
-
|
|
80
|
+
[*lines].each do |line|
|
|
79
81
|
display_line(line)
|
|
80
82
|
end
|
|
81
83
|
nil
|
|
82
84
|
end
|
|
83
85
|
|
|
84
86
|
def parse(string)
|
|
85
|
-
if
|
|
86
|
-
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 }
|
|
87
89
|
else
|
|
88
90
|
strip(string)
|
|
89
91
|
end
|
|
90
92
|
end
|
|
91
93
|
|
|
92
|
-
def indent
|
|
94
|
+
def indent
|
|
93
95
|
@indent += 1
|
|
94
96
|
yield
|
|
95
97
|
ensure
|
|
@@ -102,7 +104,7 @@ class Formatador
|
|
|
102
104
|
|
|
103
105
|
def redisplay(string = '', width = 120)
|
|
104
106
|
print("\r#{' ' * width}\r")
|
|
105
|
-
display(
|
|
107
|
+
display(string.to_s)
|
|
106
108
|
nil
|
|
107
109
|
end
|
|
108
110
|
|
|
@@ -121,7 +123,7 @@ class Formatador
|
|
|
121
123
|
string.gsub(PARSE_REGEX, '').gsub(INDENT_REGEX) { indentation }
|
|
122
124
|
end
|
|
123
125
|
|
|
124
|
-
%w
|
|
126
|
+
%w[display display_line display_lines indent parse redisplay redisplay_line new_line redisplay_progressbar].each do |method|
|
|
125
127
|
eval <<-DEF
|
|
126
128
|
def self.#{method}(*args, &block)
|
|
127
129
|
Thread.current[:formatador] ||= new
|
|
@@ -130,7 +132,7 @@ class Formatador
|
|
|
130
132
|
DEF
|
|
131
133
|
end
|
|
132
134
|
|
|
133
|
-
%w
|
|
135
|
+
%w[display_table display_compact_table].each do |method|
|
|
134
136
|
eval <<-DEF
|
|
135
137
|
def self.#{method}(*args, **kwargs, &block)
|
|
136
138
|
Thread.current[:formatador] ||= new
|
|
@@ -139,4 +141,9 @@ class Formatador
|
|
|
139
141
|
DEF
|
|
140
142
|
end
|
|
141
143
|
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
def color_support
|
|
147
|
+
@color_support ||= $stdout.tty? || ENV['GITHUB_ACTIONS'] == 'true'
|
|
148
|
+
end
|
|
142
149
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: formatador
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.2.
|
|
4
|
+
version: 1.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- geemus (Wesley Beary)
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2025-
|
|
10
|
+
date: 2025-10-28 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: reline
|
|
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
106
106
|
- !ruby/object:Gem::Version
|
|
107
107
|
version: '0'
|
|
108
108
|
requirements: []
|
|
109
|
-
rubygems_version: 3.
|
|
109
|
+
rubygems_version: 3.6.9
|
|
110
110
|
specification_version: 2
|
|
111
111
|
summary: Ruby STDOUT text formatting
|
|
112
112
|
test_files: []
|