term-ansicolor 1.9.0 → 1.10.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: f94f19feae65e9ff5aa9c4f79126eca941c7f824b2aa6fcb62dad77a2ef7e6d7
4
- data.tar.gz: 0a94fdc003d7876d96b10e77170987786fccfa6013da118376c6b8ccf92fd876
3
+ metadata.gz: 1b4b022358ec0c08c813fd02b38a04f434d49fcd75db660e25b8fe99a7b1e847
4
+ data.tar.gz: a829c2406f9a20c5738297253bcf3e3dc46f497fbb0c3433bef01fa488cd9c10
5
5
  SHA512:
6
- metadata.gz: 6e5742e8fb06c4cbfcdd065619cc0b0a4af060f0708facb67190833e7a5f1d95a51fc0844e2e532d9d67332d2e419944c144116f9c82b363f1c4b387deb6dc3e
7
- data.tar.gz: 8114385cec7788c819cfd1b70ebb8934afd4c7fd7bf68f85f5986869c840f7992e96c426c80b3debd864309211d3ad02c736a696be38b78fed6d8eff4777bd5b
6
+ metadata.gz: 1ee33e17663543ec540ae88b5e84ff8ea6651394d62fe71086258f1294e556180c3255a3f2615dba39f54ab712927b5d862607995e41e7a86cbd43e3ffc89230
7
+ data.tar.gz: b17b3b732562f3132f478d01c6ba8b96ae9c158d50ad0ca147c722ddc232125301d911574996e023a4e25696ef574bfce986df05b5a487bd43fb5d82fb6ba4ae
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ GemHadar do
21
21
  executables.merge Dir['bin/*'].map { |x| File.basename(x) }
22
22
 
23
23
  dependency 'tins', '~>1.0'
24
+ dependency 'mize'
24
25
  development_dependency 'simplecov'
25
26
  development_dependency 'test-unit'
26
27
  development_dependency 'utils'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.0
1
+ 1.10.0
data/bin/term_colortab CHANGED
@@ -66,10 +66,10 @@ for c in 16..231
66
66
  (c - 16) % 36 == 0 and puts
67
67
  print_color c
68
68
  end
69
+ puts
69
70
 
70
71
  for c in 232..255
71
72
  (c - 16) % 6 == 0 and puts
72
- (c - 16) % 12 == 0 and puts
73
73
  print_color c
74
74
  end
75
75
  puts
data/examples/example.rb CHANGED
@@ -76,7 +76,7 @@ print "clear".clear, "reset".reset, "bold".bold, "dark".dark,
76
76
 
77
77
  symbols = Term::ANSIColor::attributes
78
78
  print red { bold { "All supported attributes = " } },
79
- symbols.map { |s| __send__(s, s.inspect) } * ', ', "\n\n"
79
+ symbols.map { |s| __send__(s, s.inspect) } * ",\n", "\n\n"
80
80
 
81
81
  print "Send symbols to strings:".send(:red).send(:bold), "\n"
82
82
  print symbols[12, 8].map { |c| c.to_s.send(c) } * '', "\n\n"
@@ -2,65 +2,67 @@ module Term
2
2
  module ANSIColor
3
3
  class Attribute
4
4
  class Color256
5
- Attribute.set :color0, 0, :html => '#000000'
6
- Attribute.set :color1, 1, :html => '#800000'
7
- Attribute.set :color2, 2, :html => '#808000'
8
- Attribute.set :color3, 3, :html => '#808000'
9
- Attribute.set :color4, 4, :html => '#000080'
10
- Attribute.set :color5, 5, :html => '#800080'
11
- Attribute.set :color6, 6, :html => '#008080'
12
- Attribute.set :color7, 7, :html => '#c0c0c0'
5
+ Attribute.set :color0, 0, html: '#000000'
6
+ Attribute.set :color1, 1, html: '#800000'
7
+ Attribute.set :color2, 2, html: '#808000'
8
+ Attribute.set :color3, 3, html: '#808000'
9
+ Attribute.set :color4, 4, html: '#000080'
10
+ Attribute.set :color5, 5, html: '#800080'
11
+ Attribute.set :color6, 6, html: '#008080'
12
+ Attribute.set :color7, 7, html: '#c0c0c0'
13
13
 
14
- Attribute.set :color8, 8, :html => '#808080'
15
- Attribute.set :color9, 9, :html => '#ff0000'
16
- Attribute.set :color10, 10, :html => '#00ff00'
17
- Attribute.set :color11, 11, :html => '#ffff00'
18
- Attribute.set :color12, 12, :html => '#0000ff'
19
- Attribute.set :color13, 13, :html => '#ff00ff'
20
- Attribute.set :color14, 14, :html => '#00ffff'
21
- Attribute.set :color15, 15, :html => '#ffffff'
14
+ Attribute.set :color8, 8, html: '#808080'
15
+ Attribute.set :color9, 9, html: '#ff0000'
16
+ Attribute.set :color10, 10, html: '#00ff00'
17
+ Attribute.set :color11, 11, html: '#ffff00'
18
+ Attribute.set :color12, 12, html: '#0000ff'
19
+ Attribute.set :color13, 13, html: '#ff00ff'
20
+ Attribute.set :color14, 14, html: '#00ffff'
21
+ Attribute.set :color15, 15, html: '#ffffff'
22
22
 
