term-ansicolor 1.7.2 → 1.9.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: 45d5c44dfe80380872b30c025fbbdb6da398482fce8adf8cbdb6353d81b6ca61
4
- data.tar.gz: eed4f4cb1203e4ced32f053125e668ce6e9ffcca589b177cabcb40a675cc6e14
3
+ metadata.gz: f94f19feae65e9ff5aa9c4f79126eca941c7f824b2aa6fcb62dad77a2ef7e6d7
4
+ data.tar.gz: 0a94fdc003d7876d96b10e77170987786fccfa6013da118376c6b8ccf92fd876
5
5
  SHA512:
6
- metadata.gz: 85098f326b4e01c3d3e0ae17dfcf00d3b76897625d5db09de1ca7c172b140b1250b05f98578a8534caf21032f24949a8a9ab81912d2d819a85aad4024c91b097
7
- data.tar.gz: 23af07f3f3652f7867adab58eb360ed8f5d2adae614508ac92877d8aa6fbfd7e5a31501eb4dcb29f3ce0971f80e22b18a8667759d6d5dc78a30ef25abfcc3e53
6
+ metadata.gz: 6e5742e8fb06c4cbfcdd065619cc0b0a4af060f0708facb67190833e7a5f1d95a51fc0844e2e532d9d67332d2e419944c144116f9c82b363f1c4b387deb6dc3e
7
+ data.tar.gz: 8114385cec7788c819cfd1b70ebb8934afd4c7fd7bf68f85f5986869c840f7992e96c426c80b3debd864309211d3ad02c736a696be38b78fed6d8eff4777bd5b
data/.all_images.yml CHANGED
@@ -11,6 +11,7 @@ script: &script |-
11
11
  rake test
12
12
 
13
13
  images:
14
+ ruby:3.3-alpine: *script
14
15
  ruby:3.2-alpine: *script
15
16
  ruby:3.1-alpine: *script
16
17
  ruby:3.0-alpine: *script
data/.gitignore CHANGED
@@ -4,5 +4,6 @@
4
4
  .rvmrc
5
5
  Gemfile.lock
6
6
  coverage
7
+ errors.lst
7
8
  pkg
8
9
  tags
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.2.3
1
+ ruby 3.3.0
data/.utilsrc ADDED
@@ -0,0 +1,26 @@
1
+ # vim: set ft=ruby:
2
+
3
+ search do
4
+ prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
5
+ skip_files /(\A\.|\.sw[pon]\z|\.(log|fnm|jpg|jpeg|png|pdf|svg)\z|tags|~\z)/i
6
+ end
7
+
8
+ discover do
9
+ prune_dirs /\A(\.svn|\.git|CVS|tmp|tags|coverage|pkg)\z/
10
+ skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
11
+ binary false
12
+ end
13
+
14
+ strip_spaces do
15
+ prune_dirs /\A(\..*|CVS|pkg)\z/
16
+ skip_files /(\A\.|\.sw[pon]\z|\.log\z|~\z)/
17
+ end
18
+
19
+ probe do
20
+ test_framework :"test-unit"
21
+ end
22
+
23
+ ssh_tunnel do
24
+ terminal_multiplexer :tmux
25
+ end
26
+
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ GemHadar do
15
15
 
16
16
  test_dir 'tests'
17
17
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage',
18
- 'tags', '.bundle', '.byebug_history'
18
+ 'tags', '.bundle', '.byebug_history', 'errors.lst'
19
19
 
20
20
  readme 'README.md'
21
21
  executables.merge Dir['bin/*'].map { |x| File.basename(x) }
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.2
1
+ 1.9.0
data/bin/term_colortab CHANGED
@@ -15,6 +15,32 @@ def print_color(c)
15
15
  print ("%3u #{color.rgb.html} " % c).on_color(color.name).color(text.name)
16
16
  end
17
17
 
