tty-color 0.5.2 → 0.6.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: 0e15fe9b9cd238ffaf8dc33f932e1435ec56ce4c6c3f1074fe3a6dc0bdaa24a5
4
- data.tar.gz: 298d8b7d999481827b971216d9189b933c11f7b20cbb745dc3b0c49de84e382f
3
+ metadata.gz: 1f1b22f471c0d18b3217f7e551814833a38eb17ebef75ae6bf14c6f16feab74b
4
+ data.tar.gz: 9896b09d5e04483ba099330b9f0d81209cb04ad085fd6ec6ba3cbb26dfdb788a
5
5
  SHA512:
6
- metadata.gz: 7d821ce739f310a20759eb1297bf3c3c4079b0fb34b1102b927222d013c3eafe5bbbf74edd08084ff983f2ddcd52192d4b0e3f7d3d3c78bb081d5facc1e84dfb
7
- data.tar.gz: 6dbe41556440dd9dea0f5329dc5a6384cc1ae7e7b968db341f58a781741867ea8169937c849a5c0dcc97ab88df0a88f5077bae9b43dea23dfdc8ff436b8d0856
6
+ metadata.gz: c308f748d700a6cefe91b0e1ff320cb1b0d1d1ada66da2eff8d06caf350191db27ce13666da75117c4e8f4838850812e6792aebea115c1e8335efeeb9cc50afd
7
+ data.tar.gz: 8d252f931f7bc59cfd3526754ac1382e54513d9232fb017abf207a6c61eb99c3ef3f11cf4629f80943c54ef3f06ead8aa98dbe5c45ce54c9c7f5ba1dee557c55
@@ -1,5 +1,15 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.6.0] - 2020-11-07
4
+
5
+ ### Added
6
+ * Add 24bit color aka "direct color" aka "truecolor" by @nevans
7
+ * Add support for NO_COLOR env var by @nevans
8
+
9
+ ### Changed
10
+ * Change to freeze all regular expressions
11
+ * Change to increase test coverage to 100%
12
+
3
13
  ## [v0.5.2] - 2020-08-09
4
14
 
5
15
  ### Changed
@@ -73,6 +83,7 @@
73
83
 
74
84
  * Initial implementation and release
75
85
 
86
+ [v0.6.0]: https://github.com/piotrmurach/tty-color/compare/v0.5.2...v0.6.0
76
87
  [v0.5.2]: https://github.com/piotrmurach/tty-color/compare/v0.5.1...v0.5.2
77
88
  [v0.5.1]: https://github.com/piotrmurach/tty-color/compare/v0.5.0...v0.5.1
78
89
  [v0.5.0]: https://github.com/piotrmurach/tty-color/compare/v0.4.3...v0.5.0