23
23
  steps = [ 0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff ]
24
24
 
25
25
  for i in 16..231
26
26
  red, green, blue = (i - 16).to_s(6).rjust(3, '0').each_char.map { |c| steps[c.to_i] }
27
- Attribute.set "color#{i}", i, :red => red, :green => green, :blue => blue
27
+ Attribute.set "color#{i}", i, red: red, green: green, blue: blue
28
28
  end
29
29
 
30
30
  grey = 8
31
31
  for i in 232..255
32
- Attribute.set "color#{i}", i, :red => grey, :green => grey, :blue => grey
32
+ Attribute.set "color#{i}", i, red: grey, green: grey, blue: grey
33
33
  grey += 10
34
34
  end
35
35
 
36
- Attribute.set :on_color0, 0, :html => '#000000'
37
- Attribute.set :on_color1, 1, :html => '#800000'
38
- Attribute.set :on_color2, 2, :html => '#808000'
39
- Attribute.set :on_color3, 3, :html => '#808000'
40
- Attribute.set :on_color4, 4, :html => '#000080'
41
- Attribute.set :on_color5, 5, :html => '#800080'
42
- Attribute.set :on_color6, 6, :html => '#008080'
43
- Attribute.set :on_color7, 7, :html => '#c0c0c0'
36
+ Attribute.set :on_color0, 0, html: '#000000', background: true
37
+ Attribute.set :on_color1, 1, html: '#800000', background: true
38
+ Attribute.set :on_color2, 2, html: '#808000', background: true
39
+ Attribute.set :on_color3, 3, html: '#808000', background: true
40
+ Attribute.set :on_color4, 4, html: '#000080', background: true
41
+ Attribute.set :on_color5, 5, html: '#800080', background: true
42
+ Attribute.set :on_color6, 6, html: '#008080', background: true
43
+ Attribute.set :on_color7, 7, html: '#c0c0c0'
44
44
 
45
- Attribute.set :on_color8, 8, :html => '#808080'
46
- Attribute.set :on_color9, 9, :html => '#ff0000'
47
- Attribute.set :on_color10, 10, :html => '#00ff00'
48
- Attribute.set :on_color11, 11, :html => '#ffff00'
49
- Attribute.set :on_color12, 12, :html => '#0000ff'
50
- Attribute.set :on_color13, 13, :html => '#ff00ff'
51
- Attribute.set :on_color14, 14, :html => '#00ffff'
52
- Attribute.set :on_color15, 15, :html => '#ffffff'
45
+ Attribute.set :on_color8, 8, html: '#808080', background: true
46
+ Attribute.set :on_color9, 9, html: '#ff0000', background: true
47
+ Attribute.set :on_color10, 10, html: '#00ff00', background: true
48
+ Attribute.set :on_color11, 11, html: '#ffff00', background: true
49
+ Attribute.set :on_color12, 12, html: '#0000ff', background: true
50
+ Attribute.set :on_color13, 13, html: '#ff00ff', background: true
51
+ Attribute.set :on_color14, 14, html: '#00ffff', background: true
52
+ Attribute.set :on_color15, 15, html: '#ffffff', background: true
53
53
 
54
54
  steps = [ 0x00, 0x5f, 0x87, 0xaf, 0xd7, 0xff ]
55
55
 
56
56
  for i in 16..231
57
57
  red, green, blue = (i - 16).to_s(6).rjust(3, '0').each_char.map { |c| steps[c.to_i] }
58
- Attribute.set "on_color#{i}", i, :red => red, :green => green, :blue => blue
58
+ Attribute.set "on_color#{i}", i,
59
+ red: red, green: green, blue: blue, background: true
59
60
  end
60
61
 
61
62
  grey = 8
62
63
  for i in 232..255
63
- Attribute.set "on_color#{i}", i, :red => grey, :green => grey, :blue => grey
64
+ Attribute.set "on_color#{i}", i,
65
+ red: grey, green: grey, blue: grey, background: true
64
66
  grey += 10
65
67
  end
66
68
  end
@@ -2,23 +2,23 @@ module Term
2
2
  module ANSIColor
3
3
  class Attribute
4
4
  class Color8
