term-ansicolor 1.10.3 → 1.11.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: 4ec4bd5406d6a919febb9444a996f99a153a18562d1728bc94483b2a1ac32f8a
4
- data.tar.gz: 48e114e79275436a11dc3db76a2308a0ad804125195196ff24ace6cbe4e2354d
3
+ metadata.gz: a99b1522303d7fa622793a7b924e74f897de9a031f775f723aac24bb3f7e6bf5
4
+ data.tar.gz: 58f241a9bdbc068dae3c856aaf919939e3e1a25f831fa4fa6ed562d324365e55
5
5
  SHA512:
6
- metadata.gz: 9013380ea29dd3b95d46d878c033a7f1e0d686b9f37d117dd2794fea5262122074685bf064bec5277116089f8b6b747e2e12a8daf33045ef0a501a3cd16c59f8
7
- data.tar.gz: fd371c1dc99443dd49c30406930a2f1c687d6584f364b01505192746d851dacae619502c00ce90731812b148eab22de4f245e1256a2fc5dd7eb3980b520c3190
6
+ metadata.gz: 7e2716d88870533348a32230da0436fbb127d7dac440d4da5bbf292489b005d8d282f35b067bc14cd5919fbc4ad34ddfdbd1c2f016e5abc6d15fa11d09a988b9
7
+ data.tar.gz: 4d9601059cdc1d848a0ca8a6b7aef4bc88656ac1e55c96f391269b4f8e53ef3ec216c7882d49af63f7dc45e7c2484d4354d0a88ee8544e3a27b580ef103fae01
data/.gitignore CHANGED
@@ -4,6 +4,7 @@
4
4
  .rvmrc
5
5
  Gemfile.lock
6
6
  coverage
7
+ cscope.out
7
8
  errors.lst
8
9
  pkg
9
10
  tags
data/README.md CHANGED
@@ -31,6 +31,9 @@ The following executables are provided with Term::ANSIColor:
31
31
  * `term_mandel`: displays the mandelbrot set in the terminal
32
32
  * `term_snow`: displays falling snow in the terminal using ANSI movement
33
33
  sequences.
34
+ * `term_plasma`: draws a plasma effect on the console, possibly animated and
35
+ refreshed every `-n seconds`.
36
+
34
37
 
35
38
  Additionally the file examples/example.rb in the source/gem-distribution shows
36
39
  how this library can be used.
data/Rakefile CHANGED
@@ -15,13 +15,13 @@ GemHadar do
15
15
 
16
16
  test_dir 'tests'
17
17
  ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', 'coverage',
18
- 'tags', '.bundle', '.byebug_history', 'errors.lst'
18
+ 'tags', '.bundle', '.byebug_history', 'errors.lst', 'cscope.out'
19
19
 
20
20
  readme 'README.md'
21
21
  executables.merge Dir['bin/*'].map { |x| File.basename(x) }
22
22
 
23
23
  dependency 'tins', '~>1.0'
24
- dependency 'mize'
24
+ dependency 'mize', '~>0.5'
25
25
  development_dependency 'simplecov'
26
26
  development_dependency 'test-unit'
