pax_global_header 0000666 0000000 0000000 00000000064 13751552601 0014517 g ustar 00root root 0000000 0000000 52 comment=e2892eb2a549e313f73cba063c9a0e2e42270acf tty-color-0.6.0/ 0000775 0000000 0000000 00000000000 13751552601 0013456 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/.editorconfig 0000664 0000000 0000000 00000000226 13751552601 0016133 0 ustar 00root root 0000000 0000000 root = true [*.rb] charset = utf-8 end_of_line = lf insert_final_newline = true indent_style = space indent_size = 2 trim_trailing_whitespace = true tty-color-0.6.0/.github/ 0000775 0000000 0000000 00000000000 13751552601 0015016 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/.github/FUNDING.yml 0000664 0000000 0000000 00000000024 13751552601 0016627 0 ustar 00root root 0000000 0000000 github: piotrmurach tty-color-0.6.0/.github/ISSUE_TEMPLATE.md 0000664 0000000 0000000 00000001105 13751552601 0017520 0 ustar 00root root 0000000 0000000 ### Are you in the right place? * For issues or feature requests file a GitHub issue in this repository * For general questions or discussion post in [Gitter](https://gitter.im/piotrmurach/tty) ### Describe the problem A brief description of the issue/feature. ### Steps to reproduce the problem ``` Your code here to reproduce the issue ``` ### Actual behaviour What happened? This could be a description, log output, error raised etc... ### Expected behaviour What did you expect to happen? ### Describe your environment * OS version: * Ruby version: * TTY::Color version: tty-color-0.6.0/.github/PULL_REQUEST_TEMPLATE.md 0000664 0000000 0000000 00000000677 13751552601 0020631 0 ustar 00root root 0000000 0000000 ### Describe the change What does this Pull Request do? ### Why are we doing this? Any related context as to why is this is a desirable change. ### Benefits How will the library improve? ### Drawbacks Possible drawbacks applying this change. ### Requirements Put an X between brackets on each line if you have done the item: [] Tests written & passing locally? [] Code style checked? [] Rebased with `master` branch? [] Documentation updated? tty-color-0.6.0/.gitignore 0000664 0000000 0000000 00000000166 13751552601 0015451 0 ustar 00root root 0000000 0000000 /.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.bundle *.so *.o *.a mkmf.log tty-color-0.6.0/.rspec 0000664 0000000 0000000 00000000051 13751552601 0014567 0 ustar 00root root 0000000 0000000 --color --require spec_helper --warnings tty-color-0.6.0/.rubocop.yml 0000664 0000000 0000000 00000001322 13751552601 0015726 0 ustar 00root root 0000000 0000000 AllCops: NewCops: enable Lint/AssignmentInCondition: Enabled: false Metrics/AbcSize: Max: 30 Metrics/BlockLength: CountComments: true Max: 25 ExcludedMethods: [] Exclude: - "spec/**/*" Metrics/ClassLength: Max: 1500 Metrics/CyclomaticComplexity: Enabled: false Metrics/LineLength: Max: 80 Metrics/MethodLength: Max: 20 Naming/BinaryOperatorParameterName: Enabled: false Style/AsciiComments: Enabled: false Style/LambdaCall: SupportedStyles: - call - braces Style/StringLiterals: EnforcedStyle: double_quotes Style/TrivialAccessors: Enabled: false # { ... } for multi-line blocks is okay Style/BlockDelimiters: Enabled: false Style/CommentedKeyword: Enabled: false tty-color-0.6.0/.travis.yml 0000664 0000000 0000000 00000000646 13751552601 0015575 0 ustar 00root root 0000000 0000000 --- language: ruby before_install: "gem install bundler -v '< 2.0'" script: bundle exec rake ci rvm: - 2.0 - 2.1 - 2.2 - 2.3 - 2.4 - 2.5 - 2.6 - 2.7 - ruby-head - jruby-9.2.11.0 - jruby-head - truffleruby matrix: allow_failures: - rvm: ruby-head - rvm: jruby-head - rvm: jruby-9.2.11.0 - rvm: truffleruby fast_finish: true branches: only: master notifications: email: false tty-color-0.6.0/CHANGELOG.md 0000664 0000000 0000000 00000004755 13751552601 0015302 0 ustar 00root root 0000000 0000000 # Change log ## [v0.6.0] - 2020-11-07 ### Added * Add 24bit color aka "direct color" aka "truecolor" by @nevans * Add support for NO_COLOR env var by @nevans ### Changed * Change to freeze all regular expressions * Change to increase test coverage to 100% ## [v0.5.2] - 2020-08-09 ### Changed * Change gemspec and remove bundler as dev dependency * Change TTY::Color::Support to define verbose as keyword argument ### Fix * Fix gemspec metadata links by Igor Kapkov(@igas) ## [v0.5.1] - 2020-01-22 ### Changed * Change gemspec to add metadata and remove test artefacts ## [v0.5.0] - 2019-05-29 ### Changed * Change gemspec to load files without git * Change to limit to Ruby >= 2.0.0 ## [v0.4.3] - 2018-07-11 ### Changed * Change to use relative file paths * Change to ensure immutable strings * Change Color to use alias call ### Fixed * Fix to support iTerm 2.app for 256 color mode detection by Michael Lang(@mwlang) ## [v0.4.2] - 2017-02-06 ### Fixed * Fix File namespaces ## [v0.4.1] - 2017-01-22 ### Fixed * Fix #windows? to reference top level constant ## [v0.4.0] - 2016-12-27 ### Added * Add #command? helper * Add #windows? helper ### Changed * Change to stop checking curses on Windows ### Fixed * Fix Support#from_tput check to fail gracefully on non-unix systems * Fix Mode#from_tput check to fail gracefuly on non-unix systems ## [v0.3.0] - 2016-01-13 ### Fixed * Fix #tty? check ## [v0.2.0] - 2016-01-13 ### Changed * Change ordering of color support checks by @janlelis * Change ordering of color mode * Change Support#from_env to check ansicon * Ensure #tty? works for non-terminal devices * Remove color executable ## [v0.1.0] - 2016-01-02 * Initial implementation and release [v0.6.0]: https://github.com/piotrmurach/tty-color/compare/v0.5.2...v0.6.0 [v0.5.2]: https://github.com/piotrmurach/tty-color/compare/v0.5.1...v0.5.2 [v0.5.1]: https://github.com/piotrmurach/tty-color/compare/v0.5.0...v0.5.1 [v0.5.0]: https://github.com/piotrmurach/tty-color/compare/v0.4.3...v0.5.0 [v0.4.3]: https://github.com/piotrmurach/tty-color/compare/v0.4.2...v0.4.3 [v0.4.2]: https://github.com/piotrmurach/tty-color/compare/v0.4.1...v0.4.2 [v0.4.1]: https://github.com/piotrmurach/tty-color/compare/v0.4.0...v0.4.1 [v0.4.0]: https://github.com/piotrmurach/tty-color/compare/v0.3.0...v0.4.0 [v0.3.0]: https://github.com/piotrmurach/tty-color/compare/v0.2.0...v0.3.0 [v0.2.0]: https://github.com/piotrmurach/tty-color/compare/v0.1.0...v0.2.0 [v0.1.0]: https://github.com/piotrmurach/tty-color/compare/v0.1.0 tty-color-0.6.0/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000006235 13751552601 0016263 0 ustar 00root root 0000000 0000000 # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at piotr@piotrmurach.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ tty-color-0.6.0/Gemfile 0000664 0000000 0000000 00000000327 13751552601 0014753 0 ustar 00root root 0000000 0000000 source 'https://rubygems.org' gemspec group :development do gem 'benchmark-ips', '~> 2.7.2' end group :metrics do gem 'simplecov', '~> 0.16.1' gem 'coveralls', '~> 0.8.22' gem 'yardstick', '~> 0.9.9' end tty-color-0.6.0/LICENSE.txt 0000664 0000000 0000000 00000002107 13751552601 0015301 0 ustar 00root root 0000000 0000000 Copyright (c) 2016 Piotr Murach (https://piotrmurach.com) MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tty-color-0.6.0/README.md 0000664 0000000 0000000 00000007521 13751552601 0014742 0 ustar 00root root 0000000 0000000
# TTY::Color [][gitter] [][gem] [][travis] [][appveyor] [][codeclimate] [][coverage] [][inchpages] [gitter]: https://gitter.im/piotrmurach/tty [gem]: http://badge.fury.io/rb/tty-color [travis]: http://travis-ci.org/piotrmurach/tty-color [appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-color [codeclimate]: https://codeclimate.com/github/piotrmurach/tty-color [coverage]: https://coveralls.io/github/piotrmurach/tty-color [inchpages]: http://inch-ci.org/github/piotrmurach/tty-color > Terminal color capabilities detection. **TTY::Color** provides independent color support detection component for [TTY](https://github.com/piotrmurach/tty) toolkit. ## Installation Add this line to your application's Gemfile: ```ruby gem "tty-color" ``` And then execute: $ bundle Or install it yourself as: $ gem install tty-color ## Usage **TTY::Color** allows you to check if terminal supports color: ```ruby TTY::Color.color? # => true TTY::Color.support? # => true ``` You can also get the number of colors supported by the terminal using `mode` method: ```ruby TTY::Color.mode # => 64 ``` To detect if color support has been disabled with `NO_COLOR` environment variable, use `disabled?`: ```ruby TTY::Color.disabled? # => false ``` **TTY::Color** is just a module hence you can include it into your scripts directly: ```ruby #!/usr/bin/env ruby include TTY::Color puts color? ``` ## Command line tool [tty-color-cli](https://github.com/piotrmurach/tty-color-cli) is a command line tool for the **TTY::Color**. To check if terminal supports colors use `-s|--support`: ```bash tty-color -s tty-color --support # => true ``` And to check color mode use `-m|--mode` option: ```bash tty-color -m tty-color --mode # => 256 ``` ## Development 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. 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). ## Contributing 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. 1. Fork it ( https://github.com/piotrmurach/tty-color/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request ## Code of Conduct 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). ## Copyright Copyright (c) 2016 Piotr Murach. See LICENSE for further details. tty-color-0.6.0/Rakefile 0000664 0000000 0000000 00000000256 13751552601 0015126 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true require "bundler/gem_tasks" FileList["tasks/**/*.rake"].each(&method(:import)) desc "Run all specs" task ci: %w[ spec ] task default: :spec tty-color-0.6.0/appveyor.yml 0000664 0000000 0000000 00000001146 13751552601 0016050 0 ustar 00root root 0000000 0000000 --- install: - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - gem install bundler -v '< 2.0' - bundle install before_test: - ruby -v - gem -v - bundle -v build: off test_script: - bundle exec rake ci environment: matrix: - ruby_version: "200" - ruby_version: "200-x64" - ruby_version: "21" - ruby_version: "21-x64" - ruby_version: "22" - ruby_version: "22-x64" - ruby_version: "23" - ruby_version: "23-x64" - ruby_version: "24" - ruby_version: "24-x64" - ruby_version: "25" - ruby_version: "25-x64" - ruby_version: "26" - ruby_version: "26-x64" tty-color-0.6.0/bin/ 0000775 0000000 0000000 00000000000 13751552601 0014226 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/bin/console 0000775 0000000 0000000 00000000530 13751552601 0015614 0 ustar 00root root 0000000 0000000 #!/usr/bin/env ruby require "bundler/setup" require "tty/color" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start(__FILE__) tty-color-0.6.0/bin/setup 0000775 0000000 0000000 00000000203 13751552601 0015307 0 ustar 00root root 0000000 0000000 #!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here tty-color-0.6.0/lib/ 0000775 0000000 0000000 00000000000 13751552601 0014224 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/lib/tty-color.rb 0000664 0000000 0000000 00000000035 13751552601 0016503 0 ustar 00root root 0000000 0000000 require_relative "tty/color" tty-color-0.6.0/lib/tty/ 0000775 0000000 0000000 00000000000 13751552601 0015044 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/lib/tty/color.rb 0000664 0000000 0000000 00000003016 13751552601 0016507 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true require_relative "color/mode" require_relative "color/support" require_relative "color/version" module TTY # Responsible for checking terminal color support # # @api public module Color extend self NoValue = Module.new @verbose = false @output = $stderr attr_accessor :output, :verbose # Check if terminal supports colors # # @return [Boolean] # # @api public def support? Support.new(ENV, verbose: verbose).support? end alias supports? support? alias color? support? alias supports_color? support? # Detect if color support has been disabled with NO_COLOR ENV var. # # @return [Boolean] # true when terminal color support has been disabled, false otherwise # # @api public def disabled? Support.new(ENV, verbose: verbose).disabled? end # Check how many colors this terminal supports # # @return [Integer] # # @api public def mode Mode.new(ENV).mode end # Check if output is linked with terminal # # @return [Boolean] # # @api public def tty? output.respond_to?(:tty?) && output.tty? end # Check if command can be run # # @return [Boolean] # # @api public def command?(cmd) !!system(cmd, out: ::File::NULL, err: ::File::NULL) end # Check if Windowz # # @return [Boolean] # # @api public def windows? ::File::ALT_SEPARATOR == "\\" end end # Color end # TTY tty-color-0.6.0/lib/tty/color/ 0000775 0000000 0000000 00000000000 13751552601 0016162 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/lib/tty/color/mode.rb 0000664 0000000 0000000 00000005027 13751552601 0017437 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true module TTY module Color class Mode TERM_24BIT = /[+-]direct/.freeze TRUECOLORS = 2**24 # 8 bits per RGB channel TERM_256 = /^(alacritty|iTerm\s?\d*\.app|kitty|mintty|ms-terminal| nsterm|nsterm-build\d+|terminator|terminology(-[0-9.]+)?| termite|vscode)$/x.freeze TERM_64 = /^(hpterm-color|wy370|wy370-105k|wy370-EPC|wy370-nk| wy370-rv|wy370-tek|wy370-vb|wy370-w|wy370-wvb)$/x.freeze TERM_52 = /^(dg+ccc|dgunix+ccc|d430.*?[-+](dg|unix).*?[-+]ccc)$/x.freeze TERM_16 = /^(amiga-vnc|d430-dg|d430-unix|d430-unix-25|d430-unix-s| d430-unix-sr|d430-unix-w|d430c-dg|d430c-unix|d430c-unix-25| d430c-unix-s|d430c-unix-sr|d430c-unix-w|d470|d470-7b|d470-dg| d470c|d470c-7b|d470c-dg|dg+color|dg\+fixed|dgunix\+fixed| dgmode\+color|hp\+color|ncr260wy325pp|ncr260wy325wpp| ncr260wy350pp|ncr260wy350wpp|nsterm-c|nsterm-c-acs| nsterm-c-s|nsterm-c-s-7|nsterm-c-s-acs|nsterm\+c| nsterm-7-c|nsterm-bce)$/x.freeze TERM_8 = /vt100|xnuppc|wy350/x.freeze METHODS = %w[from_term from_tput].freeze def initialize(env) @env = env end # Detect supported colors # # @return [Integer] # out of 0, 8, 16, 52, 66, 256, 2^24 # # @api public def mode return 0 unless TTY::Color.tty? value = 8 METHODS.each do |from_check| break if (value = public_send(from_check)) != NoValue end return 8 if value == NoValue value end # Check TERM environment for colors # # @return [NoValue, Integer] # # @api private def from_term case @env["TERM"] when TERM_24BIT then TRUECOLORS when /[-+](\d+)color/ then $1.to_i when /[-+](\d+)bit/ then 2**$1.to_i when TERM_256 then 256 when TERM_64 then 64 when TERM_52 then 52 when TERM_16 then 16 when TERM_8 then 8 when /dummy/ then 0 else NoValue end end # Shell out to tput to check color support # # @return [NoValue, Integer] # # @api private def from_tput return NoValue unless TTY::Color.command?("tput colors") colors = `tput colors 2>/dev/null`.to_i colors >= 8 ? colors : NoValue rescue Errno::ENOENT NoValue end end # Mode end # Color end # TTY tty-color-0.6.0/lib/tty/color/support.rb 0000664 0000000 0000000 00000005425 13751552601 0020231 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true module TTY module Color class Support SOURCES = %w[from_term from_tput from_env from_curses].freeze ENV_VARS = %w[COLORTERM ANSICON].freeze TERM_REGEX = / color| # explicitly claims color support in the name direct| # explicitly claims "direct color" (24 bit) support #{Mode::TERM_256}| #{Mode::TERM_64}| #{Mode::TERM_52}| #{Mode::TERM_16}| #{Mode::TERM_8}| ^ansi(\.sys.*)?$| ^cygwin| ^linux| ^putty| ^rxvt| ^screen| ^tmux| ^xterm/xi.freeze # Initialize a color support # @api public def initialize(env, verbose: false) @env = env @verbose = verbose end # Detect if terminal supports color # # @return [Boolean] # true when terminal supports color, false otherwise # # @api public def support? return false unless TTY::Color.tty? return false if disabled? value = false SOURCES.each do |from_check| break if (value = public_send(from_check)) != NoValue end value == NoValue ? false : value end # Detect if color support has been disabled with NO_COLOR ENV var. # # @return [Boolean] # true when terminal color support has been disabled, false otherwise # # @api public def disabled? no_color = @env["NO_COLOR"] !(no_color.nil? || no_color.empty?) end # Inspect environment $TERM variable for color support # # @api private def from_term case @env["TERM"] when "dumb" then false when TERM_REGEX then true else NoValue end end # Shell out to tput to check color support # # @api private def from_tput return NoValue unless TTY::Color.command?("tput colors") `tput colors 2>/dev/null`.to_i > 2 rescue Errno::ENOENT NoValue end # Check if environment specifies color variables # # @api private def from_env ENV_VARS.any? { |key| @env.key?(key) } || NoValue end # Attempt to load curses to check color support # # @return [Boolean] # # @api private def from_curses(curses_class = nil) return NoValue if TTY::Color.windows? require "curses" if defined?(Curses) curses_class ||= Curses curses_class.init_screen has_color = curses_class.has_colors? curses_class.close_screen return has_color end NoValue rescue LoadError warn "no native curses support" if @verbose NoValue end end # Support end # Color end # TTY tty-color-0.6.0/lib/tty/color/version.rb 0000664 0000000 0000000 00000000147 13751552601 0020176 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true module TTY module Color VERSION = "0.6.0" end # Color end # TTY tty-color-0.6.0/spec/ 0000775 0000000 0000000 00000000000 13751552601 0014410 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/spec/spec_helper.rb 0000664 0000000 0000000 00000002076 13751552601 0017233 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true if ENV["COVERAGE"] || ENV["TRAVIS"] require "simplecov" require "coveralls" SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter ]) SimpleCov.start do command_name "spec" add_filter "spec" end end require "tty-color" RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true expectations.max_formatted_output_length = nil end config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end # Limits the available syntax to the non-monkey patched syntax that is recommended. config.disable_monkey_patching! # This setting enables warnings. It's recommended, but in some cases may # be too noisy due to issues in dependencies. config.warnings = true if config.files_to_run.one? config.default_formatter = "doc" end config.profile_examples = 2 config.order = :random Kernel.srand config.seed end tty-color-0.6.0/spec/unit/ 0000775 0000000 0000000 00000000000 13751552601 0015367 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/spec/unit/color_spec.rb 0000664 0000000 0000000 00000003214 13751552601 0020044 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true RSpec.describe TTY::Color, "integratation" do it "defaults output to stderr" do expect(TTY::Color.output).to eq($stderr) end it "defaults verbose mode to false" do expect(TTY::Color.verbose).to eq(false) end it "accesses color mode" do mode_instance = spy(:mode) allow(TTY::Color::Mode).to receive(:new).and_return(mode_instance) described_class.mode expect(mode_instance).to have_received(:mode) end it "accesses color support" do support_instance = spy(:support) allow(TTY::Color::Support).to receive(:new).and_return(support_instance) described_class.support? expect(support_instance).to have_received(:support?) end it "accesses disabled support" do support_instance = spy(:support, disabled?: :maybe) allow(TTY::Color::Support).to receive(:new).and_return(support_instance) expect(described_class.disabled?).to eq(:maybe) expect(support_instance).to have_received(:disabled?) end it "checks unknown command without raising errors and returns false" do allow(described_class).to receive(:system) .with("unknown-command", { out: ::File::NULL, err: ::File::NULL }) .and_return(nil) expect(described_class.command?("unknown-command")).to eq(false) end it "checks 'echo' command and returns true" do allow(described_class).to receive(:system). with("echo", { out: ::File::NULL, err: ::File::NULL }).and_return("") expect(described_class.command?("echo")).to eq(true) end it "detects windows platform" do stub_const("::File::ALT_SEPARATOR", "\\") expect(described_class.windows?).to eq(true) end end tty-color-0.6.0/spec/unit/mode_spec.rb 0000664 0000000 0000000 00000005720 13751552601 0017656 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true RSpec.describe TTY::Color::Mode, "detecting mode" do it "isn't terminal" do allow(TTY::Color).to receive(:tty?).and_return(false) mode = described_class.new({}) expect(mode.mode).to eq(0) end it "cannot find from term, tput " do allow(TTY::Color).to receive(:tty?).and_return(true) mode = described_class.new({}) allow(mode).to receive(:from_term).and_return(TTY::Color::NoValue) allow(mode).to receive(:from_tput).and_return(TTY::Color::NoValue) expect(mode.mode).to eq(8) expect(mode).to have_received(:from_term).ordered expect(mode).to have_received(:from_tput).ordered end it "detects color mode" do allow(TTY::Color).to receive(:tty?).and_return(true) mode = described_class.new("TERM" => "xterm-256color") expect(mode.mode).to eq(256) end context "#from_term" do { "xterm+direct" => 16_777_216, "vscode-direct" => 16_777_216, "+24bit" => 16_777_216, "xterm-256color" => 256, "alacritty" => 256, "mintty" => 256, "ms-terminal" => 256, "nsterm" => 256, "nsterm-build400" => 256, "terminator" => 256, "vscode" => 256, "iTerm.app" => 256, "iTerm 2.app" => 256, "amiga-8bit" => 256, "+8bit" => 256, "wy370-105k" => 64, "d430-unix-ccc" => 52, "d430c-unix-s-ccc" => 52, "+52color" => 52, "nsterm-bce" => 16, "d430c-dg" => 16, "d430-unix-w" => 16, "konsole-vt100" => 8, "xnuppc+basic" => 8, "dummy" => 0 }.each do |term_name, number| it "infers #{term_name.inspect} to have #{number} colors" do mode = described_class.new("TERM" => term_name) expect(mode.from_term).to eq(number) end end it "doesn't match any term variable" do mode = described_class.new({}) expect(mode.from_term).to eq(TTY::Color::NoValue) end end context "#from_tput" do it "fails to find tput utility" do mode = described_class.new({}) allow(TTY::Color).to receive(:command?).with("tput colors").and_return(nil) expect(mode.from_tput).to eq(TTY::Color::NoValue) end it "runs tput and detects 8 colors" do allow(TTY::Color).to receive(:command?).with("tput colors").and_return(true) mode = described_class.new({}) allow(mode).to receive(:`).and_return("8") expect(mode.from_tput).to eq(8) end it "runs tput but finds less than 8 colors" do allow(TTY::Color).to receive(:command?).with("tput colors").and_return(true) mode = described_class.new({}) allow(mode).to receive(:`).and_return("2") expect(mode.from_tput).to eq(TTY::Color::NoValue) end it "raises error when running tput" do allow(TTY::Color).to receive(:command?).with("tput colors").and_return(true) mode = described_class.new({}) allow(mode).to receive(:`).and_raise(Errno::ENOENT) expect(mode.from_tput).to eq(TTY::Color::NoValue) end end end tty-color-0.6.0/spec/unit/support_spec.rb 0000664 0000000 0000000 00000012736 13751552601 0020453 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true RSpec.describe TTY::Color::Support, "#support?" do it "doesn't check color support for non tty terminal" do support = described_class.new({}) allow(TTY::Color).to receive(:tty?).and_return(false) expect(support.support?).to eq(false) end it "disables color support when NO_COLOR is set" do support = described_class.new({"NO_COLOR" => "1"}) expect(support.support?).to eq(false) expect(support).to be_disabled end it "fails to find out color support" do support = described_class.new({}) allow(TTY::Color).to receive(:tty?).and_return(true) allow(support).to receive(:from_curses).and_return(TTY::Color::NoValue) allow(support).to receive(:from_tput).and_return(TTY::Color::NoValue) allow(support).to receive(:from_term).and_return(TTY::Color::NoValue) allow(support).to receive(:from_env).and_return(TTY::Color::NoValue) expect(support.support?).to eq(false) expect(support).to have_received(:from_term).ordered expect(support).to have_received(:from_tput).ordered expect(support).to have_received(:from_env).ordered expect(support).to have_received(:from_curses).ordered end it "detects color support" do support = described_class.new({"TERM" => "xterm"}) allow(TTY::Color).to receive(:tty?).and_return(true) allow(support).to receive(:from_tput) expect(support.support?).to eq(true) expect(support).to_not have_received(:from_tput) end context "#from_curses" do it "fails to load curses for color support" do support = described_class.new({}) allow(TTY::Color).to receive(:windows?).and_return(false) allow(support).to receive(:require).with("curses").and_raise(LoadError) allow(support).to receive(:warn) expect(support.from_curses).to eq(TTY::Color::NoValue) expect(support).to_not have_received(:warn) end it "fails to find Curses namespace" do support = described_class.new({}) allow(TTY::Color).to receive(:windows?).and_return(false) allow(support).to receive(:require).with("curses") expect(support.from_curses).to eq(TTY::Color::NoValue) end it "sets verbose mode on" do support = described_class.new({}, verbose: true) allow(TTY::Color).to receive(:windows?).and_return(false) allow(support).to receive(:require).with("curses").and_raise(LoadError) allow(support).to receive(:warn) support.from_curses expect(support).to have_received(:warn).with(/no native curses support/) end it "loads curses for color support" do support = described_class.new({}) allow(TTY::Color).to receive(:windows?).and_return(false) allow(support).to receive(:require).with("curses").and_return(true) stub_const("Curses", Object.new) curses = double(:curses) allow(curses).to receive(:init_screen) allow(curses).to receive(:has_colors?).and_return(true) allow(curses).to receive(:close_screen) expect(support.from_curses(curses)).to eql(true) expect(curses).to have_received(:has_colors?) end it "doesn't check on windows" do support = described_class.new({}) allow(TTY::Color).to receive(:windows?).and_return(true) expect(support.from_curses).to eq(TTY::Color::NoValue) end end context "#from_term" do it "fails to find color for dumb terminal" do support = described_class.new({"TERM" => "dumb"}) expect(support.from_term).to eq(false) end it "inspects term variable for color capabilities" do support = described_class.new({"TERM" => "xterm"}) expect(support.from_term).to eq(true) support = described_class.new({"TERM" => "tmux-256color"}) expect(support.from_term).to eq(true) end it "fails to find color capabilities from term variable " do support = described_class.new({"TERM" => "atari"}) expect(support.from_term).to eq(TTY::Color::NoValue) end end context "#from_tput" do it "fails to find tput utilty" do support = described_class.new({}) allow(TTY::Color).to receive(:command?).with("tput colors").and_return(nil) expect(support.from_tput).to eq(TTY::Color::NoValue) end it "runs tput and detects 8 colors" do allow(TTY::Color).to receive(:command?).with("tput colors").and_return(true) support = described_class.new({}) allow(support).to receive(:`).and_return("8") expect(support.from_tput).to eq(true) end it "runs tput but finds no colors" do allow(TTY::Color).to receive(:command?).with("tput colors").and_return(true) support = described_class.new({}) allow(support).to receive(:`).and_return("2") expect(support.from_tput).to eq(false) end it "raises error when running tput" do allow(TTY::Color).to receive(:command?).with("tput colors").and_return(true) support = described_class.new({}) allow(support).to receive(:`).and_raise(Errno::ENOENT) expect(support.from_tput).to eq(TTY::Color::NoValue) end end context "#from_env" do it "finds color support in colorterm variable" do support = described_class.new({"COLORTERM" => true}) expect(support.from_env).to eq(true) end it "finds ansicon support" do support = described_class.new({"ANSICON" => true}) expect(support.from_env).to eq(true) end it "doesn't find any keys in environment" do support = described_class.new({}) expect(support.from_env).to eq(TTY::Color::NoValue) end end end tty-color-0.6.0/tasks/ 0000775 0000000 0000000 00000000000 13751552601 0014603 5 ustar 00root root 0000000 0000000 tty-color-0.6.0/tasks/console.rake 0000664 0000000 0000000 00000000341 13751552601 0017107 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true desc "Load gem inside irb console" task :console do require "irb" require "irb/completion" require File.join(__FILE__, "../../lib/tty-color") ARGV.clear IRB.start end task c: :console tty-color-0.6.0/tasks/coverage.rake 0000664 0000000 0000000 00000000336 13751552601 0017244 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true desc "Measure code coverage" task :coverage do begin original, ENV["COVERAGE"] = ENV["COVERAGE"], "true" Rake::Task["spec"].invoke ensure ENV["COVERAGE"] = original end end tty-color-0.6.0/tasks/spec.rake 0000664 0000000 0000000 00000001271 13751552601 0016402 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true begin require "rspec/core/rake_task" desc "Run all specs" RSpec::Core::RakeTask.new(:spec) do |task| task.pattern = "spec/{unit,integration}{,/*/**}/*_spec.rb" end namespace :spec do desc "Run unit specs" RSpec::Core::RakeTask.new(:unit) do |task| task.pattern = "spec/unit{,/*/**}/*_spec.rb" end desc "Run integration specs" RSpec::Core::RakeTask.new(:integration) do |task| task.pattern = "spec/integration{,/*/**}/*_spec.rb" end end rescue LoadError %w[spec spec:unit spec:integration].each do |name| task name do $stderr.puts "In order to run #{name}, do `gem install rspec`" end end end tty-color-0.6.0/tty-color.gemspec 0000664 0000000 0000000 00000002375 13751552601 0016766 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true require_relative "lib/tty/color/version" Gem::Specification.new do |spec| spec.name = "tty-color" spec.version = TTY::Color::VERSION spec.authors = ["Piotr Murach"] spec.email = ["piotr@piotrmurach.com"] spec.summary = %q{Terminal color capabilities detection} spec.description = %q{Terminal color capabilities detection} spec.homepage = "https://ttytoolkit.org" spec.license = "MIT" if spec.respond_to?(:metadata=) spec.metadata = { "allowed_push_host" => "https://rubygems.org", "bug_tracker_uri" => "https://github.com/piotrmurach/tty-color/issues", "changelog_uri" => "https://github.com/piotrmurach/tty-color/blob/master/CHANGELOG.md", "documentation_uri" => "https://www.rubydoc.info/gems/tty-color", "homepage_uri" => spec.homepage, "source_code_uri" => "https://github.com/piotrmurach/tty-color" } end spec.files = Dir["lib/**/*"] spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE.txt"] spec.bindir = "exe" spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.0.0" spec.add_development_dependency "rake" spec.add_development_dependency "rspec", ">= 3.0" end