5
- Attribute.set :black, 30
6
- Attribute.set :red, 31
7
- Attribute.set :green, 32
8
- Attribute.set :yellow, 33
9
- Attribute.set :blue, 34
10
- Attribute.set :magenta, 35
11
- Attribute.set :cyan, 36
12
- Attribute.set :white, 37
5
+ Attribute.set :black, 30, color8: '#000000'
6
+ Attribute.set :red, 31, color8: '#800000'
7
+ Attribute.set :green, 32, color8: '#008000'
8
+ Attribute.set :yellow, 33, color8: '#808000'
9
+ Attribute.set :blue, 34, color8: '#000080'
10
+ Attribute.set :magenta, 35, color8: '#800080'
11
+ Attribute.set :cyan, 36, color8: '#008080'
12
+ Attribute.set :white, 37, color8: '#c0c0c0'
13
13
 
14
- Attribute.set :on_black, 40
15
- Attribute.set :on_red, 41
16
- Attribute.set :on_green, 42
17
- Attribute.set :on_yellow, 43
18
- Attribute.set :on_blue, 44
19
- Attribute.set :on_magenta, 45
20
- Attribute.set :on_cyan, 46
21
- Attribute.set :on_white, 47
14
+ Attribute.set :on_black, 40, color8: '#000000'
15
+ Attribute.set :on_red, 41, color8: '#800000'
16
+ Attribute.set :on_green, 42, color8: '#008000'
17
+ Attribute.set :on_yellow, 43, color8: '#808000'
18
+ Attribute.set :on_blue, 44, color8: '#000080'
19
+ Attribute.set :on_magenta, 45, color8: '#800080'
20
+ Attribute.set :on_cyan, 46, color8: '#008080'
21
+ Attribute.set :on_white, 47, color8: '#808080'
22
22
  end
23
23
  end
24
24
  end
@@ -1,22 +1,25 @@
1
+ require 'term/ansicolor/attribute/underline'
2
+
1
3
  module Term
2
4
  module ANSIColor
3
5
  class Attribute
4
6
  class Text
5
- Attribute.set :clear, 0 # String#clear already used in String
6
- Attribute.set :reset, 0 # synonym for :clear
7
- Attribute.set :bold, 1
8
- Attribute.set :dark, 2
9
- Attribute.set :faint, 2
10
- Attribute.set :italic, 3 # not widely implemented
11
- Attribute.set :underline, 4
12
- Attribute.set :underscore, 4 # synonym for :underline
13
- Attribute.set :blink, 5
14
- Attribute.set :rapid_blink, 6 # not widely implemented
15
- Attribute.set :reverse, 7 # String#reverse already used in String
16
- Attribute.set :negative, 7 # synonym for :reverse
17
- Attribute.set :concealed, 8
18
- Attribute.set :conceal, 8 # synonym for :concealed
19
- Attribute.set :strikethrough, 9 # not widely implemented
7
+ Attribute.set :clear, 0 # String#clear already used in String
8
+ Attribute.set :reset, 0 # synonym for :clear
9
+ Attribute.set :bold, 1
10
+ Attribute.set :dark, 2
11
+ Attribute.set :faint, 2
12
+ Attribute.set :italic, 3 # not widely implemented
13
+ Attribute.set :blink, 5
14
+ Attribute.set :rapid_blink, 6 # not widely implemented
15
+ Attribute.set :reverse, 7 # String#reverse already used in String
16
+ Attribute.set :negative, 7 # synonym for :reverse
17
+ Attribute.set :concealed, 8
18
+ Attribute.set :conceal, 8 # synonym for :concealed
19
+ Attribute.set :strikethrough, 9 # not widely implemented
20
+ Attribute.set :overline, 53
21
+
22
+ include Term::ANSIColor::Attribute::Underline
20
23
  end
21
24
  end
22
25
  end
@@ -0,0 +1,34 @@
1
+ module Term
2
+ module ANSIColor
3
+ class Attribute
4
+ module Underline
5
+ Attribute.set :underline, 4, skip_definition: true
6
+ Attribute.set :underscore, 4, skip_definition: true # synonym for :underline
7
+
8
+ def underline(string = nil, color: nil, type: nil, &block)
9
+ code = {
10
+ nil => 4,
11
+ default: '4:1',
12
+ double: '4:2',
13
+ curly: '4:3',
14
+ dotted: '4:4',
15
+ dashed: '4:5',
16
+ }.fetch(type) { raise ArgumentError, "invalid line type" }
17
+ if color
18
+ a = Term::ANSIColor::Attribute[color]
19
+ color_code =
20
+ if a.true_color? || a.rgb_color? || a.color8?
21
+ color_code = "\e[58;2;#{a.rgb.to_a * ?;}"
22
+ else
23
+ raise ArgumentError, "invalid color #{a.name.inspect}"
24
+ end
25
+ code = "#{code}m#{color_code}"
26
+ end
27
+ apply_code(code, string, &block)
28
+ end
29
+
30
+ alias underscore underline
31
+ end
32
+ end
33
+ end
34
+ end
@@ -3,31 +3,21 @@ module Term
3
3
  class Attribute
4
4
  @__store__ = {}
5
5
 
