term-ansicolor 1.10.1 → 1.10.3

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: 768db698164c4d6226839c11932c868d2a6e93e2c6d6db03e5fbee3422b8ecf7
4
- data.tar.gz: 025abdbb49d4c589a00e70c7f467612d24748cc7b43db3901ca7b9bde909e906
3
+ metadata.gz: 4ec4bd5406d6a919febb9444a996f99a153a18562d1728bc94483b2a1ac32f8a
4
+ data.tar.gz: 48e114e79275436a11dc3db76a2308a0ad804125195196ff24ace6cbe4e2354d
5
5
  SHA512:
6
- metadata.gz: ea842c5808c77941ba10f1599cda75bd8a32c07317c126298b4000b7340111f83a0dc6c7b79862d8e708860f5b4e0f2ede10e82d7a7e678fb9cf3f7122473266
7
- data.tar.gz: 2edff8a89a38ad47f54f9110923ae2a809e9196f8222d9da6ba82513bdd650eff66623baeacfb075cccc03e7b21728c1a3a58a6d759aceb61336f271a6a15add
6
+ metadata.gz: 9013380ea29dd3b95d46d878c033a7f1e0d686b9f37d117dd2794fea5262122074685bf064bec5277116089f8b6b747e2e12a8daf33045ef0a501a3cd16c59f8
7
+ data.tar.gz: fd371c1dc99443dd49c30406930a2f1c687d6584f364b01505192746d851dacae619502c00ce90731812b148eab22de4f245e1256a2fc5dd7eb3980b520c3190
data/.all_images.yml CHANGED
@@ -1,7 +1,15 @@
1
1
  dockerfile: |-
2
- RUN apk add --no-cache build-base git
3
- RUN gem update --system
4
- RUN gem install gem_hadar bundler
2
+ RUN apk add --no-cache build-base git bash
3
+ RUN bash <<NUR
4
+ if [[ "$(ruby -e 'print RUBY_VERSION')" > '3' ]]
5
+ then
6
+ gem update --system
7
+ gem install gem_hadar bundler
8
+ else
9
+ gem install gem_hadar
10
+ gem install bundler -v 2.4.22
11
+ fi
12
+ NUR
5
13
 
6
14
  script: &script |-
7
15
  echo -e "\e[1m"
@@ -15,3 +23,5 @@ images:
15
23
  ruby:3.2-alpine: *script
16
24
  ruby:3.1-alpine: *script
17
25
  ruby:3.0-alpine: *script
26
+ ruby:2.7-alpine: *script
27
+ ruby:2.6-alpine: *script
data/README.md CHANGED
@@ -22,13 +22,15 @@ The homepage of this library is located at
22
22
 
23
23
  The following executables are provided with Term::ANSIColor:
24
24
 
25
- * `cdiff`: colors a diff patch
26
- * `decolor`: decolors any text file that was colored with ANSI escape sequences
27
- * `colortab`: Displays a table of the 256 terminal colors with their indices and
25
+ * `term_cdiff`: colors a diff patch
26
+ * `term_colortab`: Displays a table of the 256 terminal colors with their indices and
28
27
  nearest html equivalents.
29
28
  * `term_display`: displays a ppm3 or ppm6 image file in the terminal. If the netpbm
30
29
  programs are installed it can handle a lot of other image file formats.
30
+ * `term_decolor`: decolors any text file that was colored with ANSI escape sequences
31
31
  * `term_mandel`: displays the mandelbrot set in the terminal
32
+ * `term_snow`: displays falling snow in the terminal using ANSI movement
33
+ sequences.
32
34
 
33
35
  Additionally the file examples/example.rb in the source/gem-distribution shows
34
36
  how this library can be used.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.10.1
1
+ 1.10.3
data/bin/term_mandel CHANGED
@@ -1,31 +1,32 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'term/ansicolor'
4
+ include Term::ANSIColor
4
5
  require 'tins/xt'
5
- require "complex"
6
6
  include Tins::GO
7
+ require "complex"
7
8
 
8
- @width, @height = Tins::Terminal.cols, Tins::Terminal.lines
9
+ $width, $height = Tins::Terminal.cols, Tins::Terminal.lines
10
+ $height *= 2
9
11
 
10
12
  def color_random
11
13
  (1..3).map { rand(255) }
12
14
  end
13
15
 
14
16
  def draw_set(rx, ry)
15
- sx = (rx.end - rx.begin).abs / @width
16
- sy = (ry.end - ry.begin).abs / @height
17
+ sx = (rx.end - rx.begin).abs / $width
18
+ sy = (ry.end - ry.begin).abs / $height
17
19
 
18
- ac = Term::ANSIColor
19
20
  steps = 16
20
- color = (5.times.map { color_random } + [ 0, 0, 0 ]).map { ac::Attribute[_1] }
21
+ color = (5.times.map { color_random } + [ 0, 0, 0 ]).map { Attribute[_1] }
21
22
  color = color[1..-1].inject(color[0,1]) { |c, x|
22
23
  c + c.last.gradient_to(x, steps:)
23
24
  }
24
25
  iters = color.size - 2
25
26
 
26
- text = ''
27
- for j in 0...@height
28
- for i in 0...@width
27
+ data = [ [] ]
28
+ for j in 0...$height
29
+ for i in 0...$width
29
30
  n, z_n = 0, Complex(0, 0)
30
31
  c = Complex(sx * i + rx.begin, sy * j + ry.begin)
31
32
  while n <= iters
@@ -33,11 +34,18 @@ def draw_set(rx, ry)
33
34
  z_n = z_n ** 2 + c
34
35
  n += 1
35
36
  end
36
- text << ac.on_color(color[n]) << ' '
37
+ data.last << n
38
+ end
39
+ data << []
40
+ end
41
+ screen = ''
42
+ (0...$height).step(2) do |j|
43
+ (0...$width).each do |i|
44
+ screen << color(color[data[j][i]]) <<
45
+ on_color(color[data[j + 1][i]]) << ?▀
37
46
  end
38
- text << ac.reset << "\n"
39
47
  end
40
- puts text
48
+ print move_home, screen, reset
41
49
  end
42
50
 
43
51
  opts = go 'x:y'
@@ -15,12 +15,12 @@ module Term
15
15
  dashed: '4:5',
16
16
  }.fetch(type) { raise ArgumentError, "invalid line type" }
17
17
  if color
18
- a = Term::ANSIColor::Attribute[color]
18
+ a = Term::ANSIColor::Attribute[color]
19
19
  color_code =
20
- if a.true_color? || a.rgb_color? || a.direct?
21
- color_code = "\e[58;2;#{a.rgb.to_a * ?;}"
20
+ if rgb = a.ask_and_send(:to_rgb_triple).full?(:to_a)
21
+ "\e[58;2;#{rgb * ?;}"
22
22
  else
23
- raise ArgumentError, "invalid color #{a.name.inspect}"
23
+ raise ArgumentError, "invalid color #{a&.name.inspect}"
24
24
  end
25
25
  code = "#{code}m#{color_code}"
26
26
  end
@@ -87,6 +87,7 @@ module Term
87
87
  @name = name.to_sym
88
88
  @background = !!options[:background]
89
89
  @code = code.to_s
90
+ @direct = false
90
91
  @true_color = false
91
92
  if rgb = options[:true_color]
92
93
  @true_color = true
@@ -72,8 +72,8 @@ module Term
72
72
 
73
73
  def initialize(hue, saturation, lightness)
74
74
  @hue = Float(hue) % 360
75
- @saturation = [ [ Float(saturation), 0 ].max, 100 ].min
76
- @lightness = [ [ Float(lightness), 0 ].max, 100 ].min
75
+ @saturation = Float(saturation).clamp(0, 100)
76
+ @lightness = Float(lightness).clamp(0, 100)
77
77
  end
78
78
 
79
79
  attr_reader :hue
@@ -59,9 +59,7 @@ module Term
59
59
  end
60
60
 
61
61
  def initialize(red, green, blue)
62
- @values = [ red, green, blue ].map { |v|
63
- [ [ Integer(v), 0 ].max, 0xff ].min
64
- }
62
+ @values = [ red, green, blue ].map! { |v| v.clamp(0, 0xff) }
65
63
  end
66
64
 
67
65
  def red
@@ -1,6 +1,6 @@
1
1
  module Term::ANSIColor
2
2
  # Term::ANSIColor version
3
- VERSION = '1.10.1'
3
+ VERSION = '1.10.3'
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 'tins/xt/ask_and_send'
2
3
  require 'mize'
3
4
 
4
5
  module Term
@@ -1,14 +1,14 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: term-ansicolor 1.10.1 ruby lib
2
+ # stub: term-ansicolor 1.10.3 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "term-ansicolor".freeze
6
- s.version = "1.10.1".freeze
6
+ s.version = "1.10.3".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-21"
11
+ s.date = "2024-07-14"
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]
@@ -134,6 +134,14 @@ class ANSIColorTest < Test::Unit::TestCase
134
134
  assert_equal Term::ANSIColor.attributes, 'foo'.attributes
135
135
  end
136
136
 
137
+ def test_underline_invalid_type
138
+ assert_raises(ArgumentError) { Term::ANSIColor.underline(type: :nix) { 'foo' } }
139
+ end
140
+
141
+ def test_underline_invalid_color
142
+ assert_raises(ArgumentError) { Term::ANSIColor.underline(color: :nix) { 'foo' } }
143
+ end
144
+
137
145
  def test_underline
138
146
  foo = 'foo'
139
147
  assert_equal "\e[4mfoo\e[0m", Term::ANSIColor.underline { foo }
@@ -98,7 +98,7 @@ class AttributeTest < Test::Unit::TestCase
98
98
  )
99
99
  assert_equal %w[
100
100
  #00ffaf #1febaa #3ed7a5 #5dc3a0 #7caf9b #9b9b96 #ba8791 #d9738c #ff5f87
101
- ], g1.map { _1.rgb.html }
101
+ ], g1.map { |c| c.rgb.html }
102
102
  g2 = Attribute['#30ffaa'].gradient_to(
103
103
  Attribute['#ff507f'],
104
104
  steps: 9,
@@ -107,6 +107,6 @@ class AttributeTest < Test::Unit::TestCase
107
107
  )
108
108
  assert_equal %w[
109
109
  #00ffaf #1febaa #3ed7a5 #5dc3a0 #7caf9b #9b9b96 #ba8791 #d9738c #ff5f87
110
- ], g2.map { _1.rgb.html }
110
+ ], g2.map { |c| c.rgb.html }
111
111
  end
112
112
  end
@@ -80,6 +80,6 @@ class HSLTripleTest < Test::Unit::TestCase
80
80
  end
81
81
 
82
82
  def test_method_missing
83
- assert_raise(NoMethodError) { @pastel_green_hsl.foo }
83
+ assert_raises(NoMethodError) { @pastel_green_hsl.foo }
84
84
  end
85
85
  end
@@ -43,7 +43,7 @@ class HyperlinkTest < Test::Unit::TestCase
43
43
  end
44
44
 
45
45
  def test_hyperlink_block_arg
46
- assert_raise(ArgumentError) { hyperlink(@link, 'bar') { 'baz' } }
46
+ assert_raises(ArgumentError) { hyperlink(@link, 'bar') { 'baz' } }
47
47
  assert_equal(
48
48
  "\e]8;;#@link\e\\foo\e]8;;\e\\",
49
49
  hyperlink(@link) { 'foo' }
@@ -96,6 +96,6 @@ class RgbTripleTest < Test::Unit::TestCase
96
96
  end
97
97
 
98
98
  def test_method_missing
99
- assert_raise(NoMethodError) { RGBTriple.new(0, 0, 0).foo }
99
+ assert_raises(NoMethodError) { RGBTriple.new(0, 0, 0).foo }
100
100
  end
101
101
  end
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.10.1
4
+ version: 1.10.3
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-21 00:00:00.000000000 Z
11
+ date: 2024-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gem_hadar