formatador 1.2.0 → 1.2.1

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: cf29b39c71a7f045ff085d5a31127c714b96e2c59b8fbaebff931084a1499a4d
4
- data.tar.gz: 4b165f7014636a0e333c2140fb89667d9203862d960f1fc7f91ca6d8087cb929
3
+ metadata.gz: 907613ddcc1485d890419b8198c117fb441e02e487e61371f50bd455d8aca4a1
4
+ data.tar.gz: 9f8ad9ea1d10ad47831a6132328aaf7d4cb80e87eb21bcc1f42fda5f0dd81a2a
5
5
  SHA512:
6
- metadata.gz: 611aebde13dcc7ce85d0f9033bcd42519d19a94ea6427aacf4f43c5800ecc2d655660fa5de146e4acd0c3106dc9f383def09d57ca4dcdbd6016bbc5831cd2411
7
- data.tar.gz: 5ba6a7f4bb3fb80e95c8b941ad12f2d937819b65cfa651d985bc080affe30723447309bb5ce0c1baf02777f70e849ba3108ed60d6f22c1e75cf0db3fcb92306c
6
+ metadata.gz: 1aaf1339006a7791ccdd9941e21d7b28ab993e528c463aaf089014cbcc88e9861f6fc5aef9b8654d8cce3fbefd81be949b4dc3f20dcd0a5731030345ea3d7ecf
7
+ data.tar.gz: 8f4026b8a0d35a4ba1eae4eff98d45cff61edc498d6378cf5dc10d86b1b04677669541096bf67a29883eb6306a53af6ba2c23f9b4134b4ad8cfa5526df90adfb
data/changelog.txt CHANGED
@@ -1,3 +1,9 @@
1
+ v1.2.1 09/17/25
2
+ ===============
3
+
4
+ add color output support for github actions
5
+ fix most lints
6
+
1
7
  v1.2.0 08/08/25
2
8
  ===============
3
9
 
data/formatador.gemspec CHANGED
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
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.0'
17
- s.date = '2025-08-08'
16
+ s.version = '1.2.1'
17
+ s.date = '2025-09-17'
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,63 @@
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.1'
9
10
 