6
- if RUBY_VERSION < '1.9'
7
- @__order__ = []
8
-
9
- def self.set(name, code, options = {})
10
- name = name.to_sym
11
- result = @__store__[name] = new(name, code, options)
12
- @__order__ << name
13
- @rgb_colors = nil
14
- result
15
- end
16
-
17
- def self.attributes(&block)
18
- @__order__.map { |name| @__store__[name] }
19
- end
20
- else
21
- def self.set(name, code, options = {})
22
- name = name.to_sym
23
- result = @__store__[name] = new(name, code, options)
24
- @rgb_colors = nil
25
- result
6
+ def self.set(name, code, **options)
7
+ name = name.to_sym
8
+ result = @__store__[name] = new(name, code, options)
9
+ unless options[:skip_definition]
10
+ ::Term::ANSIColor.class_eval do
11
+ define_method(name) do |string = nil, &block|
12
+ apply_attribute(name, string, &block)
13
+ end
14
+ end
26
15
  end
16
+ result
17
+ end
27
18
 
28
- def self.attributes(&block)
29
- @__store__.each_value(&block)
30
- end
19
+ def self.attributes(&block)
20
+ @__store__.each_value(&block)
31
21
  end
32
22
 
33
23
  def self.[](name, true_coloring: false)
@@ -60,7 +50,7 @@ module Term
60
50
  end
61
51
 
62
52
  def self.rgb_colors(options = {}, &block)
63
- colors = @rgb_colors ||= attributes.select(&:rgb_color?)
53
+ colors = attributes.select(&:rgb_color?)
64
54
  if options.key?(:gray) && !options[:gray]
65
55
  colors = colors.reject(&:gray?)
66
56
  end
@@ -95,14 +85,18 @@ module Term
95
85
 
96
86
  def initialize(name, code, options = {})
97
87
  @name = name.to_sym
98
- @background = @name.start_with?('on_')
88
+ @background = !!options[:background]
99
89
  @code = code.to_s
90
+ @true_color = false
100
91
  if rgb = options[:true_color]
101
92
  @true_color = true
102
93
  @rgb = rgb
94
+ elsif rgb = options[:color8]
95
+ @color8 = true
96
+ @rgb = RGBTriple.from_html(rgb)
103
97
  elsif html = options[:html]
104
98
  @rgb = RGBTriple.from_html(html)
105
- elsif !options.empty?
99
+ elsif options.slice(:red, :green, :blue).size == 3
106
100
  @rgb = RGBTriple.from_hash(options)
107
101
  else
108
102
  @rgb = nil # prevent instance variable not initialized warnings
@@ -116,25 +110,31 @@ module Term
116
110
  background? ? "48;2;#{@rgb.to_a * ?;}" : "38;2;#{@rgb.to_a * ?;}"
117
111
  elsif rgb_color?
118
112
  background? ? "48;5;#{@code}" : "38;5;#{@code}"
113
+ elsif color8?
114
+ background? ? (@code.to_i + 10).to_s : @code
119
115
  else
120
116
  @code
121
117
  end
122
118
  end
123
119
 
124
120
  def apply(string = nil, &block)
125
- ::Term::ANSIColor.color(self, string, &block)
121
+ ::Term::ANSIColor.apply_attribute(self, string, &block)
126
122
  end
127
123
 
128
124
  def background?
129
125
  !!@background
130
126
  end
131
127
 
128
+ def color8?
129
+ !!@color8
130
+ end
131
+
132
132
  attr_writer :background
133
133
 
134
134
  attr_reader :rgb
135
135
 
136
136
  def rgb_color?
137
- !!@rgb && !@true_color
137
+ !!@rgb && !@true_color && !@color8
138
138
  end
139
139
 
140
140
  def true_color?
@@ -1,6 +1,6 @@
1
1
  module Term::ANSIColor
2
2
  # Term::ANSIColor version
3
- VERSION = '1.9.0'
3
+ VERSION = '1.10.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,4 +1,5 @@
1
1
  require 'tins/xt/full'
2
+ require 'mize'
2
3
 
3
4
  module Term
4
5
 
@@ -18,23 +19,7 @@ module Term
18
19
  include Term::ANSIColor::Movement
19
20
  require 'term/ansicolor/hyperlink'
20
21
  include Term::ANSIColor::Hyperlink
21
-
22
- # :stopdoc:
23
- ATTRIBUTE_NAMES = Attribute.named_attributes.map(&:name)
24
- # :startdoc:
25
-
26
- # Returns true if Term::ANSIColor supports the +feature+.
27
- #
28
- # The feature :clear, that is mixing the clear color attribute into String,
29
- # is only supported on ruby implementations, that do *not* already
30
- # implement the String#clear method. It's better to use the reset color
31
- # attribute instead.
32
- def support?(feature)
33
- case feature
34
- when :clear
35
- !String.instance_methods(false).map(&:to_sym).include?(:clear)
36
- end
37
- end
22
+ include Term::ANSIColor::Attribute::Underline
38
23
 
39
24
  # Returns true, if the coloring function of this module
40
25
  # is switched on, false otherwise.
