tty-color 0.3.0 → 0.6.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
- SHA1:
3
- metadata.gz: 172ef7053be12d6a8034734dbdb8762aff8e586a
4
- data.tar.gz: f656a2a75764ceded9756d72a48e95d37605158a
2
+ SHA256:
3
+ metadata.gz: 1f1b22f471c0d18b3217f7e551814833a38eb17ebef75ae6bf14c6f16feab74b
4
+ data.tar.gz: 9896b09d5e04483ba099330b9f0d81209cb04ad085fd6ec6ba3cbb26dfdb788a
5
5
  SHA512:
6
- metadata.gz: 2bd34dfe7dad34a85fd13429880c30fbd998e1a84e80c77788f9e5c4568e611d186d97b13d336cd4643ede0c641e5e07dc8ef98446a28183301a71b394375931
7
- data.tar.gz: fea1c61b20f4e201cadab45c43b05d5989c53ce6b01baae58edb96918d4e8f1b586e28004e09a54ad5eaa97cd1a4c3493528d9e03083e9f5e892a0c946553cfa
6
+ metadata.gz: c308f748d700a6cefe91b0e1ff320cb1b0d1d1ada66da2eff8d06caf350191db27ce13666da75117c4e8f4838850812e6792aebea115c1e8335efeeb9cc50afd
7
+ data.tar.gz: 8d252f931f7bc59cfd3526754ac1382e54513d9232fb017abf207a6c61eb99c3ef3f11cf4629f80943c54ef3f06ead8aa98dbe5c45ce54c9c7f5ba1dee557c55
data/CHANGELOG.md CHANGED
@@ -1,5 +1,68 @@
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
+
13
+ ## [v0.5.2] - 2020-08-09
14
+
15
+ ### Changed
16
+ * Change gemspec and remove bundler as dev dependency
17
+ * Change TTY::Color::Support to define verbose as keyword argument
18
+
19
+ ### Fix
20
+ * Fix gemspec metadata links by Igor Kapkov(@igas)
21
+
22
+ ## [v0.5.1] - 2020-01-22
23
+
24
+ ### Changed
25
+ * Change gemspec to add metadata and remove test artefacts
26
+
27
+ ## [v0.5.0] - 2019-05-29
28
+
29
+ ### Changed
30
+ * Change gemspec to load files without git
31
+ * Change to limit to Ruby >= 2.0.0
32
+
33
+ ## [v0.4.3] - 2018-07-11
34
+
35
+ ### Changed
36
+ * Change to use relative file paths
37
+ * Change to ensure immutable strings
38
+ * Change Color to use alias call
39
+
40
+ ### Fixed
41
+ * Fix to support iTerm 2.app for 256 color mode detection by Michael Lang(@mwlang)
42
+
43
+ ## [v0.4.2] - 2017-02-06
44
+
45
+ ### Fixed
46
+ * Fix File namespaces
47
+
48
+ ## [v0.4.1] - 2017-01-22
49
+
50
+ ### Fixed
51
+ * Fix #windows? to reference top level constant
52
+
53
+ ## [v0.4.0] - 2016-12-27
54
+
55
+ ### Added
56
+ * Add #command? helper
57
+ * Add #windows? helper
58
+
59
+ ### Changed
60
+ * Change to stop checking curses on Windows
61
+
62
+ ### Fixed
63
+ * Fix Support#from_tput check to fail gracefully on non-unix systems
64
+ * Fix Mode#from_tput check to fail gracefuly on non-unix systems
65
+
3
66
  ## [v0.3.0] - 2016-01-13
4
67
 
5
68
  ### Fixed
@@ -20,6 +83,14 @@
20
83
 
21
84
  * Initial implementation and release
22
85
 