@@ -1,4 +1,4 @@
1
- Copyright (c) 2016 Piotr Murach
1
+ Copyright (c) 2016 Piotr Murach (https://piotrmurach.com)
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  <div align="center">
2
- <a href="https://piotrmurach.github.io/tty" target="_blank"><img width="130" src="https://cdn.rawgit.com/piotrmurach/tty/master/images/tty.png" alt="tty logo" /></a>
2
+ <a href="https://ttytoolkit.org"><img width="130" src="https://github.com/piotrmurach/tty/raw/master/images/tty.png" alt="TTY Toolkit logo"/></a>
3
3
  </div>
4
4
 
5
5
  # TTY::Color [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
@@ -28,7 +28,7 @@
28
28
  Add this line to your application's Gemfile:
29
29
 
30
30
  ```ruby
31
- gem 'tty-color'
31
+ gem "tty-color"
32
32
  ```
33
33
 
34
34
  And then execute:
@@ -48,12 +48,18 @@ TTY::Color.color? # => true
48
48
  TTY::Color.support? # => true
49
49
  ```
50
50
 
51
- Also you can get the number of colors supported by the terminal:
51
+ You can also get the number of colors supported by the terminal using `mode` method:
52
52
 
53
53
  ```ruby
54
54
  TTY::Color.mode # => 64
55
55
  ```
56
56
 
57
+ To detect if color support has been disabled with `NO_COLOR` environment variable, use `disabled?`:
58
+
59
+ ```ruby
60
+ TTY::Color.disabled? # => false
61
+ ```
62
+
57
63
  **TTY::Color** is just a module hence you can include it into your scripts directly:
58
64
 
59
65
  ```ruby
@@ -1 +1 @@
1
- require "tty/color"
1
+ require_relative "tty/color"
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "color/support"
4
3
  require_relative "color/mode"
4
+ require_relative "color/support"
5
5
  require_relative "color/version"
6
6
 
7
7
  module TTY
@@ -31,6 +31,16 @@ module TTY
31
31
  alias color? support?
32
32
  alias supports_color? support?
33
33
 
34
+ # Detect if color support has been disabled with NO_COLOR ENV var.
35
+ #
36
+ # @return [Boolean]
37
+ # true when terminal color support has been disabled, false otherwise
38
+ #
39
+ # @api public
40
+ def disabled?
41
+ Support.new(ENV, verbose: verbose).disabled?
42
+ end
43
+
34
44
  # Check how many colors this terminal supports
35
45
  #
36
46
  # @return [Integer]
@@ -3,23 +3,28 @@
3
3
  module TTY
4
4
  module Color
5
5
  class Mode
6
- TERM_256 = /iTerm(\s\d+){0,1}.app/x
6
+ TERM_24BIT = /[+-]direct/.freeze
7
+ TRUECOLORS = 2**24 # 8 bits per RGB channel
8
+
9
+ TERM_256 = /^(alacritty|iTerm\s?\d*\.app|kitty|mintty|ms-terminal|
10
+ nsterm|nsterm-build\d+|terminator|terminology(-[0-9.]+)?|
11
+ termite|vscode)$/x.freeze
7
12
 
8
13
  TERM_64 = /^(hpterm-color|wy370|wy370-105k|wy370-EPC|wy370-nk|
9
- wy370-rv|wy370-tek|wy370-vb|wy370-w|wy370-wvb)$/x
14
+ wy370-rv|wy370-tek|wy370-vb|wy370-w|wy370-wvb)$/x.freeze
10
15
 
11
- TERM_52 = /^(dg+ccc|dgunix+ccc|d430.*?[\-\+](dg|unix).*?[\-\+]ccc)$/x
16
+ TERM_52 = /^(dg+ccc|dgunix+ccc|d430.*?[-+](dg|unix).*?[-+]ccc)$/x.freeze
12
17
 
13
18
  TERM_16 = /^(amiga-vnc|d430-dg|d430-unix|d430-unix-25|d430-unix-s|
14
19
  d430-unix-sr|d430-unix-w|d430c-dg|d430c-unix|d430c-unix-25|
15
20
  d430c-unix-s|d430c-unix-sr|d430c-unix-w|d470|d470-7b|d470-dg|
16
21
  d470c|d470c-7b|d470c-dg|dg+color|dg\+fixed|dgunix\+fixed|
17
22
  dgmode\+color|hp\+color|ncr260wy325pp|ncr260wy325wpp|
18
- ncr260wy350pp|ncr260wy350wpp|nsterm|nsterm-c|nsterm-c-acs|
23
+ ncr260wy350pp|ncr260wy350wpp|nsterm-c|nsterm-c-acs|
19
24
  nsterm-c-s|nsterm-c-s-7|nsterm-c-s-acs|nsterm\+c|
20
- nsterm-7-c|nsterm-bce)$/x
25
+ nsterm-7-c|nsterm-bce)$/x.freeze
21
26
 
22
- TERM_8 = /vt100|xnuppc|wy350/x
27
+ TERM_8 = /vt100|xnuppc|wy350/x.freeze
23
28
 
24
29
  METHODS = %w[from_term from_tput].freeze
25
30
 
@@ -30,7 +35,7 @@ module TTY
30
35
  # Detect supported colors
31
36
  #
32
37
  # @return [Integer]
33
- # out of 0, 8, 16, 52, 64, 256
38
+ # out of 0, 8, 16, 52, 66, 256, 2^24
34
39
  #