@@ -64,22 +49,9 @@ module Term
64
49
  end
65
50
  self.true_coloring = false
66
51
 
67
- def self.create_color_method(color_name, color_value)
68
- module_eval <<-EOT
69
- def #{color_name}(string = nil, &block)
70
- color(:#{color_name}, string, &block)
71
- end
72
- EOT
73
- self
74
- end
75
-
76
- for attribute in Attribute.named_attributes
77
- create_color_method(attribute.name, attribute.code)
78
- end
79
-
80
52
  # Regular expression that is used to scan for ANSI-Attributes while
81
53
  # uncoloring strings.
82
- COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9]|[34]8;(5;\d{1,3}|2;\d{1,3}(;\d{1,3}){2}))?m/
54
+ COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9]|[34]8;(5;\d{1,3}|2;\d{1,3}(;\d{1,3}){2})|4:\d|53)?m/
83
55
 
84
56
  # Returns an uncolored version of the string, that is all ANSI-Attributes
85
57
  # are stripped from the string.
@@ -97,13 +69,9 @@ module Term
97
69
 
98
70
  alias uncolored uncolor
99
71
 
100
- # Return +string+ or the result string of the given +block+ colored with
101
- # color +name+. If string isn't a string only the escape sequence to switch
102
- # on the color +name+ is returned.
103
- def color(name, string = nil, &block)
104
- attribute = Attribute[name] or raise ArgumentError, "unknown attribute #{name.inspect}"
72
+ def apply_code(code, string = nil, &block)
105
73
  result = ''
106
- result << "\e[#{attribute.code}m" if Term::ANSIColor.coloring?
74
+ result << "\e[#{code}m" if Term::ANSIColor.coloring?
107
75
  if block_given?
108
76
  result << yield.to_s
109
77
  elsif string.respond_to?(:to_str)
@@ -117,17 +85,34 @@ module Term
117
85
  result.extend(Term::ANSIColor)
118
86
  end
119
87
 
88
+ def apply_attribute(name, string = nil, &block)
89
+ attribute = Attribute[name] or
90
+ raise ArgumentError, "unknown attribute #{name.inspect}"
91
+ apply_code(attribute.code, string, &block)
92
+ end
93
+
94
+ # Return +string+ or the result string of the given +block+ colored with
95
+ # color +name+. If string isn't a string only the escape sequence to switch
96
+ # on the color +name+ is returned.
97
+ def color(name, string = nil, &block)
98
+ apply_attribute(name, string, &block)
99
+ end
100
+
101
+ # Return +string+ or the result string of the given +block+ with a
102
+ # background colored with color +name+. If string isn't a string only the
103
+ # escape sequence to switch on the color +name+ is returned.
120
104
  def on_color(name, string = nil, &block)
121
- attribute = Attribute[name] or raise ArgumentError, "unknown attribute #{name.inspect}"
105
+ attribute = Attribute[name] or
106
+ raise ArgumentError, "unknown attribute #{name.inspect}"
122
107
  attribute = attribute.dup
123
108
  attribute.background = true
124
- color(attribute, string, &block)
109
+ apply_attribute(attribute, string, &block)
125
110
  end
126
111
 
127
112
  class << self
128
113
  # Returns an array of all Term::ANSIColor attributes as symbols.
129
- def term_ansicolor_attributes
130
- ::Term::ANSIColor::ATTRIBUTE_NAMES
114
+ memoize method: def term_ansicolor_attributes
115
+ ::Term::ANSIColor::Attribute.attributes.map(&:name)
131
116
  end
132
117
 
133
118
  alias attributes term_ansicolor_attributes
@@ -1,23 +1,23 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: term-ansicolor 1.9.0 ruby lib
2
+ # stub: term-ansicolor 1.10.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "term-ansicolor".freeze
6
- s.version = "1.9.0".freeze
6
+ s.version = "1.10.0".freeze
7
7
 
8
8
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
9
9
  s.require_paths = ["lib".freeze]
10
10
  s.authors = ["Florian Frank".freeze]
11
- s.date = "2024-06-18"
11
+ s.date = "2024-06-21"
12
12
  s.description = "This library uses ANSI escape sequences to control the attributes of terminal output".freeze
13
13
  s.email = "flori@ping.de".freeze
14
14
  s.executables = ["term_cdiff".freeze, "term_colortab".freeze, "term_decolor".freeze, "term_display".freeze, "term_mandel".freeze, "term_snow".freeze]
