colorato 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6a04ec628455d986e1a98d0046ee1b63b1f046c1bc6d7018ef5cf2524998e18e
4
- data.tar.gz: 947d85416c2d2f2a2d28645f97858788886a58b5c4088ac4b4bb55917ca781aa
3
+ metadata.gz: bad7d3caff47acf5a90642ad8fdf76cd2f31a1a5b638e87784d844dcdfcd52f0
4
+ data.tar.gz: 888331e557f8ce33b6671945d0df95a8933403c792ae6d473c480ae3fe06917c
5
5
  SHA512:
6
- metadata.gz: 261f7abe0f7bebe479efae920db1ccc976c547ea2e312e1406b7efa637d0273e1eb77483b6945e63b6c3204c61389c40ef7172db1f4ca6e1bc0d64be8889add1
7
- data.tar.gz: 968df424e0014f91f5cbe5fce37b51576790ecfd04453e6a88d168e2b096b8de9cbd617b765eef0cf76c0c96c5adf8c765794cad3364daa7c9db4f9b20f85764
6
+ metadata.gz: 4ceade3164671b98971fa803e45235ff63fb2fe94c65d842cccc270975e6127f02070324f548eafb2a3840df3d7d835e19992e155bd8a39694442ac83d9cb243
7
+ data.tar.gz: b28e0e7d7045e2efaffe119eb1ac67aeb90e592c798aadaeb584a3c2eaf2cd5be8e4594551ceb6d739ff5db21e432753c9237cbd073e0f1c7853bb12f662bee0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
  # colorato
3
3
 
4
4
 
5
+ ## 1.2.0 released 2026-10-18
6
+
7
+ * Introduce Colorato .colour_if_tty and .colour_if_supported
8
+ * Sort colour names in .show_colours
9
+
10
+
11
+ ## 1.1.0 released 2025-01-16
12
+
13
+ * Colorato.blue { 'blo' + 'ck' }
14
+ * Show the colours when `ruby lib/colorato.rb`
15
+
16
+
5
17
  ## 1.0.0 released 2023-01-03
6
18
 
7
19
  * Introduce `make colo.rb`
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2015-2023, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2015-2026, John Mettraux, jmettraux+flor@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -14,8 +14,10 @@ NC = Colorato.nocolours
14
14
 
15
15
  C.blue # => "\e[34m"
16
16
  C.blue('car') # => "\e[34mcar\e[0;0m"
17
+ C.blue { 'car' } # => "\e[34mcar\e[0;0m"
17
18
 
18
19
  NC.blue('car') # => "car"
