tty-color 0.4.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
- SHA1:
3
- metadata.gz: ddd23cb1f08a561d67b7bb22fd2e83b8621febfc
4
- data.tar.gz: 761c1a2893c56f269f7c31b88c96d68cb1372477
2
+ SHA256:
3
+ metadata.gz: 1f1b22f471c0d18b3217f7e551814833a38eb17ebef75ae6bf14c6f16feab74b
4
+ data.tar.gz: 9896b09d5e04483ba099330b9f0d81209cb04ad085fd6ec6ba3cbb26dfdb788a
5
5
  SHA512:
6
- metadata.gz: cc87ed4227b710475aeec4264a3fccb6a3f397cdc4d8d3401c0dd4bb27d5fc55709bc89693afcc6f5b2e01ab99df98ae283f36fb5746fe4b0f8b0a90ee132823
7
- data.tar.gz: 6e705c3da4f766ff6f23bdb2d84a02627ef4445ae845389a33138be075687b168c22fc570063eb0bc75c0320ea35934ca3beb4abae29981a4d5a560edffd51b0
6
+ metadata.gz: c308f748d700a6cefe91b0e1ff320cb1b0d1d1ada66da2eff8d06caf350191db27ce13666da75117c4e8f4838850812e6792aebea115c1e8335efeeb9cc50afd
7
+ data.tar.gz: 8d252f931f7bc59cfd3526754ac1382e54513d9232fb017abf207a6c61eb99c3ef3f11cf4629f80943c54ef3f06ead8aa98dbe5c45ce54c9c7f5ba1dee557c55
@@ -1,5 +1,45 @@
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
+
3
43
  ## [v0.4.2] - 2017-02-06
4
44
 
5
45
  ### Fixed
@@ -43,9 +83,14 @@
43
83
 
44
84
  * Initial implementation and release
45
85
 