15
- s.extra_rdoc_files = ["README.md".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/hsl_triple.rb".freeze, "lib/term/ansicolor/hyperlink.rb".freeze, "lib/term/ansicolor/movement.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze]
16
- s.files = [".all_images.yml".freeze, ".gitignore".freeze, ".tool-versions".freeze, ".utilsrc".freeze, "CHANGES".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/term_cdiff".freeze, "bin/term_colortab".freeze, "bin/term_decolor".freeze, "bin/term_display".freeze, "bin/term_mandel".freeze, "bin/term_snow".freeze, "examples/example.rb".freeze, "examples/lambda-red-plain.ppm".freeze, "examples/lambda-red.png".freeze, "examples/lambda-red.ppm".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/.keep".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/hsl_triple.rb".freeze, "lib/term/ansicolor/hyperlink.rb".freeze, "lib/term/ansicolor/movement.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze, "term-ansicolor.gemspec".freeze, "tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/hsl_triple_test.rb".freeze, "tests/hyperlink_test.rb".freeze, "tests/ppm_reader_test.rb".freeze, "tests/rgb_color_metrics_test.rb".freeze, "tests/rgb_triple_test.rb".freeze, "tests/test_helper.rb".freeze]
15
+ s.extra_rdoc_files = ["README.md".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/attribute/underline.rb".freeze, "lib/term/ansicolor/hsl_triple.rb".freeze, "lib/term/ansicolor/hyperlink.rb".freeze, "lib/term/ansicolor/movement.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze]
16
+ s.files = [".all_images.yml".freeze, ".gitignore".freeze, ".utilsrc".freeze, "CHANGES".freeze, "COPYING".freeze, "Gemfile".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/term_cdiff".freeze, "bin/term_colortab".freeze, "bin/term_decolor".freeze, "bin/term_display".freeze, "bin/term_mandel".freeze, "bin/term_snow".freeze, "examples/example.rb".freeze, "examples/lambda-red-plain.ppm".freeze, "examples/lambda-red.png".freeze, "examples/lambda-red.ppm".freeze, "lib/term/ansicolor.rb".freeze, "lib/term/ansicolor/.keep".freeze, "lib/term/ansicolor/attribute.rb".freeze, "lib/term/ansicolor/attribute/color256.rb".freeze, "lib/term/ansicolor/attribute/color8.rb".freeze, "lib/term/ansicolor/attribute/intense_color8.rb".freeze, "lib/term/ansicolor/attribute/text.rb".freeze, "lib/term/ansicolor/attribute/underline.rb".freeze, "lib/term/ansicolor/hsl_triple.rb".freeze, "lib/term/ansicolor/hyperlink.rb".freeze, "lib/term/ansicolor/movement.rb".freeze, "lib/term/ansicolor/ppm_reader.rb".freeze, "lib/term/ansicolor/rgb_color_metrics.rb".freeze, "lib/term/ansicolor/rgb_triple.rb".freeze, "lib/term/ansicolor/version.rb".freeze, "term-ansicolor.gemspec".freeze, "tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/hsl_triple_test.rb".freeze, "tests/hyperlink_test.rb".freeze, "tests/ppm_reader_test.rb".freeze, "tests/rgb_color_metrics_test.rb".freeze, "tests/rgb_triple_test.rb".freeze, "tests/test_helper.rb".freeze]
17
17
  s.homepage = "https://github.com/flori/term-ansicolor".freeze
18
18
  s.licenses = ["Apache-2.0".freeze]
19
19
  s.rdoc_options = ["--title".freeze, "Term-ansicolor - Ruby library that colors strings using ANSI escape sequences".freeze, "--main".freeze, "README.md".freeze]
20
- s.rubygems_version = "3.5.3".freeze
20
+ s.rubygems_version = "3.5.11".freeze
21
21
  s.summary = "Ruby library that colors strings using ANSI escape sequences".freeze
22
22
  s.test_files = ["tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/hsl_triple_test.rb".freeze, "tests/hyperlink_test.rb".freeze, "tests/ppm_reader_test.rb".freeze, "tests/rgb_color_metrics_test.rb".freeze, "tests/rgb_triple_test.rb".freeze, "tests/test_helper.rb".freeze]
23
23
 
@@ -28,4 +28,5 @@ Gem::Specification.new do |s|
28
28
  s.add_development_dependency(%q<test-unit>.freeze, [">= 0".freeze])
29
29
  s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
30
30
  s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.0".freeze])
31
+ s.add_runtime_dependency(%q<mize>.freeze, [">= 0".freeze])
31
32
  end
@@ -103,9 +103,22 @@ class ANSIColorTest < Test::Unit::TestCase
103
103
 
104
104
  def test_attributes
105
105
  foo = 'foo'
106
- for a in Term::ANSIColor.attributes
106
+ attributes = %i[
107
+ clear reset bold dark faint italic underline underscore
108
+ blink rapid_blink reverse negative concealed conceal strikethrough black
109
+ red green yellow blue magenta cyan white on_black on_red on_green on_yellow
110
+ on_blue on_magenta on_cyan on_white intense_black bright_black intense_red
111
+ bright_red intense_green bright_green intense_yellow bright_yellow
112
+ intense_blue bright_blue intense_magenta bright_magenta intense_cyan
113
+ bright_cyan intense_white bright_white on_intense_black on_bright_black
114
+ on_intense_red on_bright_red on_intense_green on_bright_green
115
+ on_intense_yellow on_bright_yellow on_intense_blue on_bright_blue
116
+ on_intense_magenta on_bright_magenta on_intense_cyan on_bright_cyan
117
+ on_intense_white on_bright_white
118
+ ]
119
+ for a in attributes
107
120
  # skip :clear and :reverse b/c Ruby implements them on string
108
- if a != :clear && a != :reverse || Term::ANSIColor.support?(:clear)
121
+ if a != :clear && a != :reverse
109
122
  refute_equal foo, foo_colored = foo.__send__(a)
110
123
  assert_equal foo, foo_colored.uncolor
111
124
  end
@@ -121,6 +134,36 @@ class ANSIColorTest < Test::Unit::TestCase
121
134
  assert_equal Term::ANSIColor.attributes, 'foo'.attributes
122
135
  end
123
136
 
137
+ def test_underline
138
+ foo = 'foo'
139
+ assert_equal "\e[4mfoo\e[0m", Term::ANSIColor.underline { foo }
140
+ assert_equal "\e[4m\e[58;2;255;135;95mfoo\e[0m", Term::ANSIColor.underline(color: '#ff8040') { foo }
141
+ end
142
+
143
+ def test_underline_double
144
+ foo = 'foo'
145
+ assert_equal "\e[4:2mfoo\e[0m", Term::ANSIColor.underline(type: :double) { foo }
146
+ assert_equal "\e[4:2m\e[58;2;255;135;95mfoo\e[0m", Term::ANSIColor.underline(type: :double, color: '#ff8040') { foo }
147
+ end
148
+
149
+ def test_underline_curly
150
+ foo = 'foo'
151
+ assert_equal "\e[4:3mfoo\e[0m", Term::ANSIColor.underline(type: :curly) { foo }
152
+ assert_equal "\e[4:3m\e[58;2;255;135;95mfoo\e[0m", Term::ANSIColor.underline(type: :curly, color: '#ff8040') { foo }
153
+ end
154
+
155
+ def test_underline_dotted
156
+ foo = 'foo'
157
+ assert_equal "\e[4:4mfoo\e[0m", Term::ANSIColor.underline(type: :dotted) { foo }
158
+ assert_equal "\e[4:4m\e[58;2;255;135;95mfoo\e[0m", Term::ANSIColor.underline(type: :dotted, color: '#ff8040') { foo }
159
+ end
160
+
161
+ def test_underline_dashed
162
+ foo = 'foo'
163
+ assert_equal "\e[4:5mfoo\e[0m", Term::ANSIColor.underline(type: :dashed) { foo }
164
+ assert_equal "\e[4:5m\e[58;2;255;135;95mfoo\e[0m", Term::ANSIColor.underline(type: :dashed, color: '#ff8040') { foo }
165
+ end
166
+
124
167
  def test_move_to
125
168
  string_23_23 = "\e[23;23Hred"
126
169
  assert_equal string_23_23, string.move_to(23, 23)
@@ -32,7 +32,7 @@ class AttributeTest < Test::Unit::TestCase
32
32
  assert_in_delta 250.954, Attribute.get(:color0).distance_to(color), 1e-3
33
33
  color = Attribute.nearest_rgb_color('#0f0')
34
34
  assert_in_delta 255, Attribute.get(:color0).distance_to(color,
35
- :metric => RGBColorMetrics::Euclidean), 1e-3
35
+ metric: RGBColorMetrics::Euclidean), 1e-3
36
36
  assert_equal 1 / 0.0, Attribute.get(:color0).distance_to(nil)
