term-ansicolor 1.10.2 → 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: 3cbfd241e244b761869192a65bdf1ca6a11ca79910c8daa6633ce6a5aec73d5f
4
- data.tar.gz: afe01235e057c5b6faa4b31a13369b8f86a00f9aca4bf07baf95a246ec7cf473
3
+ metadata.gz: 4ec4bd5406d6a919febb9444a996f99a153a18562d1728bc94483b2a1ac32f8a
4
+ data.tar.gz: 48e114e79275436a11dc3db76a2308a0ad804125195196ff24ace6cbe4e2354d
5
5
  SHA512:
6
- metadata.gz: ce2c8eaffdaa0e859738f01ab9276b70c2463fa5f647b5e2f5220b6c55c981eb5873a4255a404f17dfecf10479b4a6dfbd6a5bd7692ff1d2954a2d286658248c
7
- data.tar.gz: 93733afa943c51b91c530897ce1cda156c927fd993a24defac4f647db9582ce0b8bb791bb272eb4b59f40afcc59af728dbf03ecb725a742013bca5ecb4696d3a
6
+ metadata.gz: 9013380ea29dd3b95d46d878c033a7f1e0d686b9f37d117dd2794fea5262122074685bf064bec5277116089f8b6b747e2e12a8daf33045ef0a501a3cd16c59f8
7
+ data.tar.gz: fd371c1dc99443dd49c30406930a2f1c687d6584f364b01505192746d851dacae619502c00ce90731812b148eab22de4f245e1256a2fc5dd7eb3980b520c3190
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.2
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
@@ -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.2'
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.2 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.2".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-22"
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 }
@@ -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.2
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-22 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