colorato 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bb6270007938fb0916b87353d58dd27bd2e7955d746480e857b1ed2519211993
4
+ data.tar.gz: 3ffb11adc797a497a7b63fafb7e9a92c46fe65b36ae802e53b3651b96f3f292a
5
+ SHA512:
6
+ metadata.gz: 1a81a30427e2ba3952cddd887f8c113219ae7ef3f96672a9f3464eda375abcfd09c6a74d5a39e28d8a05da24f32b7ce89041ed141c5828c8126f393361aa3f4d
7
+ data.tar.gz: 8ac4184b1ecfd075a9ff9e877ac0db21b1c244787a978f57ef6c5226e276fcc36fbcd924e904c296b6eff185b1eac6f62fcdfe0d89d657009bbf079c32203d3c
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+
2
+ # colorato
3
+
4
+
5
+ ## 0.9.0 released 2023-01-02
6
+
7
+ * initial release
8
+
data/CREDITS.md ADDED
@@ -0,0 +1,3 @@
1
+
2
+ # colorato credits
3
+
data/LICENSE.txt ADDED
@@ -0,0 +1,24 @@
1
+
2
+ Copyright (c) 2015-2023, John Mettraux, jmettraux+flor@gmail.com
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in
12
+ all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
+ THE SOFTWARE.
21
+
22
+
23
+ Made in Japan
24
+
data/README.md ADDED
@@ -0,0 +1,10 @@
1
+
2
+ # colorato
3
+
4
+ ANSI colours tool. Taken out of [flor](https://github.com/floraison/flor).
5
+
6
+
7
+ ## LICENSE
8
+
9
+ MIT, see [LICENSE.txt](LICENSE.txt)
10
+
data/colorato.gemspec ADDED
@@ -0,0 +1,47 @@
1
+
2
+ Gem::Specification.new do |s|
3
+
4
+ s.name = 'colorato'
5
+
6
+ s.version = File.read(
7
+ File.expand_path('../lib/colorato.rb', __FILE__)
8
+ ).match(/ VERSION *= *['"]([^'"]+)/)[1]
9
+
10
+ s.platform = Gem::Platform::RUBY
11
+ s.authors = [ 'John Mettraux' ]
12
+ s.email = [ 'jmettraux+flor@gmail.com' ]
13
+ s.homepage = 'https://github.com/floraison/colorato'
14
+ s.license = 'MIT'
15
+ s.summary = 'terminal colors for flor'
16
+
17
+ s.description = %{
18
+ terminal colors extracted from flor
19
+ }.strip
20
+
21
+ s.metadata = {
22
+ 'changelog_uri' => s.homepage + '/blob/master/CHANGELOG.md',
23
+ 'documentation_uri' => s.homepage,
24
+ 'bug_tracker_uri' => s.homepage + '/issues',
25
+ #'mailing_list_uri' => 'https://groups.google.com/forum/#!forum/floraison',
26
+ 'homepage_uri' => s.homepage,
27
+ 'source_code_uri' => s.homepage,
28
+ #'wiki_uri' => s.homepage + '/wiki',
29
+ }
30
+
31
+ #s.files = `git ls-files`.split("\n")
32
+ s.files = Dir[
33
+ 'README.{md,txt}',
34
+ 'CHANGELOG.{md,txt}', 'CREDITS.{md,txt}', 'LICENSE.{md,txt}',
35
+ #'Makefile',
36
+ 'lib/**/*.rb', #'spec/**/*.rb', 'test/**/*.rb',
37
+ "#{s.name}.gemspec",
38
+ ]
39
+
40
+ #s.add_runtime_dependency 'raabro', '~> 1.4'
41
+ #s.add_runtime_dependency 'et-orbi', '~> 1', '>= 1.2.7'
42
+
43
+ s.add_development_dependency 'rspec', '~> 3.12'
44
+
45
+ s.require_path = 'lib'
46
+ end
47
+
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Colorato
4
+
5
+ COLOURS = Hash[*%w[
6
+
7
+ reset 0;0
8
+
9
+ bright 1 dim 2 underlined 4 blink 5 reverse 7 hidden 8 strike 9 default 39
10
+
11
+ black 30 red 31 green 32 yellow 33 blue 34 magenta 35 cyan 36
12
+ light_gray 37 dark_gray 90 light_red 91 light_green 92 light_yellow 93
13
+ light_blue 94 light_magenta 95 light_cyan 96 white 97
14
+ bg_default 49 bg_black 40 bg_red 41 bg_green 42 bg_yellow 43 bg_blue 44
15
+ bg_magenta 45 bg_cyan 46 bg_light_gray 47 bg_dark_gray 100
16
+ bg_light_red 101 bg_light_green 102 bg_light_yellow 103
17
+ bg_light_blue 104 bg_light_magenta 105 bg_light_cyan 106 bg_white 107
18
+
19
+ brown yellow purple magenta dark_grey dark_gray light_grey light_gray
20
+
21
+ rd red bl blue bu blue ba black bk black gn green gr green dg dark_gray
22
+ gy light_gray lg light_gray yl yellow y yellow ma magenta wt white
23
+ rs reset
24
+ br bright bri bright un underlined rv reverse bn blink blg bg_light_gray
25
+ und underlined rev reverse
26
+
27
+ ]].freeze
28
+
29
+ class Colours
30
+
31
+ Colorato::COLOURS.each do |k, v|
32
+ if v.match(/\A\d/) # Ruby 2.3 doesn't have String#match?
33
+ class_eval(%{
34
+ def #{k}(s=nil)
35
+ s ? "[#{v}m" + s + "" : "[#{v}m"
36
+ end })
37
+ else
38
+ class_eval(
39
+ "alias #{k} #{v}")
40
+ end
41
+ end
42
+ end
43
+
44
+ class NoColours
45
+
46
+ Colorato::COLOURS.each do |k, v|
47
+ if v.match(/\A\d/) # Ruby 2.3 doesn't have String#match?
48
+ class_eval("def #{k}(s=''); s; end")
49
+ else
50
+ class_eval("alias #{k} #{v}")
51
+ end
52
+ end
53
+ end
54
+
55
+ @colours = Colours.new
56
+ @no_colours = NoColours.new
57
+
58
+ def self.no_colours
59
+
60
+ @no_colours
61
+ end
62
+
63
+ def self.colours(opts={})
64
+
65
+ c = nil;
66
+ [ :color, :colour, :colors, :colours ].each do |k|
67
+ if opts.has_key?(k); c = opts[k]; break; end
68
+ end
69
+
70
+ return @colours if c == true
71
+ return @no_colours if c == false
72
+
73
+ o = opts[:out] || $stdout
74
+
75
+ return @colours if (
76
+ (o.respond_to?(:log_colours?) ? o.log_colours? : o.tty?) ||
77
+ ($0[-6..-1] == '/rspec' &&
78
+ (ARGV.include?('--tty') || ARGV.include?('--color'))))
79
+
80
+ @no_colours
81
+ end
82
+ end
83
+
@@ -0,0 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Colorato; class << self
4
+
5
+ def decolour(s)
6
+
7
+ s.gsub(/\x1b\[\d+(;\d+)?m/, '')
8
+ end
9
+
10
+ def no_colour_length(s)
11
+
12
+ decolour(s).length
13
+ end
14
+
15
+ def truncate_string(s, maxlen, post='...')
16
+
17
+ ncl = no_colour_length(s)
18
+ r = StringIO.new
19
+ l = 0
20
+
21
+ s.scan(/(\x1b\[\d+(?:;\d+)?m|[^\x1b]+)/) do |ss, _|
22
+ if ss[0, 1] == ""
23
+ r << ss
24
+ else
25
+ ss = ss[0, maxlen - l]
26
+ r << ss
27
+ l += ss.length
28
+ break if l >= maxlen
29
+ end
30
+ end
31
+
32
+ return r.string if l < maxlen
33
+
34
+ if post.is_a?(String)
35
+ r << post
36
+ elsif post.is_a?(Proc)
37
+ r << post.call(ncl, maxlen, s)
38
+ end
39
+
40
+ r.string
41
+ end
42
+
43
+ alias decolor decolour
44
+
45
+ alias bw_length no_colour_length
46
+ alias nocolor_length no_colour_length
47
+ alias no_color_length no_colour_length
48
+ alias nocolour_length no_colour_length
49
+ end; end
50
+
51
+
52
+ #if $0 == __FILE__
53
+ #
54
+ # puts "# frozen_string_literal: true"
55
+ # puts
56
+ # puts "module Colorato; class << self"
57
+ # Colorato::COLOURS.each do |k, v|
58
+ # if v.match?(/\A\d/)
59
+ # puts " def #{k}(s=nil); s ? \"[#{v}m\#{s}\" : \"[#{v}m\"; end"
60
+ # else
61
+ # puts " alias #{k} #{v}"
62
+ # end
63
+ # end
64
+ # puts "end; end"
65
+ # puts
66
+ # puts "module NoColorato; class << self"
67
+ # Colorato::COLOURS.each do |k, v|
68
+ # if v.match?(/\A\d/)
69
+ # puts " def #{k}(s=nil); s ? s : ''; end"
70
+ # else
71
+ # puts " alias #{k} #{v}"
72
+ # end
73
+ # end
74
+ # puts "end; end"
75
+ #end
76
+
data/lib/colorato.rb ADDED
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+
4
+ module Colorato
5
+
6
+ VERSION = '0.9.0'
7
+ end
8
+
9
+ require 'colorato/core'
10
+ require 'colorato/module'
11
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: colorato
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - John Mettraux
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-01-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.12'
27
+ description: terminal colors extracted from flor
28
+ email:
29
+ - jmettraux+flor@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - CHANGELOG.md
35
+ - CREDITS.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - colorato.gemspec
39
+ - lib/colorato.rb
40
+ - lib/colorato/core.rb
41
+ - lib/colorato/module.rb
42
+ homepage: https://github.com/floraison/colorato
43
+ licenses:
44
+ - MIT
45
+ metadata:
46
+ changelog_uri: https://github.com/floraison/colorato/blob/master/CHANGELOG.md
47
+ documentation_uri: https://github.com/floraison/colorato
48
+ bug_tracker_uri: https://github.com/floraison/colorato/issues
49
+ homepage_uri: https://github.com/floraison/colorato
50
+ source_code_uri: https://github.com/floraison/colorato
51
+ post_install_message:
52
+ rdoc_options: []
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ required_rubygems_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ requirements: []
66
+ rubygems_version: 3.1.6
67
+ signing_key:
68
+ specification_version: 4
69
+ summary: terminal colors for flor
70
+ test_files: []