27
27
  development_dependency 'utils'
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.10.3
1
+ 1.11.0
data/bin/term_plasma ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tins/go'
4
+ include Tins::GO
5
+ require 'term/ansicolor'
6
+ include Term::ANSIColor
7
+ Term::ANSIColor.true_coloring = ENV['COLORTERM'] =~ /\A(truecolor|24bit)\z/
8
+ include Math
9
+
10
+ # Generates a palette of 256 colors based on sine waves
11
+ #
12
+ # @return [Array<Array<Integer>>] An array of arrays, each containing
13
+ # three integers representing the RGB values of a color.
14
+ def generate_palette
15
+ (0..255).map { |i|
16
+ [
17
+ 128 + 128 * sin(PI * i / 32.0),
18
+ 128 + 128 * sin(PI * i / 64.0),
19
+ 128 + 128 * sin(PI * i / 128.0),
20
+ ].map { _1.clamp(0, 255).round }
21
+ }
22
+ end
23
+
24
+ # Resets the terminal to its original state, and assigns width $w and height
25
+ # $h.
26
+ def full_reset
27
+ $w, $h = Tins::Terminal.cols, Tins::Terminal.lines
28
+ $h *= 2
29
+ print reset, clear_screen, move_home, hide_cursor
30
+ end
31
+
32
+ # Generates a screen based on a plasma.
33
+ #
34
+ # @param plasma [Array<Array<Integer>>] An array of arrays, each containing
35
+ # three integers representing the RGB values of a color.
36
+ # @return [String] The string representation of the screen, each character
37
+ # representing a pixel on the screen with the corresponding color.
38
+ def generate_screen(plasma)
39
+ screen = ''
40
+ 0.step($h - 1, 2) do |y|
41
+ 0.upto($w - 1) do |x|
42
+ screen << color(plasma[y][x]) + on_color(plasma[y + 1][x]) + ?▀
43
+ end
44
+ end
45
+ screen
46
+ end
47
+
48
+ # Generates a plasma generated based on sine waves
49
+ #
50
+ # @param now [Float] A value based on the current time in seconds
51
+ # @return [Array<Array<Integer>>] An array of arrays, each containing
52
+ # three integers representing the RGB values of a color.
53
+ def generate_plasma(now)
54
+ plasma = Array.new($h) { [ nil ] * $w }
55
+ 0.upto($h - 1) do |y|
56
+ 0.upto($w - 1) do |x|
57
+ x, y = x.to_f, y.to_f
58
+ color = (
59
+ 128.0 + (128.0 * sin((x / 7.0) - 3.0 * cos(now / 2.0))) +
60
+ 128.0 + (128.0 * sin((y / 13.0) - 2.0 * sin(now))) +
61
+ 128.0 + (128.0 * sin(hypot((x - $w / 3.0), (y - $h / 2.0)) / 5.0)) +
62
+ 128.0 + (128.0 * sin((hypot(x, y) / 5.0) - sin(now / 3.0)))
63
+ ) / 4.0
64
+ plasma[y][x] = $palette[(color + now).round % $palette.size]
65
+ end
66
+ end
67
+ plasma
68
+ end
69
+
70
+ $opts = go('n:')
71
+
72
+ $palette = generate_palette
73
+
74
+ begin
75
+ $full_reset = true
76
+ trap(:SIGWINCH) { $full_reset = true }
77
+
78
+ loop do
79
+ if $full_reset
80
+ $full_reset = false
81
+ full_reset
82
+ end
83
+
84
+ now = Time.now.to_f / ($opts[?n]&.to_f || 1)
85
+ plasma = generate_plasma(now)
86
+ print move_home, generate_screen(plasma), reset
87
+
88
+ if n = $opts[?n]&.to_f
89
+ sleep n
90
+ else
91
+ print move_to_column(1), erase_in_line, show_cursor
92
+ exit
93
+ end
94
+ end
95
+ rescue Interrupt
96
+ print reset, clear_screen, move_home, show_cursor
97
+ end
@@ -40,7 +40,7 @@ module Term
40
40
  Attribute.set :on_color4, 4, html: '#000080', background: true
41
41
  Attribute.set :on_color5, 5, html: '#800080', background: true
42
42
  Attribute.set :on_color6, 6, html: '#008080', background: true
43
- Attribute.set :on_color7, 7, html: '#c0c0c0'
43
+ Attribute.set :on_color7, 7, html: '#c0c0c0', background: true
44
44
 
45
45
  Attribute.set :on_color8, 8, html: '#808080', background: true
46
46
  Attribute.set :on_color9, 9, html: '#ff0000', background: true
@@ -49,12 +49,25 @@ module Term
49
49
  @__store__[name.to_sym]
50
50
  end
51
51
 
52
- def self.rgb_colors(options = {}, &block)
53
- colors = attributes.select(&:rgb_color?)
54
- if options.key?(:gray) && !options[:gray]
55
- colors = colors.reject(&:gray?)
52
+ class << self
53
+ memoize method:
54
+ def rgb_colors(options = {}, &block)
55
+ colors = attributes.select(&:rgb_color?)
56
+ if options.key?(:gray) && !options[:gray]
57
+ colors = colors.reject(&:gray?)
58
+ end
59
+ colors.each(&block)
60
+ end
61
+
62
+ memoize method:
63
+ def rgb_foreground_colors(options = {}, &block)
64
+ rgb_colors(options).reject(&:background?).each(&block)
65
+ end
66
+
67
+ memoize method:
68
+ def rgb_background_colors(options = {}, &block)
69
+ rgb_colors(options).select(&:background?).each(&block)
56
70
  end
57
- colors.each(&block)
58
71
  end
59
72
 
60
73
  def self.named_attributes(&block)
@@ -63,14 +76,12 @@ module Term
63
76
 
64
77
  def self.nearest_rgb_color(color, options = {})
65
78
  rgb = RGBTriple[color]
66
- colors = rgb_colors(options)
67
- colors.reject(&:background?).min_by { |c| c.distance_to(rgb, options) }
79
+ rgb_foreground_colors(options).min_by { |c| c.distance_to(rgb, options) }
68
80
  end
69
81
 
70
82
  def self.nearest_rgb_on_color(color, options = {})
71
83
  rgb = RGBTriple[color]
72
- colors = rgb_colors(options)
73
- colors.select(&:background?).min_by { |c| c.distance_to(rgb, options) }
84
+ rgb_background_colors(options).min_by { |c| c.distance_to(rgb, options) }
74
85
  end
75
86
 
76
87
  def self.true_color(color, options = {})
@@ -2,7 +2,7 @@ module Term
2
2
  module ANSIColor
3
3
  class HSLTriple
4
4
  def self.from_rgb_triple(rgb)