37
37
  end
38
38
 
@@ -40,14 +40,14 @@ class AttributeTest < Test::Unit::TestCase
40
40
  assert_equal Attribute.get(:color0).rgb, Attribute.nearest_rgb_color('#000').rgb
41
41
  assert_equal Attribute.get(:color15).rgb, Attribute.nearest_rgb_color('#ffffff').rgb
42
42
  assert_equal :color248, Attribute.nearest_rgb_color('#aaa').name
43
- assert_equal :color109, Attribute.nearest_rgb_color('#aaa', :gray => false).name
43
+ assert_equal :color109, Attribute.nearest_rgb_color('#aaa', gray: false).name
44
44
  end
45
45
 
46
46
  def test_nearest_rgb_on_color
47
47
  assert_equal Attribute.get(:on_color0).rgb, Attribute.nearest_rgb_on_color('#000').rgb
48
48
  assert_equal Attribute.get(:on_color15).rgb, Attribute.nearest_rgb_on_color('#ffffff').rgb
49
49
  assert_equal :on_color248, Attribute.nearest_rgb_on_color('#aaa').name
50
- assert_equal :on_color109, Attribute.nearest_rgb_on_color('#aaa', :gray => false).name
50
+ assert_equal :on_color109, Attribute.nearest_rgb_on_color('#aaa', gray: false).name
51
51
  end
52
52
 
53
53
  def test_apply
@@ -59,13 +59,13 @@ class AttributeTest < Test::Unit::TestCase
59
59
  def test_gradient