20
+ NC.blue { 'car' } # => "car"
19
21
  ```
20
22
 
21
23
  ### .decolour(string)
data/colorato.gemspec CHANGED
@@ -26,6 +26,7 @@ terminal colors extracted from flor
26
26
  'homepage_uri' => s.homepage,
27
27
  'source_code_uri' => s.homepage,
28
28
  #'wiki_uri' => s.homepage + '/wiki',
29
+ 'rubygems_mfa_required' => 'true',
29
30
  }
30
31
 
31
32
  #s.files = `git ls-files`.split("\n")
@@ -40,7 +41,8 @@ terminal colors extracted from flor
40
41
  #s.add_runtime_dependency 'raabro', '~> 1.4'
41
42
  #s.add_runtime_dependency 'et-orbi', '~> 1', '>= 1.2.7'
42
43
 
43
- s.add_development_dependency 'rspec', '~> 3.12'
44
+ #s.add_development_dependency 'rspec', '~> 3.12'
45
+ s.add_development_dependency 'probatio', '~> 1'
44
46
 
45
47
  s.require_path = 'lib'
46
48
  end
data/lib/colorato/core.rb CHANGED
@@ -12,6 +12,7 @@ module Colorato
12
12
  black 30 red 31 green 32 yellow 33 blue 34 magenta 35 cyan 36
13
13
  light_gray 37 dark_gray 90 light_red 91 light_green 92 light_yellow 93
14
14
  light_blue 94 light_magenta 95 light_cyan 96 white 97
15
+
15
16
  bg_default 49 bg_black 40 bg_red 41 bg_green 42 bg_yellow 43 bg_blue 44
16
17
  bg_magenta 45 bg_cyan 46 bg_light_gray 47 bg_dark_gray 100
17
18
  bg_light_red 101 bg_light_green 102 bg_light_yellow 103
@@ -35,16 +36,14 @@ module Colorato
35
36
  if v.match(/\A\d/) # Ruby 2.3 doesn't have String#match?
36
37
 
37
38
  ::Colorato::Colours.class_eval(%{
38
- def #{k}(s=nil)
39
- s ?
40
- "\e[#{v}m\#{s}\e[0;0m" :
39
+ def #{k}(s=nil, &block)
40
+ (x = (block && block.call) || s) ?
41
+ "\e[#{v}m\#{x}\e[0;0m" :
41
42
  "\e[#{v}m"
42
43
  end })
43
44
  ::Colorato::NoColours.class_eval(%{
44
- def #{k}(s=nil)
45
- s ?
46
- s :
47
- ''
45
+ def #{k}(s=nil, &block)
46
+ (x = (block && block.call) || s) ? x : ''
48
47
  end })
49
48
 
50
49
  else
@@ -70,6 +69,69 @@ module Colorato
70
69
  alias colors colours
71
70
  alias nocolors no_colours
72
71
  alias no_colors no_colours
72
+
73
+ def colour_if_tty(out=$stdout)
74
+
75
+ return (out.tty? rescue false) ? colours : no_colours
76
+ end
77
+ alias color_if_tty colour_if_tty
78
+
79
+ def colour_if_supported(out=$stdout)
80
+
81
+ return no_colours unless out.tty?
82
+
83
+ return no_colours if ENV['NO_COLOR']
84
+
85
+ return no_colours if ENV['FORCE_COLOR'] || ENV['FORCE_COLOUR']
86
+ # colorato...
87
+
88
+ return colours if ENV['COLORTERM']
89
+
90
+ t = ENV['TERM']
91
+
92
+ return colours if t == nil
93
+ return no_colours if t == 'dumb'
94
+
95
+ #return colours if t == 'screen'
96
+ #return colours if t.include?('color')
97
+ #return colours if t.include?('xterm')
98
+
99
+ colours
100
+ end
101
+ alias color_if_supported colour_if_supported
102
+
103
+ def show_colours
104
+
105
+ cs = Colorato.colours.public_methods
106
+ .inject([]) { |a, n|
107
+ m = n.to_s.match(/^bg_(.+)$/)
108
+ a << m[1] if m
109
+ a }
110
+ .sort
111
+
112
+ #%w[ (default) bright dim ].each do |filter|
113
+
114
+ puts
115
+
116
+ fs = %w[ (def) bright dim ]
117
+
118
+ puts "%14s %-9s %-9s %-9s" % ([ '' ] + fs)
119
+ puts
120
+
121
+ cs.each do |n|
122
+ a = [ n ]
123
+ fs.each do |f|
124
+ f = Colorato.colours.send(f) rescue ''
125
+ fgc = f + Colorato.colours.send(n)
126
+ bgc = f + Colorato.colours.send("bg_#{n}")
127
+ a << (fgc + 'Text' + Colorato.colours.reset)
128
+ a << (bgc + ' ' + Colorato.colours.reset)
129
+ end
130
+ puts "%14s: %s %s %s %s %s %s" % a
131
+ end
132
+
133
+ puts
134
+ end
73
135
  end
74
136
  end
75
137
 
data/lib/colorato/more.rb CHANGED
@@ -55,4 +55,3 @@ module Colorato; class << self
55
55
  alias nocolour_length no_colour_length
56
56
  end; end
57
57
 
58
-
data/lib/colorato.rb CHANGED
@@ -3,9 +3,12 @@
3
3
 
4
4
  module Colorato
5
5
 
6
- VERSION = '1.0.0'
6
+ VERSION = '1.2.0'
7
7
  end
8
8
 
9
9
  require 'colorato/core'
10
10
  require 'colorato/more'
11
11
 
12
+
13
+ Colorato.show_colours if __FILE__ == $0
14
+
metadata CHANGED
@@ -1,29 +1,28 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: colorato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-01-03 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: rspec
13
+ name: probatio
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '3.12'
18
+ version: '1'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '3.12'
25
+ version: '1'
27
26
  description: terminal colors extracted from flor
28
27
  email:
29
28
  - jmettraux+flor@gmail.com
@@ -48,7 +47,7 @@ metadata:
48
47
  bug_tracker_uri: https://github.com/floraison/colorato/issues
49
48
  homepage_uri: https://github.com/floraison/colorato
50
49
  source_code_uri: https://github.com/floraison/colorato
51
- post_install_message:
50
+ rubygems_mfa_required: 'true'
52
51
  rdoc_options: []
53
52
  require_paths:
54
53
  - lib
@@ -63,8 +62,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
63
62
  - !ruby/object:Gem::Version
64
63
  version: '0'
65
64
  requirements: []
66
- rubygems_version: 3.1.6
67
- signing_key:
65
+ rubygems_version: 3.6.9
68
66
  specification_version: 4
69
67
  summary: terminal colors for flor
70
68
  test_files: []