18
+ if Term::ANSIColor.true_coloring = ENV['COLORTERM'] =~ /\A(truecolor|24bit)\z/
19
+
20
+ puts "True colors".bold, ""
21
+ step = 36
22
+ (0..255).step(step) do |g|
23
+ (0..255).step(step) do |r|
24
+ (0..255).step(step) do |b|
25
+ print Term::ANSIColor.on_color(Term::ANSIColor::RGBTriple.new(r, g, b)) { ' ' }
26
+ end
27
+ print ' '
28
+ end
29
+ puts
30
+ end
31
+
32
+ puts
33
+ (0..255).step(4) do |g|
34
+ print Term::ANSIColor.on_color(Term::ANSIColor::RGBTriple.new(g, g, g)) { ' ' }
35
+ end
36
+ puts
37
+ puts
38
+
39
+ end
40
+
41
+ Term::ANSIColor.true_coloring = false
42
+
43
+ puts "256 colors".bold, ""
18
44
  for c in 0..3
19
45
  print_color c
20
46
  end
data/bin/term_display CHANGED
@@ -65,13 +65,14 @@ Options are
65
65
  -a ASPECT x:y aspect, defaults to 2.2
66
66
  -C COLS number of columns for rendering with aspect, defaults to max
67
67
  -R ROWS number of rows for rendering with aspect, defaults to max - 1
68
+ -t use true colors
68
69
  -h this help
69
70
 
70
71
  EOT
71
72
  exit rc
72
73
  end
73
74
 
74
- opts = go 'hm:g:s:a:C:R:'
75
+ opts = go 'hm:g:s:a:C:R:t'
75
76
  opts['h'] and usage
76
77
  filename = ARGV.shift or usage 1
77
78
  metric = Term::ANSIColor::RGBColorMetrics.metric(opts['m'] || 'CIELab')
@@ -84,8 +85,9 @@ opts['R'] ||= [ Tins::Terminal.rows - 1, 0 ].max
84
85
  file = provide_ppm_file(filename, opts)
85
86
  ppm = Term::ANSIColor::PPMReader.new(
86
87
  file,
87
- :metric => metric,
88
- :gray => gray
88
+ metric: metric,
89
+ gray: gray,
90
+ true_coloring: opts[?t]
89
91
  )
90
92
 
91
93
  puts ppm
data/bin/term_mandel CHANGED
@@ -15,16 +15,12 @@ def draw_set(rx, ry)
15
15
  sx = (rx.end - rx.begin).abs / @width
16
16
  sy = (ry.end - ry.begin).abs / @height
17
17
 
18
- ac = Term::ANSIColor
19
- color =
20
- ac::Attribute[ color_random ].gradient_to(ac::Attribute[ color_random ], :steps => 16) +
21
- ac::Attribute[ color_random ].gradient_to(ac::Attribute[ color_random ], :steps => 16) +
22
- ac::Attribute[ color_random ].gradient_to(ac::Attribute[ color_random ], :steps => 16) +
23
- ac::Attribute[ color_random ].gradient_to(ac::Attribute[ color_random ], :steps => 16) +
24
- ac::Attribute[ color_random ].gradient_to(ac::Attribute[ color_random ], :steps => 16) +
25
- ac::Attribute[ color_random ].gradient_to(ac::Attribute[ color_random ], :steps => 16) +
26
- ac::Attribute[ color_random ].gradient_to(ac::Attribute[ color_random ], :steps => 16) +
27
- ac::Attribute[ color_random ].gradient_to(ac::Attribute['#000'], :steps => 16)
18
+ ac = Term::ANSIColor
19
+ steps = 16
20
+ color = (5.times.map { color_random } + [ 0, 0, 0 ]).map { ac::Attribute[_1] }
21
+ color = color[1..-1].inject(color[0,1]) { |c, x|
22
+ c + c.last.gradient_to(x, steps:)
23
+ }
28
24
  iters = color.size - 2
29
25
 
30
26
  text = ''
@@ -44,9 +40,11 @@ def draw_set(rx, ry)
44
40
  puts text
45
41
  end
46
42
 
47
- opts = go 'x:y:'
43
+ opts = go 'x:y'
48
44
 
49
- rx = opts['x'].full? { |r| Range.new(*(r.split('..', 2).map(&:to_f))) } || (-2.0..1.0)
50
- ry = opts['y'].full? { |r| Range.new(*(r.split('..', 2).map(&:to_f))) } || (-1.0..1.0)
45
+ Term::ANSIColor.true_coloring = ENV['COLORTERM'] =~ /\A(truecolor|24bit)\z/
46
+
47
+ rx = opts[?x].full? { |r| Range.new(*(r.split('..', 2).map(&:to_f))) } || (-2.0..1.0)
48
+ ry = opts[?y].full? { |r| Range.new(*(r.split('..', 2).map(&:to_f))) } || (-1.0..1.0)
51
49
 