10
11
  STYLES = {
11
- :"\/" => "0",
12
- :reset => "0",
13
- :bold => "1",
14
- :underline => "4",
15
- :blink_slow => "5",
16
- :blink_fast => "6",
17
- :negative => "7", # invert color/color
18
- :normal => "22",
19
- :underline_none => "24",
20
- :blink_off => "25",
21
- :positive => "27", # revert color/color
22
- :_black_ => "40",
23
- :_red_ => "41",
24
- :_green_ => "42",
25
- :_yellow_ => "43",
26
- :_blue_ => "44",
27
- :_magenta_ => "45",
28
- :_purple_ => "45",
29
- :_cyan_ => "46",
30
- :_white_ => "47",
31
- :_light_black_ => "100",
32
- :_light_red_ => "101",
33
- :_light_green_ => "102",
34
- :_light_yellow_ => "103",
35
- :_light_blue_ => "104",
36
- :_light_magenta_ => "105",
37
- :_light_purple_ => "105",
38
- :_light_cyan_ => "106",
39
- :black => "30",
40
- :red => "31",
41
- :green => "32",
42
- :yellow => "33",
43
- :blue => "34",
44
- :magenta => "35",
45
- :purple => "35",
46
- :cyan => "36",
47
- :white => "37",
48
- :light_black => "90",
49
- :light_red => "91",
50
- :light_green => "92",
51
- :light_yellow => "93",
52
- :light_blue => "94",
53
- :light_magenta => "95",
54
- :light_purple => "95",
55
- :light_cyan => "96",
56
- }
57
-
58
- PARSE_REGEX = /\[(#{ STYLES.keys.join('|') })\]/ix
59
- INDENT_REGEX = /\[indent\]/ix
12
+ "\/": '0',
13
+ reset: '0',
14
+ bold: '1',
15
+ underline: '4',
16
+ blink_slow: '5',
17
+ blink_fast: '6',
18
+ negative: '7', # invert color/color
19
+ normal: '22',
20
+ underline_none: '24',
21
+ blink_off: '25',
22
+ positive: '27', # revert color/color
23
+ _black_: '40',
24
+ _red_: '41',
25
+ _green_: '42',
26
+ _yellow_: '43',
27
+ _blue_: '44',
28
+ _magenta_: '45',
29
+ _purple_: '45',
30
+ _cyan_: '46',
31
+ _white_: '47',
32
+ _light_black_: '100',
33
+ _light_red_: '101',
34
+ _light_green_: '102',
35
+ _light_yellow_: '103',
36
+ _light_blue_: '104',
37
+ _light_magenta_: '105',
38
+ _light_purple_: '105',
39
+ _light_cyan_: '106',
40
+ black: '30',
41
+ red: '31',
42
+ green: '32',
43
+ yellow: '33',
44
+ blue: '34',
45
+ magenta: '35',
46
+ purple: '35',
47
+ cyan: '36',
48
+ white: '37',
49
+ light_black: '90',
50
+ light_red: '91',
51
+ light_green: '92',
52
+ light_yellow: '93',
53
+ light_blue: '94',
54
+ light_magenta: '95',
55
+ light_purple: '95',
56
+ light_cyan: '96'
57
+ }.freeze
58
+
59
+ PARSE_REGEX = /\[(#{STYLES.keys.join('|')})\]/ix.freeze
60
+ INDENT_REGEX = /\[indent\]/ix.freeze
60
61
 
61
62
  def initialize
62
63
  @indent = 1
@@ -75,21 +76,21 @@ class Formatador
75
76
  end
76
77
 
77
78
  def display_lines(lines = [])
78
- for line in [*lines]
79
+ [*lines].each do |line|
79
80
  display_line(line)
80
81
  end
81
82
  nil
82
83
  end
83
84
 
84
85
  def parse(string)
85
- if $stdout.tty?
86
- string.gsub(PARSE_REGEX) { "\e[#{STYLES[$1.to_sym]}m" }.gsub(INDENT_REGEX) { indentation }
86
+ if color_support
87
+ string.gsub(PARSE_REGEX) { "\e[#{STYLES[::Regexp.last_match(1).to_sym]}m" }.gsub(INDENT_REGEX) { indentation }
87
88
  else
88
89
  strip(string)
89
90
  end
90
91
  end
91
92
 
92
- def indent(&block)
93
+ def indent
93
94
  @indent += 1
94
95
  yield
95
96
  ensure
@@ -102,7 +103,7 @@ class Formatador
102
103
 
103
104
  def redisplay(string = '', width = 120)
104
105
  print("\r#{' ' * width}\r")
105
- display("#{string}")
106
+ display(string.to_s)
106
107
  nil
107
108
  end
108
109
 
@@ -121,7 +122,7 @@ class Formatador
121
122
  string.gsub(PARSE_REGEX, '').gsub(INDENT_REGEX) { indentation }
122
123
  end
123
124
 
124
- %w{display display_line display_lines indent parse redisplay redisplay_line new_line redisplay_progressbar}.each do |method|
125
+ %w[display display_line display_lines indent parse redisplay redisplay_line new_line redisplay_progressbar].each do |method|
125
126
  eval <<-DEF
126
127
  def self.#{method}(*args, &block)
127
128
  Thread.current[:formatador] ||= new
@@ -130,7 +131,7 @@ class Formatador
130
131
  DEF
131
132
  end
132
133
 
133
- %w{display_table display_compact_table}.each do |method|
134
+ %w[display_table display_compact_table].each do |method|
134
135
  eval <<-DEF
135
136
  def self.#{method}(*args, **kwargs, &block)
136
137
  Thread.current[:formatador] ||= new
@@ -139,4 +140,9 @@ class Formatador
139
140
  DEF
140
141
  end
141
142
 
143
+ private
144
+
145
+ def color_support
146
+ @color_support ||= $stdout.tty? || ENV['GITHUB_ACTIONS'] == 'true'
147
+ end
142
148
  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.0
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - geemus (Wesley Beary)
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-08 00:00:00.000000000 Z
10
+ date: 2025-09-17 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.7.1
109
+ rubygems_version: 3.6.9
110
110
  specification_version: 2
111
111
  summary: Ruby STDOUT text formatting
112
112
  test_files: []