23
- [v0.3.0]: https://github.com/peter-murach/tty-color/compare/v0.2.0...v0.3.0
24
- [v0.2.0]: https://github.com/peter-murach/tty-color/compare/v0.1.0...v0.2.0
25
- [v0.1.0]: https://github.com/peter-murach/tty-color/compare/v0.1.0
86
+ [v0.6.0]: https://github.com/piotrmurach/tty-color/compare/v0.5.2...v0.6.0
87
+ [v0.5.2]: https://github.com/piotrmurach/tty-color/compare/v0.5.1...v0.5.2
88
+ [v0.5.1]: https://github.com/piotrmurach/tty-color/compare/v0.5.0...v0.5.1
89
+ [v0.5.0]: https://github.com/piotrmurach/tty-color/compare/v0.4.3...v0.5.0
90
+ [v0.4.3]: https://github.com/piotrmurach/tty-color/compare/v0.4.2...v0.4.3
91
+ [v0.4.2]: https://github.com/piotrmurach/tty-color/compare/v0.4.1...v0.4.2
92
+ [v0.4.1]: https://github.com/piotrmurach/tty-color/compare/v0.4.0...v0.4.1
93
+ [v0.4.0]: https://github.com/piotrmurach/tty-color/compare/v0.3.0...v0.4.0
94
+ [v0.3.0]: https://github.com/piotrmurach/tty-color/compare/v0.2.0...v0.3.0
95
+ [v0.2.0]: https://github.com/piotrmurach/tty-color/compare/v0.1.0...v0.2.0
96
+ [v0.1.0]: https://github.com/piotrmurach/tty-color/compare/v0.1.0
data/LICENSE.txt CHANGED
@@ -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,26 +1,34 @@
1
- # TTY::Color
1
+ <div align="center">
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
+ </div>
4
+
5
+ # TTY::Color [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter]
6
+
2
7
  [![Gem Version](https://badge.fury.io/rb/tty-color.svg)][gem]
3
- [![Build Status](https://secure.travis-ci.org/peter-murach/tty-color.svg?branch=master)][travis]
4
- [![Code Climate](https://codeclimate.com/github/peter-murach/tty-color/badges/gpa.svg)][codeclimate]
5
- [![Coverage Status](https://coveralls.io/repos/peter-murach/tty-color/badge.svg)][coverage]
6
- [![Inline docs](http://inch-ci.org/github/peter-murach/tty-color.svg?branch=master)][inchpages]
8
+ [![Build Status](https://secure.travis-ci.org/piotrmurach/tty-color.svg?branch=master)][travis]
9
+ [![Build status](https://ci.appveyor.com/api/projects/status/j1nflklmnfrb2yrf?svg=true)][appveyor]
10
+ [![Code Climate](https://codeclimate.com/github/piotrmurach/tty-color/badges/gpa.svg)][codeclimate]
11
+ [![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-color/badge.svg)][coverage]
12
+ [![Inline docs](http://inch-ci.org/github/piotrmurach/tty-color.svg?branch=master)][inchpages]
7
13
 
14
+ [gitter]: https://gitter.im/piotrmurach/tty
8
15
  [gem]: http://badge.fury.io/rb/tty-color
9
- [travis]: http://travis-ci.org/peter-murach/tty-color
10
- [codeclimate]: https://codeclimate.com/github/peter-murach/tty-color
11
- [coverage]: https://coveralls.io/r/peter-murach/tty-color
12
- [inchpages]: http://inch-ci.org/github/peter-murach/tty-color
16
+ [travis]: http://travis-ci.org/piotrmurach/tty-color
17
+ [appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-color
18
+ [codeclimate]: https://codeclimate.com/github/piotrmurach/tty-color
19
+ [coverage]: https://coveralls.io/github/piotrmurach/tty-color
20
+ [inchpages]: http://inch-ci.org/github/piotrmurach/tty-color
13
21
 
14
22
  > Terminal color capabilities detection.
15
23
 
16
- **TTY::Color** provides independent color support detection component for [TTY](https://github.com/peter-murach/tty) toolkit.
24
+ **TTY::Color** provides independent color support detection component for [TTY](https://github.com/piotrmurach/tty) toolkit.
17
25
 
18
26
  ## Installation
19
27
 
20
28
  Add this line to your application's Gemfile:
21
29
 
22
30
  ```ruby
23
- gem 'tty-color'
31
+ gem "tty-color"
24
32
  ```
25
33
 
26
34
  And then execute:
@@ -36,16 +44,22 @@ Or install it yourself as:
36
44
  **TTY::Color** allows you to check if terminal supports color:
37
45
 
38
46
  ```ruby
39
- TTY::Color.color? # => true
40
- TTY::Color.supports? # => true
47
+ TTY::Color.color? # => true
48
+ TTY::Color.support? # => true
41
49
  ```
42
50
 
43
- 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:
44
52
 
45
53
  ```ruby
46
54
  TTY::Color.mode # => 64
47
55
  ```
48
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
+
49
63
  **TTY::Color** is just a module hence you can include it into your scripts directly:
50
64
 
51
65
  ```ruby
@@ -58,28 +72,44 @@ puts color?
58
72
 
59
73
  ## Command line tool
60
74
 
61
- [tty-color-cli](https://github.com/peter-murach/tty-color-cli) is a command line tool for the **TTY::Color**.
75
+ [tty-color-cli](https://github.com/piotrmurach/tty-color-cli) is a command line tool for the **TTY::Color**.
62
76
 
63
- To check if terminal supports colors do:
77
+ To check if terminal supports colors use `-s|--support`:
64
78
 
65
79
  ```bash
66
- color -s
80
+ tty-color -s
81
+ tty-color --support
82
+ # => true
67
83
  ```
68
84
 
69
- and to check color mode:
85
+ And to check color mode use `-m|--mode` option:
70
86
 
71
87
  ```bash
72
- color -m
88
+ tty-color -m
89
+ tty-color --mode
90
+ # => 256
73
91
  ```
74
92
 
93
+ ## Development
94
+
95
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+
97
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
98
+
75
99
  ## Contributing
76
100
 
77
- 1. Fork it ( https://github.com/peter-murach/tty-color/fork )
101
+ Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/tty-color. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
102
+
103
+ 1. Fork it ( https://github.com/piotrmurach/tty-color/fork )
78
104
  2. Create your feature branch (`git checkout -b my-new-feature`)
79
105
  3. Commit your changes (`git commit -am 'Add some feature'`)
80
106
  4. Push to the branch (`git push origin my-new-feature`)
81
107
  5. Create a new Pull Request
82
108
 
109
+ ## Code of Conduct
110
+
111
+ Everyone interacting in the TTY::Color project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/piotrmurach/tty-color/blob/master/CODE_OF_CONDUCT.md).
112
+
83
113
  ## Copyright
84
114
 
85
115
  Copyright (c) 2016 Piotr Murach. See LICENSE for further details.
@@ -1,25 +1,32 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  module Color
5
5
  class Mode
6
- TERM_256 = /iTerm.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
26
+
27
+ TERM_8 = /vt100|xnuppc|wy350/x.freeze
21
28
 
22
- TERM_8 = /vt100|xnuppc|wy350/x
29
+ METHODS = %w[from_term from_tput].freeze
23
30
 
24
31
  def initialize(env)
25
32
  @env = env
@@ -28,14 +35,14 @@ module TTY
28
35
  # Detect supported colors
29
36
  #
30
37
  # @return [Integer]
31
- # out of 0, 8, 16, 52, 64, 256
38
+ # out of 0, 8, 16, 52, 66, 256, 2^24
32
39
  #
33
40
  # @api public
34
41
  def mode
35
42
  return 0 unless TTY::Color.tty?
36
43
 
37
44
  value = 8
38
- %w(from_term from_tput).each do |from_check|
45
+ METHODS.each do |from_check|
39
46
  break if (value = public_send(from_check)) != NoValue
40
47
  end
41
48
  return 8 if value == NoValue
@@ -48,15 +55,16 @@ module TTY
48
55
  #
49
56
  # @api private
50
57
  def from_term
51
- case @env['TERM']
52
- when /[\-\+](\d+)color/ then $1.to_i
53
- when /[\-\+](\d+)bit/ then 2 ** $1.to_i
58
+ case @env["TERM"]
59
+ when TERM_24BIT then TRUECOLORS
60
+ when /[-+](\d+)color/ then $1.to_i
61
+ when /[-+](\d+)bit/ then 2**$1.to_i
54
62
  when TERM_256 then 256
55
63
  when TERM_64 then 64
56
64
  when TERM_52 then 52
57
65
  when TERM_16 then 16
58
66
  when TERM_8 then 8
59
- when /dummy/ then 0
67
+ when /dummy/ then 0
60
68
  else NoValue
61
69
  end
62
70
  end
@@ -67,6 +75,8 @@ module TTY
67
75
  #
68
76
  # @api private
69
77
  def from_tput
78
+ return NoValue unless TTY::Color.command?("tput colors")
79
+
70
80
  colors = `tput colors 2>/dev/null`.to_i
71
81
  colors >= 8 ? colors : NoValue
72
82
  rescue Errno::ENOENT
@@ -1,15 +1,35 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  module Color
5
5
  class Support
6
- SOURCES = %w(from_term from_tput from_env from_curses).freeze
6
+ SOURCES = %w[from_term from_tput from_env from_curses].freeze
7
+ ENV_VARS = %w[COLORTERM ANSICON].freeze
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
7
27
 
8
28
  # Initialize a color support
9
29
  # @api public
10
- def initialize(env, options = {})
30
+ def initialize(env, verbose: false)
11
31
  @env = env
12
- @verbose = options.fetch(:verbose) { false }
32
+ @verbose = verbose
13
33
  end
14
34
 
15
35
  # Detect if terminal supports color
@@ -18,24 +38,35 @@ module TTY
18
38
  # true when terminal supports color, false otherwise
19
39
  #
20
40
  # @api public
21
- def supports?
41
+ def support?
22
42
  return false unless TTY::Color.tty?
43
+ return false if disabled?
23
44
 
24
45
  value = false
25
46
  SOURCES.each do |from_check|
26
47
  break if (value = public_send(from_check)) != NoValue
27
48
  end
28
- return false if value == NoValue
29
- value
49
+ value == NoValue ? false : value
50
+ end
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?)
30
61
  end
31
62
 
32
63
  # Inspect environment $TERM variable for color support
33
64
  #
34
65
  # @api private
35
66
  def from_term
36
- case @env['TERM']
37
- when 'dumb' then false
38
- when /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i then true
67
+ case @env["TERM"]
68
+ when "dumb" then false
69
+ when TERM_REGEX then true
39
70
  else NoValue
40
71
  end
41
72
  end
@@ -44,6 +75,8 @@ module TTY
44
75
  #
45
76
  # @api private
46
77
  def from_tput
78
+ return NoValue unless TTY::Color.command?("tput colors")
79
+
47
80
  `tput colors 2>/dev/null`.to_i > 2
48
81
  rescue Errno::ENOENT
49
82
  NoValue
@@ -53,7 +86,7 @@ module TTY
53
86
  #
54
87
  # @api private
55
88
  def from_env
56
- ['COLORTERM', 'ANSICON'].any? { |key| @env.key?(key) } || NoValue
89
+ ENV_VARS.any? { |key| @env.key?(key) } || NoValue
57
90
  end
58
91
 
59
92
  # Attempt to load curses to check color support
@@ -62,19 +95,20 @@ module TTY
62
95
  #
63
96
  # @api private
64
97
  def from_curses(curses_class = nil)
65
- require 'curses'
98
+ return NoValue if TTY::Color.windows?
99
+
100
+ require "curses"
66
101
 
67
102
  if defined?(Curses)
68
103
  curses_class ||= Curses
69
104
  curses_class.init_screen
70
105
  has_color = curses_class.has_colors?
71
106
  curses_class.close_screen
72
- has_color
73
- else
74
- NoValue
107
+ return has_color
75
108
  end
109
+ NoValue
76
110
  rescue LoadError
77
- warn 'no native curses support' if @verbose
111
+ warn "no native curses support" if @verbose
78
112
  NoValue
79
113
  end
80
114
  end # Support
@@ -1,7 +1,7 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
3
  module TTY
4
4
  module Color
5
- VERSION = "0.3.0"
5
+ VERSION = "0.6.0"
6
6
  end # Color
7
7
  end # TTY
data/lib/tty/color.rb CHANGED
@@ -1,8 +1,8 @@
1
- # encoding: utf-8
1
+ # frozen_string_literal: true
2
2
 
3
- require 'tty/color/support'
4
- require 'tty/color/mode'
5
- require 'tty/color/version'
3
+ require_relative "color/mode"
4
+ require_relative "color/support"
5
+ require_relative "color/version"
6
6
 
7
7
  module TTY
8
8
  # Responsible for checking terminal color support
@@ -24,11 +24,22 @@ module TTY
24
24
  # @return [Boolean]
25
25
  #
26
26
  # @api public
27
- def supports?
28
- Support.new(ENV, verbose: verbose).supports?
27
+ def support?
28
+ Support.new(ENV, verbose: verbose).support?
29
+ end
30
+ alias supports? support?
31
+ alias color? support?
32
+ alias supports_color? support?
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?
29
42
  end
30
- alias_method :color?, :supports?
31
- alias_method :supports_color?, :supports?
32
43
 
33
44
  # Check how many colors this terminal supports
34
45
  #
@@ -47,5 +58,23 @@ module TTY
47
58
  def tty?
48
59
  output.respond_to?(:tty?) && output.tty?
49
60
  end
61
+
62
+ # Check if command can be run
63
+ #
64
+ # @return [Boolean]
65
+ #
66
+ # @api public
67
+ def command?(cmd)
68
+ !!system(cmd, out: ::File::NULL, err: ::File::NULL)
69
+ end
70
+
71
+ # Check if Windowz
72
+ #
73
+ # @return [Boolean]
74
+ #
75
+ # @api public
76
+ def windows?
77
+ ::File::ALT_SEPARATOR == "\\"
78
+ end
50
79
  end # Color
51
80
  end # TTY
data/lib/tty-color.rb CHANGED
@@ -1,4 +1 @@
1
- # encoding: utf-8
2
-
3
- require 'tty/color'
4
- require "tty/color/version"
1
+ require_relative "tty/color"
metadata CHANGED
@@ -1,104 +1,88 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-color
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Murach
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-13 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
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: 1.5.0
20
- - - <
17
+ - - ">="
21
18
  - !ruby/object:Gem::Version
22
- version: '2.0'
19
+ version: '0'
23
20
  type: :development
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 1.5.0
30
- - - <
31
- - !ruby/object:Gem::Version
32
- version: '2.0'
26
+ version: '0'
33
27
  - !ruby/object:Gem::Dependency
34
- name: rake
28
+ name: rspec
35
29
  requirement: !ruby/object:Gem::Requirement
36
30
  requirements:
37
- - - ~>
31
+ - - ">="
38
32
  - !ruby/object:Gem::Version
39
- version: '10.0'
33
+ version: '3.0'
40
34
  type: :development
41
35
  prerelease: false
42
36
  version_requirements: !ruby/object:Gem::Requirement
43
37
  requirements:
44
- - - ~>
38
+ - - ">="
45
39
  - !ruby/object:Gem::Version
46
- version: '10.0'
40
+ version: '3.0'
47
41
  description: Terminal color capabilities detection
48
42
  email:
49
- - ''
43
+ - piotr@piotrmurach.com
50
44
  executables: []
51
45
  extensions: []
52
- extra_rdoc_files: []
46
+ extra_rdoc_files:
47
+ - README.md
48
+ - CHANGELOG.md
49
+ - LICENSE.txt
53
50
  files:
54
- - .gitignore
55
- - .rspec
56
- - .travis.yml
57
51
  - CHANGELOG.md
58
- - Gemfile
59
52
  - LICENSE.txt
60
53
  - README.md
61
- - Rakefile
62
54
  - lib/tty-color.rb
63
55
  - lib/tty/color.rb
64
56
  - lib/tty/color/mode.rb
65
57
  - lib/tty/color/support.rb
66
58
  - lib/tty/color/version.rb
67
- - spec/spec_helper.rb
68
- - spec/unit/color_spec.rb
69
- - spec/unit/mode_spec.rb
70
- - spec/unit/supports_spec.rb
71
- - tasks/console.rake
72
- - tasks/coverage.rake
73
- - tasks/spec.rake
74
- - tty-color.gemspec
75
- homepage: http://peter-murach.github.io/tty
59
+ homepage: https://ttytoolkit.org
76
60
  licenses:
77
61
  - MIT
78
- metadata: {}
62
+ metadata:
63
+ allowed_push_host: https://rubygems.org
64
+ bug_tracker_uri: https://github.com/piotrmurach/tty-color/issues
65
+ changelog_uri: https://github.com/piotrmurach/tty-color/blob/master/CHANGELOG.md
66
+ documentation_uri: https://www.rubydoc.info/gems/tty-color
67
+ homepage_uri: https://ttytoolkit.org
68
+ source_code_uri: https://github.com/piotrmurach/tty-color
79
69
  post_install_message:
80
70
  rdoc_options: []
81
71
  require_paths:
82
72
  - lib
83
73
  required_ruby_version: !ruby/object:Gem::Requirement
84
74
  requirements:
85
- - - '>='
75
+ - - ">="
86
76
  - !ruby/object:Gem::Version
87
- version: '0'
77
+ version: 2.0.0
88
78
  required_rubygems_version: !ruby/object:Gem::Requirement
89
79
  requirements:
90
- - - '>='
80
+ - - ">="
91
81
  - !ruby/object:Gem::Version
92
82
  version: '0'
93
83
  requirements: []
94
- rubyforge_project:
95
- rubygems_version: 2.0.3
84
+ rubygems_version: 3.1.2
96
85
  signing_key:
97
86
  specification_version: 4
98
87
  summary: Terminal color capabilities detection
99
- test_files:
100
- - spec/spec_helper.rb
101
- - spec/unit/color_spec.rb
102
- - spec/unit/mode_spec.rb
103
- - spec/unit/supports_spec.rb
104
- has_rdoc:
88
+ test_files: []
data/.gitignore DELETED
@@ -1,14 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /Gemfile.lock
4
- /_yardoc/
5
- /coverage/
6
- /doc/
7
- /pkg/
8
- /spec/reports/
9
- /tmp/
10
- *.bundle
11
- *.so
12
- *.o
13
- *.a
14
- mkmf.log
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --color
2
- --require spec_helper
3
- --warnings
data/.travis.yml DELETED
@@ -1,23 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- bundler_args: --without yard benchmarks
6
- script: "bundle exec rake ci"
7
- rvm:
8
- - 1.9.3
9
- - 2.0
10
- - 2.1
11
- - 2.2
12
- - rbx-2
13
- - jruby-19mode
14
- - jruby
15
- - jruby-head
16
- - ruby-head
17
- matrix:
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
21
- fast_finish: true
22
- branches:
23
- only: master
data/Gemfile DELETED
@@ -1,15 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'rspec', '~> 3.4.0'
7
- gem 'yard', '~> 0.8.7'
8
- gem 'benchmark-ips', '~> 2.0.0'
9
- end
10
-
11
- group :metrics do
12
- gem 'coveralls', '~> 0.8.2'
13
- gem 'simplecov', '~> 0.10.0'
14
- gem 'yardstick', '~> 0.9.9'
15
- end
data/Rakefile DELETED
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require "bundler/gem_tasks"
4
-
5
- FileList['tasks/**/*.rake'].each(&method(:import))
6
-
7
- desc 'Run all specs'
8
- task ci: %w[ spec ]
data/spec/spec_helper.rb DELETED
@@ -1,45 +0,0 @@
1
- # encoding: utf-8
2
-
3
- if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS'])
4
- require 'simplecov'
5
- require 'coveralls'
6
-
7
- SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
8
- SimpleCov::Formatter::HTMLFormatter,
9
- Coveralls::SimpleCov::Formatter
10
- ]
11
-
12
- SimpleCov.start do
13
- command_name 'spec'
14
- add_filter 'spec'
15
- end
16
- end
17
-
18
- require 'tty-color'
19
-
20
- RSpec.configure do |config|
21
- config.expect_with :rspec do |expectations|
22
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
23
- end
24
-
25
- config.mock_with :rspec do |mocks|
26
- mocks.verify_partial_doubles = true
27
- end
28
-
29
- # Limits the available syntax to the non-monkey patched syntax that is recommended.
30
- config.disable_monkey_patching!
31
-
32
- # This setting enables warnings. It's recommended, but in some cases may
33
- # be too noisy due to issues in dependencies.
34
- config.warnings = true
35
-
36
- if config.files_to_run.one?
37
- config.default_formatter = 'doc'
38
- end
39
-
40
- config.profile_examples = 2
41
-
42
- config.order = :random
43
-
44
- Kernel.srand config.seed
45
- end
@@ -1,21 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Color, 'integratation' do
4
- it "accesses color mode" do
5
- mode_instance = spy(:mode)
6
- allow(TTY::Color::Mode).to receive(:new).and_return(mode_instance)
7
-
8
- described_class.mode
9
-
10
- expect(mode_instance).to have_received(:mode)
11
- end
12
-
13
- it "accesses color support" do
14
- support_instance = spy(:support)
15
- allow(TTY::Color::Support).to receive(:new).and_return(support_instance)
16
-
17
- described_class.supports?
18
-
19
- expect(support_instance).to have_received(:supports?)
20
- end
21
- end
@@ -1,94 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Color::Mode, 'detecting mode' do
4
- it "isn't terminal" do
5
- allow(TTY::Color).to receive(:tty?).and_return(false)
6
- mode = described_class.new({})
7
- expect(mode.mode).to eq(0)
8
- end
9
-
10
- it "cannot find from term, tput " do
11
- allow(TTY::Color).to receive(:tty?).and_return(true)
12
- mode = described_class.new({})
13
- allow(mode).to receive(:from_term).and_return(TTY::Color::NoValue)
14
- allow(mode).to receive(:from_tput).and_return(TTY::Color::NoValue)
15
-
16
- expect(mode.mode).to eq(8)
17
- expect(mode).to have_received(:from_term).ordered
18
- expect(mode).to have_received(:from_tput).ordered
19
- end
20
-
21
- it "detects color mode" do
22
- allow(TTY::Color).to receive(:tty?).and_return(true)
23
- mode = described_class.new('TERM' => 'xterm-256color')
24
-
25
- expect(mode.mode).to eq(256)
26
- end
27
-
28
- context '#from_term' do
29
- it 'infers mode for xterm-256color' do
30
- mode = described_class.new('TERM' => 'xterm-256color')
31
- expect(mode.from_term).to eq(256)
32
- end
33
-
34
- it 'infers mode for iTerm.app' do
35
- mode = described_class.new('TERM' => 'iTerm.app')
36
- expect(mode.from_term).to eq(256)
37
- end
38
-
39
- it 'infers mode from terminal environment' do
40
- mode = described_class.new('TERM' => 'amiga-8bit')
41
- expect(mode.from_term).to eq(256)
42
- end
43
-
44
- it 'infers mode for wy730' do
45
- mode = described_class.new('TERM' => 'wy370-105k')
46
- expect(mode.from_term).to eq(64)
47
- end
48
-
49
- it 'infers mode for d430-unix-ccc' do
50
- mode = described_class.new('TERM' => 'd430-unix-ccc')
51
- expect(mode.from_term).to eq(52)
52
- end
53
-
54
- it 'infers mode for d430-unix-s-ccc' do
55
- mode = described_class.new('TERM' => 'd430c-unix-s-ccc')
56
- expect(mode.from_term).to eq(52)
57
- end
58
-
59
- it 'infers mode for nsterm-bce' do
60
- mode = described_class.new('TERM' => 'nsterm-bce')
61
- expect(mode.from_term).to eq(16)
62
- end
63
-
64
- it 'infers mode for d430-c' do
65
- mode = described_class.new('TERM' => 'd430c-dg')
66
- expect(mode.from_term).to eq(16)
67
- end
68
-
69
- it 'infers mode for d430-unix-w' do
70
- mode = described_class.new('TERM' => 'd430-unix-w')
71
- expect(mode.from_term).to eq(16)
72
- end
73
-
74
- it 'infers mode for vt100' do
75
- mode = described_class.new('TERM' => 'konsole-vt100')
76
- expect(mode.from_term).to eq(8)
77
- end
78
-
79
- it 'infers mode for xnuppc' do
80
- mode = described_class.new('TERM' => 'xnuppc+basic')
81
- expect(mode.from_term).to eq(8)
82
- end
83
-
84
- it 'infers mode fro dummy terminal' do
85
- mode = described_class.new('TERM' => 'dummy')
86
- expect(mode.from_term).to eq(0)
87
- end
88
-
89
- it "doesn't match any term variable" do
90
- mode = described_class.new({})
91
- expect(mode.from_term).to eq(TTY::Color::NoValue)
92
- end
93
- end
94
- end
@@ -1,112 +0,0 @@
1
- # encoding: utf-8
2
-
3
- RSpec.describe TTY::Color::Support, '#supports?' do
4
- it "doesn't check color support for non tty terminal" do
5
- support = described_class.new({})
6
- allow(TTY::Color).to receive(:tty?).and_return(false)
7
- expect(support.supports?).to eq(false)
8
- end
9
-
10
- it "fails to find out color support" do
11
- support = described_class.new({})
12
- allow(TTY::Color).to receive(:tty?).and_return(true)
13
-
14
- allow(support).to receive(:from_curses).and_return(TTY::Color::NoValue)
15
- allow(support).to receive(:from_tput).and_return(TTY::Color::NoValue)
16
- allow(support).to receive(:from_term).and_return(TTY::Color::NoValue)
17
- allow(support).to receive(:from_env).and_return(TTY::Color::NoValue)
18
-
19
- expect(support.supports?).to eq(false)
20
-
21
- expect(support).to have_received(:from_term).ordered
22
- expect(support).to have_received(:from_tput).ordered
23
- expect(support).to have_received(:from_env).ordered
24
- expect(support).to have_received(:from_curses).ordered
25
- end
26
-
27
- it "detects color support" do
28
- support = described_class.new('TERM' => 'xterm')
29
- allow(TTY::Color).to receive(:tty?).and_return(true)
30
- allow(support).to receive(:from_tput)
31
-
32
- expect(support.supports?).to eq(true)
33
- expect(support).to_not have_received(:from_tput)
34
- end
35
-
36
- context '#from_curses' do
37
- it "fails to load curses for color support" do
38
- support = described_class.new({})
39
- allow(support).to receive(:require).with('curses').
40
- and_raise(LoadError)
41
- allow(support).to receive(:warn)
42
-
43
- expect(support.from_curses).to eq(TTY::Color::NoValue)
44
- expect(support).to_not have_received(:warn)
45
- end
46
-
47
- it "fails to find Curses namespace" do
48
- support = described_class.new({})
49
- allow(support).to receive(:require).with('curses')
50
-
51
- expect(support.from_curses).to eq(TTY::Color::NoValue)
52
- end
53
-
54
- it "sets verbose mode on" do
55
- support = described_class.new({}, verbose: true)
56
- allow(support).to receive(:require).with('curses').
57
- and_raise(LoadError)
58
- allow(support).to receive(:warn)
59
-
60
- support.from_curses
61
-
62
- expect(support).to have_received(:warn).with(/no native curses support/)
63
- end
64
-
65
- it "loads curses for color support" do
66
- support = described_class.new({})
67
- allow(support).to receive(:require).with('curses').and_return(true)
68
- stub_const("Curses", Object.new)
69
- curses = double(:curses)
70
- allow(curses).to receive(:init_screen)
71
- allow(curses).to receive(:has_colors?).and_return(true)
72
- allow(curses).to receive(:close_screen)
73
-
74
- expect(support.from_curses(curses)).to eql(true)
75
- expect(curses).to have_received(:has_colors?)
76
- end
77
- end
78
-
79
- context '#form_term' do
80
- it "fails to find color for dumb terminal" do
81
- support = described_class.new('TERM' => 'dumb')
82
- expect(support.from_term).to eq(false)
83
- end
84
-
85
- it "inspects term variable for color capabilities" do
86
- support = described_class.new('TERM' => 'xterm')
87
- expect(support.from_term).to eq(true)
88
- end
89
-
90
- it "fails to find color capabilities from term variable " do
91
- support = described_class.new('TERM' => 'atari')
92
- expect(support.from_term).to eq(TTY::Color::NoValue)
93
- end
94
- end
95
-
96
- context '#from_env' do
97
- it "finds color support in colorterm variable" do
98
- support = described_class.new('COLORTERM' => true)
99
- expect(support.from_env).to eq(true)
100
- end
101
-
102
- it "finds ansicon support" do
103
- support = described_class.new('ANSICON' => true)
104
- expect(support.from_env).to eq(true)
105
- end
106
-
107
- it "doesn't find any keys in environment" do
108
- support = described_class.new({})
109
- expect(support.from_env).to eq(TTY::Color::NoValue)
110
- end
111
- end
112
- end
data/tasks/console.rake DELETED
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Load gem inside irb console'
4
- task :console do
5
- require 'irb'
6
- require 'irb/completion'
7
- require File.join(__FILE__, '../../lib/tty-color')
8
- ARGV.clear
9
- IRB.start
10
- end
data/tasks/coverage.rake DELETED
@@ -1,11 +0,0 @@
1
- # encoding: utf-8
2
-
3
- desc 'Measure code coverage'
4
- task :coverage do
5
- begin
6
- original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true'
7
- Rake::Task['spec'].invoke
8
- ensure
9
- ENV['COVERAGE'] = original
10
- end
11
- end
data/tasks/spec.rake DELETED
@@ -1,29 +0,0 @@
1
- # encoding: utf-8
2
-
3
- begin
4
- require 'rspec/core/rake_task'
5
-
6
- desc 'Run all specs'
7
- RSpec::Core::RakeTask.new(:spec) do |task|
8
- task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb'
9
- end
10
-
11
- namespace :spec do
12
- desc 'Run unit specs'
13
- RSpec::Core::RakeTask.new(:unit) do |task|
14
- task.pattern = 'spec/unit{,/*/**}/*_spec.rb'
15
- end
16
-
17
- desc 'Run integration specs'
18
- RSpec::Core::RakeTask.new(:integration) do |task|
19
- task.pattern = 'spec/integration{,/*/**}/*_spec.rb'
20
- end
21
- end
22
-
23
- rescue LoadError
24
- %w[spec spec:unit spec:integration].each do |name|
25
- task name do
26
- $stderr.puts "In order to run #{name}, do `gem install rspec`"
27
- end
28
- end
29
- end
data/tty-color.gemspec DELETED
@@ -1,23 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'tty/color/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = 'tty-color'
8
- spec.version = TTY::Color::VERSION
9
- spec.authors = ['Piotr Murach']
10
- spec.email = [""]
11
- spec.summary = %q{Terminal color capabilities detection}
12
- spec.description = %q{Terminal color capabilities detection}
13
- spec.homepage = "http://peter-murach.github.io/tty"
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^spec})
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency 'bundler', '>= 1.5.0', '< 2.0'
22
- spec.add_development_dependency 'rake', '~> 10.0'
23
- end