52
50
  draw_set rx, ry
data/bin/term_snow CHANGED
@@ -9,23 +9,23 @@ class SnowFlake
9
9
  extend Term::ANSIColor
10
10
 
11
11
  def initialize(x, y, shape: %w[ ❄ ❅ ❆ • • · · . . ])
12
- @x, @y, @shape = x, y, Array(shape).sample
13
- @shape.size != 1 and raise ArgumentError, "#@shape needs to be a character"
14
- end
12
+ @x, @y, @shape = x, y, Array(shape).sample
13
+ @shape.size != 1 and raise ArgumentError, "#@shape needs to be a character"
14
+ end
15
15
 
16
- attr_accessor :x
16
+ attr_accessor :x
17
17
 
18
- attr_accessor :y
18
+ attr_accessor :y
19
19
 
20
- attr_accessor :shape
20
+ attr_accessor :shape
21
21
 
22
- def to_s
23
- move_to(y, x) { white on_black @shape }
24
- end
22
+ def to_s
23
+ move_to(y, x) { white on_black @shape }
24
+ end
25
25
  end
26
26
 
27
- opts = go 'n:s:'
28
- new_snowflakes = (opts[?n] || 3).to_i
27
+ opts = go 'n:s:'
28
+ new_snowflakes = (opts[?n] || 3).to_i
29
29
  sleep_duration = (opts[?s] || 0.2).to_f
30
30
 
31
31
  flakes = []
@@ -51,7 +51,7 @@ loop do
51
51
  sf.x = SnowFlake.terminal_columns
52
52
  end
53
53
  else
54
- sf.x == 1
54
+ sf.x += 1
55
55
  if sf.x > SnowFlake.terminal_columns
56
56
  sf.x = 1
57
57
  end
@@ -64,7 +64,7 @@ loop do
64
64
  flakes << SnowFlake.new(rand(1..SnowFlake.terminal_columns), 1)
65
65
  end
66
66
 
67
- print *flakes
67
+ print(*flakes)
68
68
 
69
69
  sleep sleep_duration
70
70
  rescue Interrupt
data/examples/example.rb CHANGED
@@ -81,6 +81,34 @@ print red { bold { "All supported attributes = " } },
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"
83
83
 
84
+ print red { bold { "Use true colors if supported" } }, "\n"
85
+
86
+ colors = Term::ANSIColor::Attribute['#ff0000'].gradient_to(
87
+ Term::ANSIColor::Attribute['#ffff00'],
88
+ true_coloring: true,
89
+ step: 16
90
+ )
91
+ colors += Term::ANSIColor::Attribute[colors.last].gradient_to(
92
+ Term::ANSIColor::Attribute['#00ff00'],
93
+ true_coloring: true,
94
+ step: 16
95
+ )
96
+ colors += Term::ANSIColor::Attribute[colors.last].gradient_to(
97
+ Term::ANSIColor::Attribute['#00ffff'],
98
+ true_coloring: true,
99
+ step: 16
100
+ )
101
+ colors += Term::ANSIColor::Attribute[colors.last].gradient_to(
102
+ Term::ANSIColor::Attribute['#0000ff'],
103
+ true_coloring: true,
104
+ step: 16
105
+ )
106
+
107
+ chars = %w[ ⣾ ⣽ ⣻ ⢿ ⡿ ⣟ ⣯ ⣷ ]
108
+ colors.each_with_index { |c, i| print c.apply { chars[i % chars.size] } }
109
+ puts
110
+ puts
111
+
84
112
  print red { bold { "Make strings monochromatic again:" } }, "\n"