35
40
  # @api public
36
41
  def mode
@@ -51,8 +56,9 @@ module TTY
51
56
  # @api private
52
57
  def from_term
53
58
  case @env["TERM"]
54
- when /[\-\+](\d+)color/ then $1.to_i
55
- when /[\-\+](\d+)bit/ then 2 ** $1.to_i
59
+ when TERM_24BIT then TRUECOLORS
60
+ when /[-+](\d+)color/ then $1.to_i
61
+ when /[-+](\d+)bit/ then 2**$1.to_i
56
62
  when TERM_256 then 256
57
63
  when TERM_64 then 64
58
64
  when TERM_52 then 52
@@ -69,9 +75,8 @@ module TTY
69
75
  #
70
76
  # @api private
71
77
  def from_tput
72
- if !TTY::Color.command?("tput colors")
73
- return NoValue
74
- end
78
+ return NoValue unless TTY::Color.command?("tput colors")
79
+
75
80
  colors = `tput colors 2>/dev/null`.to_i
76
81
  colors >= 8 ? colors : NoValue
77
82
  rescue Errno::ENOENT
@@ -6,6 +6,25 @@ module TTY
6
6
  SOURCES = %w[from_term from_tput from_env from_curses].freeze
7
7
  ENV_VARS = %w[COLORTERM ANSICON].freeze
8
8
 
9
+ TERM_REGEX = /
10
+ color| # explicitly claims color support in the name
11
+ direct| # explicitly claims "direct color" (24 bit) support
12
+
13
+ #{Mode::TERM_256}|
14
+ #{Mode::TERM_64}|
15
+ #{Mode::TERM_52}|
16
+ #{Mode::TERM_16}|
17
+ #{Mode::TERM_8}|
18
+
19
+ ^ansi(\.sys.*)?$|
20
+ ^cygwin|
21
+ ^linux|
22
+ ^putty|
23
+ ^rxvt|
24
+ ^screen|
25
+ ^tmux|
26
+ ^xterm/xi.freeze
27
+
9
28
  # Initialize a color support
10
29
  # @api public
11
30
  def initialize(env, verbose: false)
@@ -21,6 +40,7 @@ module TTY
21
40
  # @api public
22
41
  def support?
23
42
  return false unless TTY::Color.tty?
43
+ return false if disabled?
24
44
 
25
45
  value = false
26
46
  SOURCES.each do |from_check|
@@ -29,13 +49,24 @@ module TTY
29
49
  value == NoValue ? false : value
30
50
  end
31
51
 
52
+ # Detect if color support has been disabled with NO_COLOR ENV var.
53
+ #
54
+ # @return [Boolean]
55
+ # true when terminal color support has been disabled, false otherwise
56
+ #
57
+ # @api public
58
+ def disabled?
59
+ no_color = @env["NO_COLOR"]
60
+ !(no_color.nil? || no_color.empty?)
61
+ end
62
+
32
63
  # Inspect environment $TERM variable for color support
33
64
  #
34
65
  # @api private
35
66
  def from_term
36
67
  case @env["TERM"]
37
68
  when "dumb" then false
38
- when /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i then true
69
+ when TERM_REGEX then true
39
70
  else NoValue
40
71
  end
41
72
  end
@@ -44,10 +75,9 @@ module TTY
44
75
  #
45
76
  # @api private
46
77
  def from_tput
47
- return NoValue if !TTY::Color.command?("tput colors")
78
+ return NoValue unless TTY::Color.command?("tput colors")
48
79
 
49
- cmd = %q(tput colors 2>/dev/null)
50
- `#{cmd}`.to_i > 2
80
+ `tput colors 2>/dev/null`.to_i > 2
51
81
  rescue Errno::ENOENT
52
82
  NoValue
53
83
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module TTY
4
4
  module Color
5
- VERSION = "0.5.2"
5
+ VERSION = "0.6.0"
6
6
  end # Color
7
7
  end # TTY
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-color
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-09 00:00:00.000000000 Z
11
+ date: 2020-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake