tty-color 0.4.1 → 0.5.2

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: cff99f84bcdda1fe01b29386402c71a3d8a373d0
4
- data.tar.gz: dce987972527cc537f8a93246ca385a0a19d89b6
2
+ SHA256:
3
+ metadata.gz: 0e15fe9b9cd238ffaf8dc33f932e1435ec56ce4c6c3f1074fe3a6dc0bdaa24a5
4
+ data.tar.gz: 298d8b7d999481827b971216d9189b933c11f7b20cbb745dc3b0c49de84e382f
5
5
  SHA512:
6
- metadata.gz: 95111d6bb1ec69ff7aa4e9a3cd7a1517f4d35eca92ff0a330f626f2b4b65fbaf5051e983c73033b8c06cbf1995500966c13abc89304a7ca435e16a9ff6aeb8e5
7
- data.tar.gz: 2bca782ad5c0ff731e21f447a50deb5b57c4344e8481b2b25b1d25a0c904efd15fdbf825733c6a4a0d51b70aa9817e5e9840550dc29d262b6634bf3b5d59612d
6
+ metadata.gz: 7d821ce739f310a20759eb1297bf3c3c4079b0fb34b1102b927222d013c3eafe5bbbf74edd08084ff983f2ddcd52192d4b0e3f7d3d3c78bb081d5facc1e84dfb
7
+ data.tar.gz: 6dbe41556440dd9dea0f5329dc5a6384cc1ae7e7b968db341f58a781741867ea8169937c849a5c0dcc97ab88df0a88f5077bae9b43dea23dfdc8ff436b8d0856
@@ -1,5 +1,40 @@
1
1
  # Change log
2
2
 
3
+ ## [v0.5.2] - 2020-08-09
4
+
5
+ ### Changed
6
+ * Change gemspec and remove bundler as dev dependency
7
+ * Change TTY::Color::Support to define verbose as keyword argument
8
+
9
+ ### Fix
10
+ * Fix gemspec metadata links by Igor Kapkov(@igas)
11
+
12
+ ## [v0.5.1] - 2020-01-22
13
+
14
+ ### Changed
15
+ * Change gemspec to add metadata and remove test artefacts
16
+
17
+ ## [v0.5.0] - 2019-05-29
18
+
19
+ ### Changed
20
+ * Change gemspec to load files without git
21
+ * Change to limit to Ruby >= 2.0.0
22
+
23
+ ## [v0.4.3] - 2018-07-11
24
+
25
+ ### Changed
26
+ * Change to use relative file paths
27
+ * Change to ensure immutable strings
28
+ * Change Color to use alias call
29
+
30
+ ### Fixed
31
+ * Fix to support iTerm 2.app for 256 color mode detection by Michael Lang(@mwlang)
32
+
33
+ ## [v0.4.2] - 2017-02-06
34
+
35
+ ### Fixed
36
+ * Fix File namespaces
37
+
3
38
  ## [v0.4.1] - 2017-01-22
4
39
 
5
40
  ### Fixed
@@ -38,7 +73,13 @@
38
73
 
39
74
  * Initial implementation and release
40
75
 
41
- [v0.4.0]: https://github.com/peter-murach/tty-color/compare/v0.3.0...v0.4.0
42
- [v0.3.0]: https://github.com/peter-murach/tty-color/compare/v0.2.0...v0.3.0
43
- [v0.2.0]: https://github.com/peter-murach/tty-color/compare/v0.1.0...v0.2.0
44
- [v0.1.0]: https://github.com/peter-murach/tty-color/compare/v0.1.0
76
+ [v0.5.2]: https://github.com/piotrmurach/tty-color/compare/v0.5.1...v0.5.2
77
+ [v0.5.1]: https://github.com/piotrmurach/tty-color/compare/v0.5.0...v0.5.1
78
+ [v0.5.0]: https://github.com/piotrmurach/tty-color/compare/v0.4.3...v0.5.0
79
+ [v0.4.3]: https://github.com/piotrmurach/tty-color/compare/v0.4.2...v0.4.3
80
+ [v0.4.2]: https://github.com/piotrmurach/tty-color/compare/v0.4.1...v0.4.2
81
+ [v0.4.1]: https://github.com/piotrmurach/tty-color/compare/v0.4.0...v0.4.1
82
+ [v0.4.0]: https://github.com/piotrmurach/tty-color/compare/v0.3.0...v0.4.0
83
+ [v0.3.0]: https://github.com/piotrmurach/tty-color/compare/v0.2.0...v0.3.0
84
+ [v0.2.0]: https://github.com/piotrmurach/tty-color/compare/v0.1.0...v0.2.0
85
+ [v0.1.0]: https://github.com/piotrmurach/tty-color/compare/v0.1.0
data/README.md CHANGED
@@ -1,4 +1,9 @@
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>
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]
@@ -39,8 +44,8 @@ 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
51
  Also you can get the number of colors supported by the terminal:
@@ -63,26 +68,42 @@ puts color?
63
68
 
64
69
  [tty-color-cli](https://github.com/piotrmurach/tty-color-cli) is a command line tool for the **TTY::Color**.
65
70
 
66
- To check if terminal supports colors do:
71
+ To check if terminal supports colors use `-s|--support`:
67
72
 
68
73
  ```bash
69
- color -s
74
+ tty-color -s
75
+ tty-color --support
76
+ # => true
70
77
  ```
71
78
 
72
- and to check color mode:
79
+ And to check color mode use `-m|--mode` option:
73
80
 
74
81
  ```bash
75
- color -m
82
+ tty-color -m
83
+ tty-color --mode
84
+ # => 256
76
85
  ```
77
86
 
87
+ ## Development
88
+
89
+ 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.
90
+
91
+ 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).
92
+
78
93
  ## Contributing
79
94
 
95
+ 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.
96
+
80
97
  1. Fork it ( https://github.com/piotrmurach/tty-color/fork )
81
98
  2. Create your feature branch (`git checkout -b my-new-feature`)
82
99
  3. Commit your changes (`git commit -am 'Add some feature'`)
83
100
  4. Push to the branch (`git push origin my-new-feature`)
84
101
  5. Create a new Pull Request
85
102
 
103
+ ## Code of Conduct
104
+
105
+ 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).
106
+
86
107
  ## Copyright
87
108
 
88
- Copyright (c) 2016-2017 Piotr Murach. See LICENSE for further details.
109
+ 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 "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/support"
4
+ require_relative "color/mode"
5
+ require_relative "color/version"
6
6
 
7
7
  module TTY
8
8
  # Responsible for checking terminal color support
@@ -24,11 +24,12 @@ 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
29
  end
30
- alias_method :color?, :supports?
31
- alias_method :supports_color?, :supports?
30
+ alias supports? support?
31
+ alias color? support?
32
+ alias supports_color? support?
32
33
 
33
34
  # Check how many colors this terminal supports
34
35
  #
@@ -54,7 +55,7 @@ module TTY
54
55
  #
55
56
  # @api public
56
57
  def command?(cmd)
57
- !!system(cmd, out: File::NULL, err: File::NULL)
58
+ !!system(cmd, out: ::File::NULL, err: ::File::NULL)
58
59
  end
59
60
 
60
61
  # Check if Windowz
@@ -1,9 +1,9 @@
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_256 = /iTerm(\s\d+){0,1}.app/x
7
7
 
8
8
  TERM_64 = /^(hpterm-color|wy370|wy370-105k|wy370-EPC|wy370-nk|
9
9
  wy370-rv|wy370-tek|wy370-vb|wy370-w|wy370-wvb)$/x
@@ -21,6 +21,8 @@ module TTY
21
21
 
22
22
  TERM_8 = /vt100|xnuppc|wy350/x
23
23
 
24
+ METHODS = %w[from_term from_tput].freeze
25
+
24
26
  def initialize(env)
25
27
  @env = env
26
28
  end
@@ -35,7 +37,7 @@ module TTY
35
37
  return 0 unless TTY::Color.tty?
36
38
 
37
39
  value = 8
38
- %w(from_term from_tput).each do |from_check|
40
+ METHODS.each do |from_check|
39
41
  break if (value = public_send(from_check)) != NoValue
40
42
  end
41
43
  return 8 if value == NoValue
@@ -48,7 +50,7 @@ module TTY
48
50
  #
49
51
  # @api private
50
52
  def from_term
51
- case @env['TERM']
53
+ case @env["TERM"]
52
54
  when /[\-\+](\d+)color/ then $1.to_i
53
55
  when /[\-\+](\d+)bit/ then 2 ** $1.to_i
54
56
  when TERM_256 then 256
@@ -1,15 +1,16 @@
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
7
8
 
8
9
  # Initialize a color support
9
10
  # @api public
10
- def initialize(env, options = {})
11
+ def initialize(env, verbose: false)
11
12
  @env = env
12
- @verbose = options.fetch(:verbose) { false }
13
+ @verbose = verbose
13
14
  end
14
15
 
15
16
  # Detect if terminal supports color
@@ -18,23 +19,22 @@ module TTY
18
19
  # true when terminal supports color, false otherwise
19
20
  #
20
21
  # @api public
21
- def supports?
22
+ def support?
22
23
  return false unless TTY::Color.tty?
23
24
 
24
25
  value = false
25
26
  SOURCES.each do |from_check|
26
27
  break if (value = public_send(from_check)) != NoValue
27
28
  end
28
- return false if value == NoValue
29
- value
29
+ value == NoValue ? false : value
30
30
  end
31
31
 
32
32
  # Inspect environment $TERM variable for color support
33
33
  #
34
34
  # @api private
35
35
  def from_term
36
- case @env['TERM']
37
- when 'dumb' then false
36
+ case @env["TERM"]
37
+ when "dumb" then false
38
38
  when /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i then true
39
39
  else NoValue
40
40
  end
@@ -44,10 +44,9 @@ module TTY
44
44
  #
45
45
  # @api private
46
46
  def from_tput
47
+ return NoValue if !TTY::Color.command?("tput colors")
48
+
47
49
  cmd = %q(tput colors 2>/dev/null)
48
- if !TTY::Color.command?("tput colors")
49
- return NoValue
50
- end
51
50
  `#{cmd}`.to_i > 2
52
51
  rescue Errno::ENOENT
53
52
  NoValue
@@ -57,7 +56,7 @@ module TTY
57
56
  #
58
57
  # @api private
59
58
  def from_env
60
- ['COLORTERM', 'ANSICON'].any? { |key| @env.key?(key) } || NoValue
59
+ ENV_VARS.any? { |key| @env.key?(key) } || NoValue
61
60
  end
62
61
 
63
62
  # Attempt to load curses to check color support
@@ -67,7 +66,8 @@ module TTY
67
66
  # @api private
68
67
  def from_curses(curses_class = nil)
69
68
  return NoValue if TTY::Color.windows?
70
- require 'curses'
69
+
70
+ require "curses"
71
71
 
72
72
  if defined?(Curses)
73
73
  curses_class ||= Curses
@@ -78,7 +78,7 @@ module TTY
78
78
  end
79
79
  NoValue
80
80
  rescue LoadError
81
- warn 'no native curses support' if @verbose
81
+ warn "no native curses support" if @verbose
82
82
  NoValue
83
83
  end
84
84
  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.1"
5
+ VERSION = "0.5.2"
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.1
4
+ version: 0.5.2
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-01-22 00:00:00.000000000 Z
11
+ date: 2020-08-09 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,25 +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.5
11
- - 2.3.1
12
- - ruby-head
13
- - jruby-9000
14
- - jruby-head
15
- - rbx-2
16
- matrix:
17
- allow_failures:
18
- - rvm: ruby-head
19
- - rvm: jruby-head
20
- - rvm: rbx-2
21
- fast_finish: true
22
- branches:
23
- only: master
24
- notifications:
25
- 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