85
113
  print [
86
114
  "red".red,
@@ -88,3 +116,5 @@ print [
88
116
  uncolored { "not red anymore".red },
89
117
  uncolored("not red anymore".red)
90
118
  ].map { |x| x + "\n" } * ''
119
+
120
+ puts "Use the " + "Source".hyperlink("https://github.com/flori/term-ansicolor") + ", Luke!"
@@ -30,15 +30,28 @@ module Term
30
30
  end
31
31
  end
32
32
 
33
- def self.[](name)
34
- case
35
- when self === name then name
36
- when Array === name then nearest_rgb_color name
37
- when name.respond_to?(:to_rgb_triple) then nearest_rgb_color(name.to_rgb_triple.to_a)
38
- when name.to_s =~ /\A(on_)?(\d+)\z/ then get "#$1color#$2"
39
- when name.to_s =~ /\A#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_color name
40
- when name.to_s =~ /\Aon_#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_on_color name
41
- else get name
33
+ def self.[](name, true_coloring: false)
34
+ true_coloring ||= Term::ANSIColor.true_coloring?
35
+ if true_coloring
36
+ case
37
+ when self === name then name
38
+ when Array === name then true_color name
39
+ when name.respond_to?(:to_rgb_triple) then true_color(name.to_rgb_triple.to_a)
40
+ when name.to_s =~ /\A(on_)?(\d+)\z/ then get "#$1color#$2"
41
+ when name.to_s =~ /\A#([0-9a-f]{3}){1,2}\z/i then true_color name
42
+ when name.to_s =~ /\Aon_#([0-9a-f]{3}){1,2}\z/i then on_true_color name
43
+ else get name
44
+ end
45
+ else
46
+ case
47
+ when self === name then name
48
+ when Array === name then nearest_rgb_color name
49
+ when name.respond_to?(:to_rgb_triple) then nearest_rgb_color(name.to_rgb_triple.to_a)
50
+ when name.to_s =~ /\A(on_)?(\d+)\z/ then get "#$1color#$2"
51
+ when name.to_s =~ /\A#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_color name
52
+ when name.to_s =~ /\Aon_#([0-9a-f]{3}){1,2}\z/i then nearest_rgb_on_color name
53
+ else get name
54
+ end
42
55
  end
43
56
  end
44
57
 
@@ -70,10 +83,24 @@ module Term
70
83
  colors.select(&:background?).min_by { |c| c.distance_to(rgb, options) }
71
84
  end
72
85
 
86
+ def self.true_color(color, options = {})
87
+ rgb = RGBTriple[color]
88
+ new(:true, "", { true_color: rgb, background: false })
89
+ end
90
+
91
+ def self.on_true_color(color, options = {})
92
+ rgb = RGBTriple[color]
93
+ new(:on_true, "", { true_color: rgb, background: true })
94
+ end
95
+
73
96
  def initialize(name, code, options = {})
74
- @name = name.to_sym
75
- @code = code.to_s
76
- if html = options[:html]
97
+ @name = name.to_sym
98
+ @background = @name.start_with?('on_')
99
+ @code = code.to_s
100
+ if rgb = options[:true_color]
101
+ @true_color = true
102
+ @rgb = rgb
103
+ elsif html = options[:html]
77
104
  @rgb = RGBTriple.from_html(html)
78
105
  elsif !options.empty?
79
106
  @rgb = RGBTriple.from_hash(options)
@@ -85,7 +112,9 @@ module Term
85
112
  attr_reader :name
86
113
 
87
114
  def code
88
- if rgb_color?
115
+ if true_color?
116
+ background? ? "48;2;#{@rgb.to_a * ?;}" : "38;2;#{@rgb.to_a * ?;}"
117
+ elsif rgb_color?
89
118
  background? ? "48;5;#{@code}" : "38;5;#{@code}"
90
119
  else
91
120
  @code
@@ -97,13 +126,19 @@ module Term
97
126
  end
98
127
 
99
128
  def background?
100
- @name.to_s.start_with?('on_')
129
+ !!@background
101
130
  end
102
131
 
132
+ attr_writer :background
133
+
103
134
  attr_reader :rgb
104
135
 
105
136
  def rgb_color?
106
- !!@rgb
137
+ !!@rgb && !@true_color
138
+ end
139
+
140
+ def true_color?
141
+ !!(@rgb && @true_color)
107
142
  end
108
143
 
109
144
  def gray?
@@ -127,11 +162,16 @@ module Term
127
162
 
128
163
  def gradient_to(other, options = {})
129
164
  if our_rgb = to_rgb_triple and
130
- other.respond_to?(:to_rgb_triple) and
131
- other_rgb = other.to_rgb_triple
132
- then
165
+ other.respond_to?(:to_rgb_triple) and
166
+ other_rgb = other.to_rgb_triple
167
+ then
168
+ true_coloring = options[:true_coloring] || Term::ANSIColor.true_coloring?
133
169
  our_rgb.gradient_to(other_rgb, options).map do |rgb_triple|
134
- self.class.nearest_rgb_color(rgb_triple, options)
170
+ if true_coloring
171
+ self.class.true_color(rgb_triple, options)
172
+ else
173
+ self.class.nearest_rgb_color(rgb_triple, options)
174
+ end
135
175
  end
136
176
  else
137
177
  []
@@ -0,0 +1,34 @@
1
+ require 'tins/terminal'
2
+
3
+ module Term
4
+ module ANSIColor
5
+ module Hyperlink
6
+ def hyperlink(link, string = nil, id: nil, as_link: false)
7
+ block_given? && string != nil && !respond_to?(:to_str) and
8
+ raise ArgumentError,
9
+ "Require either the string argument or a block argument"
10
+ if link.nil?
11
+ link = ''
12
+ end
13
+ if as_link && !link.empty?
14
+ string ||= link
15
+ end
16
+ result = ''
17
+ if Term::ANSIColor.coloring?
18
+ result = "\e]8;#{"id=#{id}" unless id.nil?};" << link.to_str << "\e\\"
19
+ end
20
+ if block_given?
21
+ result << yield.to_s
22
+ elsif string.respond_to?(:to_str)
23
+ result << string.to_str
24
+ elsif respond_to?(:to_str)
25
+ result << to_str
26
+ else
27
+ return result # only switch on
28
+ end
29
+ result << "\e]8;;\e\\" if Term::ANSIColor.coloring?
30
+ result
31
+ end
32
+ end
33
+ end
34
+ end
@@ -4,9 +4,10 @@ module Term
4
4
  include Term::ANSIColor
5
5
 
6
6
  def initialize(io, options = {})
7
- @io = io
8
- @options = options
9
- @buffer = ''
7
+ @io = io
8
+ @options = options
9
+ @buffer = ''
10
+ @true_coloring = options[:true_coloring]
10
11
  end
11
12
 
12
13
  def reset_io
@@ -34,7 +35,11 @@ module Term
34
35
  last_pixel = nil
35
36
  for pixel in row
36
37
  if pixel != last_pixel
37
- color = Attribute.nearest_rgb_color(pixel, @options)
38
+ color = if @true_coloring
39
+ Attribute.true_color(pixel, @options)
40
+ else
41
+ Attribute.nearest_rgb_color(pixel, @options)
42
+ end
38
43
  result << on_color(color)
39
44
  last_pixel = pixel
40
45
  end
@@ -1,6 +1,6 @@
1
1
  module Term::ANSIColor
2
2
  # Term::ANSIColor version
3
- VERSION = '1.7.2'
3
+ VERSION = '1.9.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:
@@ -15,8 +15,9 @@ module Term
15
15
  require 'term/ansicolor/attribute/intense_color8'
16
16
  require 'term/ansicolor/attribute/color256'
17
17
  require 'term/ansicolor/movement'
18
-
19
18
  include Term::ANSIColor::Movement
19
+ require 'term/ansicolor/hyperlink'
20
+ include Term::ANSIColor::Hyperlink
20
21
 
21
22
  # :stopdoc:
22
23
  ATTRIBUTE_NAMES = Attribute.named_attributes.map(&:name)
@@ -34,6 +35,7 @@ module Term
34
35
  !String.instance_methods(false).map(&:to_sym).include?(:clear)
35
36
  end
36
37
  end
38
+
37
39
  # Returns true, if the coloring function of this module
38
40
  # is switched on, false otherwise.
39
41
  def self.coloring?
@@ -42,12 +44,26 @@ module Term
42
44
 
43
45
  # Turns the coloring on or off globally, so you can easily do
44
46
  # this for example:
45
- # Term::ANSIColor::coloring = STDOUT.isatty
47
+ # Term::ANSIColor::coloring = STDOUT.isatty
46
48
  def self.coloring=(val)
47
- @coloring = val
49
+ @coloring = !!val
48
50
  end
49
51
  self.coloring = true
50
52
 
53
+ # Returns true, if the tue coloring mode of this module is switched on,
54
+ # false otherwise.
55
+ def self.true_coloring?
56
+ @true_coloring
57
+ end
58
+
59
+ # Turns the true coloring mode on or off globally, that will display 24-bit
60
+ # colors if your terminal supports it:
61
+ # Term::ANSIColor::true_coloring = ENV['COLORTERM'] =~ /\A(truecolor|24bit)\z/
62
+ def self.true_coloring=(val)
63
+ @true_coloring = !!val
64
+ end
65
+ self.true_coloring = false
66
+
51
67
  def self.create_color_method(color_name, color_value)
52
68
  module_eval <<-EOT
53
69
  def #{color_name}(string = nil, &block)
@@ -63,10 +79,10 @@ module Term
63
79
 
64
80
  # Regular expression that is used to scan for ANSI-Attributes while
65
81
  # uncoloring strings.
66
- COLORED_REGEXP = /\e\[(?:(?:[349]|10)[0-7]|[0-9]|[34]8;5;\d{1,3})?m/
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/
67
83
 
68
- # Returns an uncolored version of the string, that is all
69
- # ANSI-Attributes are stripped from the string.
84
+ # Returns an uncolored version of the string, that is all ANSI-Attributes
85
+ # are stripped from the string.
70
86
  def uncolor(string = nil) # :yields:
71
87
  if block_given?
72
88
  yield.to_str.gsub(COLORED_REGEXP, '')
@@ -95,7 +111,7 @@ module Term
95
111
  elsif respond_to?(:to_str)
96
112
  result << to_str
97
113
  else
98
- return result #only switch on
114
+ return result # only switch on
99
115
  end
100
116
  result << "\e[0m" if Term::ANSIColor.coloring?
101
117
  result.extend(Term::ANSIColor)
@@ -103,7 +119,9 @@ module Term
103
119
 
104
120
  def on_color(name, string = nil, &block)
105
121
  attribute = Attribute[name] or raise ArgumentError, "unknown attribute #{name.inspect}"
106
- color("on_#{attribute.name}", string, &block)
122
+ attribute = attribute.dup
123
+ attribute.background = true
124
+ color(attribute, string, &block)
107
125
  end
108
126
 
109
127
  class << self
@@ -1,31 +1,31 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: term-ansicolor 1.7.2 ruby lib
2
+ # stub: term-ansicolor 1.9.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "term-ansicolor".freeze
6
- s.version = "1.7.2"
6
+ s.version = "1.9.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-03-15"
11
+ s.date = "2024-06-18"
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/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, "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/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/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/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]
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.4.19".freeze
20
+ s.rubygems_version = "3.5.3".freeze
21
21
  s.summary = "Ruby library that colors strings using ANSI escape sequences".freeze
22
- s.test_files = ["tests/ansicolor_test.rb".freeze, "tests/attribute_test.rb".freeze, "tests/hsl_triple_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]
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
 
24
24
  s.specification_version = 4
25
25
 
26
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.14.0"])
27
- s.add_development_dependency(%q<simplecov>.freeze, [">= 0"])
28
- s.add_development_dependency(%q<test-unit>.freeze, [">= 0"])
29
- s.add_development_dependency(%q<utils>.freeze, [">= 0"])
30
- s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.0"])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.15.0".freeze])
27
+ s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
28
+ s.add_development_dependency(%q<test-unit>.freeze, [">= 0".freeze])
29
+ s.add_development_dependency(%q<utils>.freeze, [">= 0".freeze])
30
+ s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.0".freeze])
31
31
  end
@@ -157,4 +157,20 @@ class ANSIColorTest < Test::Unit::TestCase
157
157
  string = Color.red(string)
158
158
  assert_kind_of Term::ANSIColor, 'new'
159
159
  end
160
+
161
+ def test_coloring
162
+ assert Term::ANSIColor.coloring?
163
+ Term::ANSIColor.coloring = false
164
+ assert_false Term::ANSIColor.coloring?
165
+ ensure
166
+ Term::ANSIColor.coloring = true
167
+ end
168
+
169
+ def test_true_coloring
170
+ assert_false Term::ANSIColor.true_coloring?
171
+ Term::ANSIColor.true_coloring = true
172
+ assert Term::ANSIColor.true_coloring?
173
+ ensure
174
+ Term::ANSIColor.true_coloring = false
175
+ end
160
176
  end
@@ -70,4 +70,43 @@ class AttributeTest < Test::Unit::TestCase
70
70
  assert_equal [ :color49, :color43, :color79, :color73, :color108,
71
71
  :color247, :color138, :color168, :color204 ], g2.map(&:name)
72
72
  end
73
+
74
+ def test_true_color
75
+ pinkish = Attribute['#f050a0', true_coloring: true]
76
+ assert_equal [ 240, 80, 160 ], pinkish.to_rgb_triple.to_a
77
+ on_pinkish = Attribute['on_#f050a0', true_coloring: true]
78
+ assert_equal [ 240, 80, 160 ], on_pinkish.to_rgb_triple.to_a
79
+ red = Attribute['9', true_coloring: true]
80
+ assert_equal [ 255, 0, 0 ], red.to_rgb_triple.to_a
81
+ red = Attribute['red', true_coloring: true]
82
+ assert_equal :red, red.name
83
+ pinkish_pinkish = Attribute[pinkish, true_coloring: true]
84
+ assert_equal pinkish, pinkish_pinkish
85
+ pinkish_pinkish = Attribute[pinkish.to_rgb_triple, true_coloring: true]
86
+ assert_equal pinkish.to_rgb_triple, pinkish_pinkish.to_rgb_triple
87
+ pinkish_pinkish = Attribute[pinkish.to_rgb_triple.to_a, true_coloring: true]
88
+ assert_equal pinkish.to_rgb_triple, pinkish_pinkish.to_rgb_triple
89
+ end
90
+
91
+ def test_true_color_gradient
92
+ g0 = Attribute[:blink].gradient_to Attribute['#30ffaa']
93
+ assert_equal [], g0
94
+ g1 = Attribute['#30ffaa'].gradient_to(
95
+ Attribute['#ff507f'],
96
+ :steps => 9,
97
+ true_coloring: true
98
+ )
99
+ assert_equal %w[
100
+ #00ffaf #1febaa #3ed7a5 #5dc3a0 #7caf9b #9b9b96 #ba8791 #d9738c #ff5f87
101
+ ], g1.map { _1.rgb.html }
102
+ g2 = Attribute['#30ffaa'].gradient_to(
103
+ Attribute['#ff507f'],
104
+ :steps => 9,
105
+ true_coloring: true,
106
+ :metric => RGBColorMetrics::Euclidean
107
+ )
108
+ assert_equal %w[
109
+ #00ffaf #1febaa #3ed7a5 #5dc3a0 #7caf9b #9b9b96 #ba8791 #d9738c #ff5f87
110
+ ], g2.map { _1.rgb.html }
111
+ end
73
112
  end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class HyperlinkTest < Test::Unit::TestCase
4
+ include Term::ANSIColor
5
+
6
+ def setup
7
+ @link = 'https://foo.example.com'
8
+ end
9
+
10
+ def test_hyperlink_switch_on
11
+ assert_equal(
12
+ "\e]8;;#@link\e\\",
13
+ hyperlink(@link)
14
+ )
15
+ end
16
+
17
+ def test_hyperlink_switch_off
18
+ assert_equal(
19
+ "\e]8;;\e\\",
20
+ hyperlink(nil)
21
+ )
22
+ end
23
+
24
+ def test_hyperlink_as_link
25
+ assert_equal(
26
+ hyperlink(@link, as_link: true),
27
+ "\e]8;;#@link\e\\#@link\e]8;;\e\\",
28
+ )
29
+ end
30
+
31
+ def test_hyperlink_two_args
32
+ assert_equal(
33
+ "\e]8;;#@link\e\\foo\e]8;;\e\\",
34
+ hyperlink(@link, 'foo')
35
+ )
36
+ end
37
+
38
+ def test_hyperlink_two_args_with_id
39
+ assert_equal(
40
+ "\e]8;id=666;#@link\e\\foo\e]8;;\e\\",
41
+ hyperlink(@link, 'foo', id: 666)
42
+ )
43
+ end
44
+
45
+ def test_hyperlink_block_arg
46
+ assert_raise(ArgumentError) { hyperlink(@link, 'bar') { 'baz' } }
47
+ assert_equal(
48
+ "\e]8;;#@link\e\\foo\e]8;;\e\\",
49
+ hyperlink(@link) { 'foo' }
50
+ )
51
+ end
52
+
53
+ def test_with_stringy_self
54
+ string = 'foo'
55
+ string.extend Term::ANSIColor
56
+ assert_equal "\e]8;;#@link\e\\foo\e]8;;\e\\", string.hyperlink(@link)
57
+ end
58
+ end
@@ -28,6 +28,14 @@ class PPMReaderTest < Test::Unit::TestCase
28
28
  end
29
29
  end
30
30
 
31
+ def test_rendering_ppm_with_true_colors
32
+ File.open(example_path('lambda-red.ppm')) do |ppm6|
33
+ ppm_reader = PPMReader.new(ppm6, :true_coloring => true)
34
+ assert_equal '5faa2b046cc3e030f86588e472683834',
35
+ Digest::MD5.hexdigest(ppm_reader.to_s)
36
+ end
37
+ end
38
+
31
39
  def test_to_a
32
40
  File.open(example_path('lambda-red.ppm')) do |ppm6|
33
41
  ppm_reader = PPMReader.new(ppm6, :gray => false)
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.7.2
4
+ version: 1.9.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-03-15 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.14.0
19
+ version: 1.15.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.14.0
26
+ version: 1.15.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -100,6 +100,7 @@ extra_rdoc_files:
100
100
  - lib/term/ansicolor/attribute/intense_color8.rb
101
101
  - lib/term/ansicolor/attribute/text.rb
102
102
  - lib/term/ansicolor/hsl_triple.rb
103
+ - lib/term/ansicolor/hyperlink.rb
103
104
  - lib/term/ansicolor/movement.rb
104
105
  - lib/term/ansicolor/ppm_reader.rb
105
106
  - lib/term/ansicolor/rgb_color_metrics.rb
@@ -109,6 +110,7 @@ files:
109
110
  - ".all_images.yml"
110
111
  - ".gitignore"
111
112
  - ".tool-versions"
113
+ - ".utilsrc"
112
114
  - CHANGES
113
115
  - COPYING
114
116
  - Gemfile
@@ -133,6 +135,7 @@ files:
133
135
  - lib/term/ansicolor/attribute/intense_color8.rb
134
136
  - lib/term/ansicolor/attribute/text.rb
135
137
  - lib/term/ansicolor/hsl_triple.rb
138
+ - lib/term/ansicolor/hyperlink.rb
136
139
  - lib/term/ansicolor/movement.rb
137
140
  - lib/term/ansicolor/ppm_reader.rb
138
141
  - lib/term/ansicolor/rgb_color_metrics.rb
@@ -142,6 +145,7 @@ files:
142
145
  - tests/ansicolor_test.rb
143
146
  - tests/attribute_test.rb
144
147
  - tests/hsl_triple_test.rb
148
+ - tests/hyperlink_test.rb
145
149
  - tests/ppm_reader_test.rb
146
150
  - tests/rgb_color_metrics_test.rb
147
151
  - tests/rgb_triple_test.rb
@@ -169,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
169
173
  - !ruby/object:Gem::Version
170
174
  version: '0'
171
175
  requirements: []
172
- rubygems_version: 3.4.19
176
+ rubygems_version: 3.5.3
173
177
  signing_key:
174
178
  specification_version: 4
175
179
  summary: Ruby library that colors strings using ANSI escape sequences
@@ -177,6 +181,7 @@ test_files:
177
181
  - tests/ansicolor_test.rb
178
182
  - tests/attribute_test.rb
179
183
  - tests/hsl_triple_test.rb
184
+ - tests/hyperlink_test.rb
180
185
  - tests/ppm_reader_test.rb
181
186
  - tests/rgb_color_metrics_test.rb
182
187
  - tests/rgb_triple_test.rb