46
- [v0.4.2]: https://github.com/peter-murach/tty-color/compare/v0.4.1...v0.4.2
47
- [v0.4.1]: https://github.com/peter-murach/tty-color/compare/v0.4.0...v0.4.1
48
- [v0.4.0]: https://github.com/peter-murach/tty-color/compare/v0.3.0...v0.4.0
49
- [v0.3.0]: https://github.com/peter-murach/tty-color/compare/v0.2.0...v0.3.0
50
- [v0.2.0]: https://github.com/peter-murach/tty-color/compare/v0.1.0...v0.2.0
51
- [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
@@ -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,4 +1,9 @@
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
+
1
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
8
  [![Build Status](https://secure.travis-ci.org/piotrmurach/tty-color.svg?branch=master)][travis]
4
9
  [![Build status](https://ci.appveyor.com/api/projects/status/j1nflklmnfrb2yrf?svg=true)][appveyor]
@@ -23,7 +28,7 @@
23
28
  Add this line to your application's Gemfile:
24
29
 
25
30
  ```ruby
26
- gem 'tty-color'
31
+ gem "tty-color"
27
32
  ```
28
33
 
29
34
  And then execute:
@@ -39,16 +44,22 @@ Or install it yourself as:
39
44
  **TTY::Color** allows you to check if terminal supports color:
40
45
 
41
46
  ```ruby
42
- TTY::Color.color? # => true
43
- TTY::Color.supports? # => true
47
+ TTY::Color.color? # => true
48
+ TTY::Color.support? # => true
44
49
  ```
45
50
 
46
- 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:
47
52
 
48
53
  ```ruby
49
54
  TTY::Color.mode # => 64
50
55
  ```
51
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
+
52
63
  **TTY::Color** is just a module hence you can include it into your scripts directly:
53
64
 
54
65
  ```ruby
@@ -63,26 +74,42 @@ puts color?
63
74
 
64
75
  [tty-color-cli](https://github.com/piotrmurach/tty-color-cli) is a command line tool for the **TTY::Color**.
65
76
 
66
- To check if terminal supports colors do:
77
+ To check if terminal supports colors use `-s|--support`:
67
78
 
68
79
  ```bash
69
- color -s
80
+ tty-color -s
81
+ tty-color --support
82
+ # => true
70
83
  ```
71
84
 
72
- and to check color mode:
85
+ And to check color mode use `-m|--mode` option:
73
86
 
74
87
  ```bash
75
- color -m
88
+ tty-color -m
89
+ tty-color --mode
90
+ # => 256
76
91
  ```
77
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
+
78
99
  ## Contributing
79
100
 
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
+
80
103
  1. Fork it ( https://github.com/piotrmurach/tty-color/fork )
81
104
  2. Create your feature branch (`git checkout -b my-new-feature`)
82
105
  3. Commit your changes (`git commit -am 'Add some feature'`)
83
106
  4. Push to the branch (`git push origin my-new-feature`)
84
107
  5. Create a new Pull Request
85
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
+
86
113
  ## Copyright
87
114
 
88
- Copyright (c) 2016-2017 Piotr Murach. See LICENSE for further details.
115
+ Copyright (c) 2016 Piotr Murach. See LICENSE for further details.
@@ -1,4 +1 @@
1
- # encoding: utf-8
2
-
3
- require 'tty/color'
4
- require "tty/color/version"
1
+ require_relative "tty/color"
@@ -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
  #
@@ -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,9 +55,10 @@ 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
@@ -67,9 +75,8 @@ module TTY
67
75
  #
68
76
  # @api private
69
77
  def from_tput
70
- if !TTY::Color.command?("tput colors")
71
- return NoValue
72
- end
78
+ return NoValue unless TTY::Color.command?("tput colors")
79
+
73
80
  colors = `tput colors 2>/dev/null`.to_i
74
81
  colors >= 8 ? colors : NoValue
75
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,11 +75,9 @@ module TTY
44
75
  #
45
76
  # @api private
46
77
  def from_tput
47
- cmd = %q(tput colors 2>/dev/null)
48
- if !TTY::Color.command?("tput colors")
49
- return NoValue
50
- end
51
- `#{cmd}`.to_i > 2
78
+ return NoValue unless TTY::Color.command?("tput colors")
79
+
80
+ `tput colors 2>/dev/null`.to_i > 2
52
81
  rescue Errno::ENOENT
53
82
  NoValue
54
83
  end
@@ -57,7 +86,7 @@ module TTY
57
86
  #
58
87
  # @api private
59
88
  def from_env
60
- ['COLORTERM', 'ANSICON'].any? { |key| @env.key?(key) } || NoValue
89
+ ENV_VARS.any? { |key| @env.key?(key) } || NoValue
61
90
  end
62
91
 
63
92
  # Attempt to load curses to check color support
@@ -67,7 +96,8 @@ module TTY
67
96
  # @api private
68
97
  def from_curses(curses_class = nil)
69
98
  return NoValue if TTY::Color.windows?
70
- require 'curses'
99
+
100
+ require "curses"
71
101
 
72
102
  if defined?(Curses)
73
103
  curses_class ||= Curses
@@ -78,7 +108,7 @@ module TTY
78
108
  end
79
109
  NoValue
80
110
  rescue LoadError
81
- warn 'no native curses support' if @verbose
111
+ warn "no native curses support" if @verbose
82
112
  NoValue
83
113
  end
84
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.4.2"
5
+ VERSION = "0.6.0"
6
6
  end # Color
7
7
  end # TTY
metadata CHANGED
@@ -1,82 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tty-color
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
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: 2017-02-06 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
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.0
20
- - - "<"
21
- - !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
- - appveyor.yml
63
54
  - lib/tty-color.rb
64
55
  - lib/tty/color.rb
65
56
  - lib/tty/color/mode.rb
66
57
  - lib/tty/color/support.rb
67
58
  - lib/tty/color/version.rb
68
- - spec/spec_helper.rb
69
- - spec/unit/color_spec.rb
70
- - spec/unit/mode_spec.rb
71
- - spec/unit/supports_spec.rb
72
- - tasks/console.rake
73
- - tasks/coverage.rake
74
- - tasks/spec.rake
75
- - tty-color.gemspec
76
- homepage: http://piotrmurach.github.io/tty
59
+ homepage: https://ttytoolkit.org
77
60
  licenses:
78
61
  - MIT
79
- 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
80
69
  post_install_message:
81
70
  rdoc_options: []
82
71
  require_paths:
@@ -85,21 +74,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
74
  requirements:
86
75
  - - ">="
87
76
  - !ruby/object:Gem::Version
88
- version: '0'
77
+ version: 2.0.0
89
78
  required_rubygems_version: !ruby/object:Gem::Requirement
90
79
  requirements:
91
80
  - - ">="
92
81
  - !ruby/object:Gem::Version
93
82
  version: '0'
94
83
  requirements: []
95
- rubyforge_project:
96
- rubygems_version: 2.5.1
84
+ rubygems_version: 3.1.2
97
85
  signing_key:
98
86
  specification_version: 4
99
87
  summary: Terminal color capabilities detection
100
- test_files:
101
- - spec/spec_helper.rb
102
- - spec/unit/color_spec.rb
103
- - spec/unit/mode_spec.rb
104
- - spec/unit/supports_spec.rb
105
- 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
@@ -1,26 +0,0 @@
1
- ---
2
- language: ruby
3
- sudo: false
4
- cache: bundler
5
- script: "bundle exec rake ci"
6
- rvm:
7
- - 1.9.3
8
- - 2.0.0
9
- - 2.1.10
10
- - 2.2.6
11
- - 2.3.3
12
- - 2.4.0
13
- - ruby-head
14
- - jruby-9000
15
- - jruby-head
16
- - rbx-3
17
- matrix:
18
- allow_failures:
19
- - rvm: ruby-head
20
- - rvm: jruby-head
21
- - rvm: rbx-3
22
- fast_finish: true
23
- branches:
24
- only: master
25
- notifications:
26
- email: false
data/Gemfile DELETED
@@ -1,16 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- group :development do
6
- gem 'rspec', '~> 3.5.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
- gem 'term-ansicolor', '=1.3.2'
16
- 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 ]
@@ -1,23 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake ci
10
- environment:
11
- matrix:
12
- - ruby_version: "193"
13
- - ruby_version: "200"
14
- - ruby_version: "200-x64"
15
- - ruby_version: "21"
16
- - ruby_version: "21-x64"
17
- - ruby_version: "22"
18
- - ruby_version: "22-x64"
19
- - ruby_version: "23"
20
- - ruby_version: "23-x64"
21
- matrix:
22
- allow_failures:
23
- - ruby_version: "193"
@@ -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,103 +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
-
95
- context '#from_tput' do
96
- it "fails to find tput utilty" do
97
- mode = described_class.new({})
98
- cmd = "tput colors"
99
- allow(TTY::Color).to receive(:command?).with(cmd).and_return(nil)
100
- expect(mode.from_tput).to eq(TTY::Color::NoValue)
101
- end
102
- end
103
- end
@@ -1,129 +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(TTY::Color).to receive(:windows?).and_return(false)
40
- allow(support).to receive(:require).with('curses').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(TTY::Color).to receive(:windows?).and_return(false)
50
- allow(support).to receive(:require).with('curses')
51
-
52
- expect(support.from_curses).to eq(TTY::Color::NoValue)
53
- end
54
-
55
- it "sets verbose mode on" do
56
- support = described_class.new({}, verbose: true)
57
- allow(TTY::Color).to receive(:windows?).and_return(false)
58
- allow(support).to receive(:require).with('curses').and_raise(LoadError)
59
- allow(support).to receive(:warn)
60
-
61
- support.from_curses
62
-
63
- expect(support).to have_received(:warn).with(/no native curses support/)
64
- end
65
-
66
- it "loads curses for color support" do
67
- support = described_class.new({})
68
- allow(TTY::Color).to receive(:windows?).and_return(false)
69
- allow(support).to receive(:require).with('curses').and_return(true)
70
- stub_const("Curses", Object.new)
71
- curses = double(:curses)
72
- allow(curses).to receive(:init_screen)
73
- allow(curses).to receive(:has_colors?).and_return(true)
74
- allow(curses).to receive(:close_screen)
75
-
76
- expect(support.from_curses(curses)).to eql(true)
77
- expect(curses).to have_received(:has_colors?)
78
- end
79
-
80
- it "doesn't check on windows" do
81
- support = described_class.new({})
82
- allow(TTY::Color).to receive(:windows?).and_return(true)
83
- expect(support.from_curses).to eq(TTY::Color::NoValue)
84
- end
85
- end
86
-
87
- context '#form_term' do
88
- it "fails to find color for dumb terminal" do
89
- support = described_class.new('TERM' => 'dumb')
90
- expect(support.from_term).to eq(false)
91
- end
92
-
93
- it "inspects term variable for color capabilities" do
94
- support = described_class.new('TERM' => 'xterm')
95
- expect(support.from_term).to eq(true)
96
- end
97
-
98
- it "fails to find color capabilities from term variable " do
99
- support = described_class.new('TERM' => 'atari')
100
- expect(support.from_term).to eq(TTY::Color::NoValue)
101
- end
102
- end
103
-
104
- context '#from_tput' do
105
- it "fails to find tput utilty" do
106
- support = described_class.new({})
107
- cmd = "tput colors"
108
- allow(TTY::Color).to receive(:command?).with(cmd).and_return(nil)
109
- expect(support.from_tput).to eq(TTY::Color::NoValue)
110
- end
111
- end
112
-
113
- context '#from_env' do
114
- it "finds color support in colorterm variable" do
115
- support = described_class.new('COLORTERM' => true)
116
- expect(support.from_env).to eq(true)
117
- end
118
-
119
- it "finds ansicon support" do
120
- support = described_class.new('ANSICON' => true)
121
- expect(support.from_env).to eq(true)
122
- end
123
-
124
- it "doesn't find any keys in environment" do
125
- support = described_class.new({})
126
- expect(support.from_env).to eq(TTY::Color::NoValue)
127
- end
128
- end
129
- end
@@ -1,11 +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
11
- task c: :console
@@ -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
@@ -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
@@ -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://piotrmurach.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