5
- ps = rgb.to_a.map { |x| x / 255.0 }
5
+ ps = [ rgb.red / 255.0, rgb.green / 255.0, rgb.blue / 255.0 ]
6
6
  p_min = ps.min
7
7
  p_max = ps.max
8
8
  p_red, p_green, p_blue = ps
@@ -53,11 +53,7 @@ module Term
53
53
  private
54
54
 
55
55
  def parse_row
56
- row = []
57
- @width.times do
58
- row << parse_next_pixel
59
- end
60
- row
56
+ @width.times.map { parse_next_pixel }
61
57
  end
62
58
 
63
59
  def parse_next_pixel
@@ -19,16 +19,16 @@ module Term
19
19
  if v <= 0.04045
20
20
  v / 12
21
21
  else
22
- ( (v + 0.055) / 1.055) ** 2.4
22
+ ( (v + 0.055) / 1.055 ) ** 2.4
23
23
  end
24
24
  end
25
25
 
26
26
  def normalize_rgb_triple(rgb_triple)
27
27
  [
28
- rgb_triple.red,
29
- rgb_triple.green,
30
- rgb_triple.blue
31
- ].map { |v| normalize(v) }
28
+ normalize(rgb_triple.red),
29
+ normalize(rgb_triple.green),
30
+ normalize(rgb_triple.blue),
31
+ ]
32
32
  end
33
33
  end
34
34
  end
@@ -59,7 +59,11 @@ module Term
59
59
  end
60
60
 
61
61
  def initialize(red, green, blue)
62
- @values = [ red, green, blue ].map! { |v| v.clamp(0, 0xff) }
62
+ @values = [
63
+ red.clamp(0, 0xff),
64
+ green.clamp(0, 0xff),
65
+ blue.clamp(0, 0xff),
66
+ ]
63
67
  end
64
68
 
65
69
  def red
@@ -106,7 +110,7 @@ module Term
106
110
 
107
111
  def css(percentage: false)
108
112
  if percentage
109
- "rgb(%s%%,%s%%,%s%%)" % @values.map { |v| 100.0 * v / 255 }
113
+ "rgb(%s%%,%s%%,%s%%)" % percentages
110
114
  else
111
115
  "rgb(%u,%u,%u)" % @values
112
116
  end
@@ -1,6 +1,6 @@
1
1
  module Term::ANSIColor
2
2
  # Term::ANSIColor version
3
- VERSION = '1.10.3'
3
+ VERSION = '1.11.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,32 +1,32 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: term-ansicolor 1.10.3 ruby lib
2
+ # stub: term-ansicolor 1.11.0 ruby lib
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "term-ansicolor".freeze
6
- s.version = "1.10.3".freeze
6
+ s.version = "1.11.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-07-14"
11
+ s.date = "2024-08-01"
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
- s.executables = ["term_cdiff".freeze, "term_colortab".freeze, "term_decolor".freeze, "term_display".freeze, "term_mandel".freeze, "term_snow".freeze]
14
+ s.executables = ["term_cdiff".freeze, "term_colortab".freeze, "term_decolor".freeze, "term_display".freeze, "term_mandel".freeze, "term_plasma".freeze, "term_snow".freeze]
15
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]
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_plasma".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.11".freeze
20
+ s.rubygems_version = "3.5.16".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
 
24
24
  s.specification_version = 4
25
25
 
26
- s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.15.0".freeze])
26
+ s.add_development_dependency(%q<gem_hadar>.freeze, ["~> 1.16.1".freeze])
27
27
  s.add_development_dependency(%q<simplecov>.freeze, [">= 0".freeze])
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
+ s.add_runtime_dependency(%q<mize>.freeze, ["~> 0.5".freeze])
32
32
  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.3
4
+ version: 1.11.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-07-14 00:00:00.000000000 Z
11
+ date: 2024-08-01 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.15.0
19
+ version: 1.16.1
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.15.0
26
+ version: 1.16.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: simplecov
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: mize
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '0.5'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '0.5'
97
97
  description: This library uses ANSI escape sequences to control the attributes of
98
98
  terminal output
99
99
  email: flori@ping.de
@@ -103,6 +103,7 @@ executables:
103
103
  - term_decolor
104
104
  - term_display
105
105
  - term_mandel
106
+ - term_plasma
106
107
  - term_snow
107
108
  extensions: []
108
109
  extra_rdoc_files:
@@ -136,6 +137,7 @@ files:
136
137
  - bin/term_decolor
137
138
  - bin/term_display
138
139
  - bin/term_mandel
140
+ - bin/term_plasma
139
141
  - bin/term_snow
140
142
  - examples/example.rb
141
143
  - examples/lambda-red-plain.ppm
@@ -188,7 +190,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
190
  - !ruby/object:Gem::Version
189
191
  version: '0'
190
192
  requirements: []
191
- rubygems_version: 3.5.11
193
+ rubygems_version: 3.5.16
192
194
  signing_key:
193
195
  specification_version: 4
194
196
  summary: Ruby library that colors strings using ANSI escape sequences