60
60
  g0 = Attribute[:blink].gradient_to Attribute['#30ffaa']
61
61
  assert_equal [], g0
62
- g1 = Attribute['#30ffaa'].gradient_to(Attribute['#ff507f'], :steps => 9)
62
+ g1 = Attribute['#30ffaa'].gradient_to(Attribute['#ff507f'], steps: 9)
63
63
  assert_equal [ :color49, :color49, :color43, :color79, :color108,
64
64
  :color247, :color138, :color168, :color204 ], g1.map(&:name)
65
65
  g2 = Attribute['#30ffaa'].gradient_to(
66
66
  Attribute['#ff507f'],
67
- :steps => 9,
68
- :metric => RGBColorMetrics::Euclidean
67
+ steps: 9,
68
+ metric: RGBColorMetrics::Euclidean
69
69
  )
70
70
  assert_equal [ :color49, :color43, :color79, :color73, :color108,
71
71
  :color247, :color138, :color168, :color204 ], g2.map(&:name)
@@ -93,7 +93,7 @@ class AttributeTest < Test::Unit::TestCase
93
93
  assert_equal [], g0
94
94
  g1 = Attribute['#30ffaa'].gradient_to(
95
95
  Attribute['#ff507f'],
96
- :steps => 9,
96
+ steps: 9,
97
97
  true_coloring: true
98
98
  )
99
99
  assert_equal %w[
@@ -101,9 +101,9 @@ class AttributeTest < Test::Unit::TestCase
101
101
  ], g1.map { _1.rgb.html }
102
102
  g2 = Attribute['#30ffaa'].gradient_to(
103
103
  Attribute['#ff507f'],
104
- :steps => 9,
104
+ steps: 9,
105
105
  true_coloring: true,
106
- :metric => RGBColorMetrics::Euclidean
106
+ metric: RGBColorMetrics::Euclidean
107
107
  )
108
108
  assert_equal %w[
109
109
  #00ffaf #1febaa #3ed7a5 #5dc3a0 #7caf9b #9b9b96 #ba8791 #d9738c #ff5f87
@@ -13,7 +13,7 @@ class HSLTripleTest < Test::Unit::TestCase
13
13
 
14
14
  def test_hsl_cast
15
15
  assert_equal '#85e085', HSLTriple[ @pastel_green_hsl ].html
16
- assert_equal '#85e085', HSLTriple[ :hue => 120, :saturation => 59.4, :lightness => 70 ].html
16
+ assert_equal '#85e085', HSLTriple[ hue: 120, saturation: 59.4, lightness: 70 ].html
17
17
  assert_equal '#11ddff', HSLTriple[ '#1df' ].html
18
18
  assert_equal '#8000ff', HSLTriple[ 'rgb(128,0,255)' ].html
19
19
  assert_equal '#85e085', HSLTriple[ 'hsl(120.0,59.4%,70.0%)' ].html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: term-ansicolor
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
4
+ version: 1.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-18 00:00:00.000000000 Z
11
+ date: 2024-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mize
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: This library uses ANSI escape sequences to control the attributes of
84
98
  terminal output
85
99
  email: flori@ping.de
@@ -99,6 +113,7 @@ extra_rdoc_files:
99
113
  - lib/term/ansicolor/attribute/color8.rb
100
114
  - lib/term/ansicolor/attribute/intense_color8.rb
101
115
  - lib/term/ansicolor/attribute/text.rb
116
+ - lib/term/ansicolor/attribute/underline.rb
102
117
  - lib/term/ansicolor/hsl_triple.rb
103
118
  - lib/term/ansicolor/hyperlink.rb
104
119
  - lib/term/ansicolor/movement.rb
@@ -109,7 +124,6 @@ extra_rdoc_files:
109
124
  files:
110
125
  - ".all_images.yml"
111
126
  - ".gitignore"
112
- - ".tool-versions"
113
127
  - ".utilsrc"
114
128
  - CHANGES
115
129
  - COPYING
@@ -134,6 +148,7 @@ files:
134
148
  - lib/term/ansicolor/attribute/color8.rb
135
149
  - lib/term/ansicolor/attribute/intense_color8.rb
136
150
  - lib/term/ansicolor/attribute/text.rb
151
+ - lib/term/ansicolor/attribute/underline.rb
137
152
  - lib/term/ansicolor/hsl_triple.rb
138
153
  - lib/term/ansicolor/hyperlink.rb
139
154
  - lib/term/ansicolor/movement.rb
@@ -173,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
188
  - !ruby/object:Gem::Version
174
189
  version: '0'
175
190
  requirements: []
176
- rubygems_version: 3.5.3
191
+ rubygems_version: 3.5.11
177
192
  signing_key:
178
193
  specification_version: 4
179
194
  summary: Ruby library that colors strings using ANSI escape sequences
data/.tool-versions DELETED
@@ -1 +0,0 @@
1
- ruby 3.3.0