pax_global_header00006660000000000000000000000064136121462110014507gustar00rootroot0000000000000052 comment=2b41dafc319f6331787df7955622568ce8417f29 tty-color-0.5.1/000077500000000000000000000000001361214621100134465ustar00rootroot00000000000000tty-color-0.5.1/.github/000077500000000000000000000000001361214621100150065ustar00rootroot00000000000000tty-color-0.5.1/.github/FUNDING.yml000066400000000000000000000000241361214621100166170ustar00rootroot00000000000000github: piotrmurach tty-color-0.5.1/.github/ISSUE_TEMPLATE.md000066400000000000000000000011051361214621100175100ustar00rootroot00000000000000### 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.5.1/.github/PULL_REQUEST_TEMPLATE.md000066400000000000000000000006761361214621100206200ustar00rootroot00000000000000### 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? [] Documentaion updated? tty-color-0.5.1/.gitignore000066400000000000000000000001661361214621100154410ustar00rootroot00000000000000/.bundle/ /.yardoc /Gemfile.lock /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ *.bundle *.so *.o *.a mkmf.log tty-color-0.5.1/.rspec000066400000000000000000000000511361214621100145570ustar00rootroot00000000000000--color --require spec_helper --warnings tty-color-0.5.1/.travis.yml000066400000000000000000000005541361214621100155630ustar00rootroot00000000000000--- language: ruby before_install: "gem install bundler -v '< 2.0'" script: bundle exec rake ci rvm: - 2.0.0 - 2.1.10 - 2.2.10 - 2.3.8 - 2.4.6 - 2.5.5 - 2.6.3 - ruby-head - jruby-9.2.6.0 - jruby-head matrix: allow_failures: - rvm: ruby-head - rvm: jruby-head fast_finish: true branches: only: master notifications: email: false tty-color-0.5.1/CHANGELOG.md000066400000000000000000000036051361214621100152630ustar00rootroot00000000000000# Change log ## [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.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.5.1/CODE_OF_CONDUCT.md000066400000000000000000000062351361214621100162530ustar00rootroot00000000000000# 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.5.1/Gemfile000066400000000000000000000003271361214621100147430ustar00rootroot00000000000000source '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.5.1/LICENSE.txt000066400000000000000000000020551361214621100152730ustar00rootroot00000000000000Copyright (c) 2016 Piotr Murach 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.5.1/README.md000066400000000000000000000071301361214621100147260ustar00rootroot00000000000000
tty logo
# TTY::Color [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter] [![Gem Version](https://badge.fury.io/rb/tty-color.svg)][gem] [![Build Status](https://secure.travis-ci.org/piotrmurach/tty-color.svg?branch=master)][travis] [![Build status](https://ci.appveyor.com/api/projects/status/j1nflklmnfrb2yrf?svg=true)][appveyor] [![Code Climate](https://codeclimate.com/github/piotrmurach/tty-color/badges/gpa.svg)][codeclimate] [![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-color/badge.svg)][coverage] [![Inline docs](http://inch-ci.org/github/piotrmurach/tty-color.svg?branch=master)][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 ``` Also you can get the number of colors supported by the terminal: ```ruby TTY::Color.mode # => 64 ``` **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 do: ```bash color -s ``` And to check color mode: ```bash color -m ``` ## 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.5.1/Rakefile000066400000000000000000000002171361214621100151130ustar00rootroot00000000000000require "bundler/gem_tasks" FileList['tasks/**/*.rake'].each(&method(:import)) desc 'Run all specs' task ci: %w[ spec ] task default: :spec tty-color-0.5.1/appveyor.yml000066400000000000000000000011461361214621100160400ustar00rootroot00000000000000--- 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.5.1/bin/000077500000000000000000000000001361214621100142165ustar00rootroot00000000000000tty-color-0.5.1/bin/console000077500000000000000000000005301361214621100156040ustar00rootroot00000000000000#!/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.5.1/bin/setup000077500000000000000000000002031361214621100152770ustar00rootroot00000000000000#!/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.5.1/lib/000077500000000000000000000000001361214621100142145ustar00rootroot00000000000000tty-color-0.5.1/lib/tty-color.rb000066400000000000000000000000241361214621100164710ustar00rootroot00000000000000require 'tty/color' tty-color-0.5.1/lib/tty/000077500000000000000000000000001361214621100150345ustar00rootroot00000000000000tty-color-0.5.1/lib/tty/color.rb000066400000000000000000000023671361214621100165070ustar00rootroot00000000000000# frozen_string_literal: true require_relative 'color/support' require_relative 'color/mode' 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? # 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.5.1/lib/tty/color/000077500000000000000000000000001361214621100161525ustar00rootroot00000000000000tty-color-0.5.1/lib/tty/color/mode.rb000066400000000000000000000043711361214621100174300ustar00rootroot00000000000000# frozen_string_literal: true module TTY module Color class Mode TERM_256 = /iTerm(\s\d+){0,1}.app/x TERM_64 = /^(hpterm-color|wy370|wy370-105k|wy370-EPC|wy370-nk| wy370-rv|wy370-tek|wy370-vb|wy370-w|wy370-wvb)$/x TERM_52 = /^(dg+ccc|dgunix+ccc|d430.*?[\-\+](dg|unix).*?[\-\+]ccc)$/x 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|nsterm-c|nsterm-c-acs| nsterm-c-s|nsterm-c-s-7|nsterm-c-s-acs|nsterm\+c| nsterm-7-c|nsterm-bce)$/x TERM_8 = /vt100|xnuppc|wy350/x METHODS = %w[from_term from_tput].freeze def initialize(env) @env = env end # Detect supported colors # # @return [Integer] # out of 0, 8, 16, 52, 64, 256 # # @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 /[\-\+](\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 if !TTY::Color.command?("tput colors") return NoValue end 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.5.1/lib/tty/color/support.rb000066400000000000000000000041241361214621100202140ustar00rootroot00000000000000# 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 # Initialize a color support # @api public def initialize(env, options = {}) @env = env @verbose = options.fetch(:verbose) { false } 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? value = false SOURCES.each do |from_check| break if (value = public_send(from_check)) != NoValue end value == NoValue ? false : value end # Inspect environment $TERM variable for color support # # @api private def from_term case @env['TERM'] when 'dumb' then false when /^screen|^xterm|^vt100|color|ansi|cygwin|linux/i then true else NoValue end end # Shell out to tput to check color support # # @api private def from_tput return NoValue if !TTY::Color.command?("tput colors") cmd = %q(tput colors 2>/dev/null) `#{cmd}`.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.5.1/lib/tty/color/version.rb000066400000000000000000000001471361214621100201660ustar00rootroot00000000000000# frozen_string_literal: true module TTY module Color VERSION = "0.5.1" end # Color end # TTY tty-color-0.5.1/spec/000077500000000000000000000000001361214621100144005ustar00rootroot00000000000000tty-color-0.5.1/spec/spec_helper.rb000066400000000000000000000020131361214621100172120ustar00rootroot00000000000000# 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 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.5.1/spec/unit/000077500000000000000000000000001361214621100153575ustar00rootroot00000000000000tty-color-0.5.1/spec/unit/color_spec.rb000066400000000000000000000013161361214621100200350ustar00rootroot00000000000000# 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 end tty-color-0.5.1/spec/unit/mode_spec.rb000066400000000000000000000061701361214621100176460ustar00rootroot00000000000000# 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 it 'infers mode for xterm-256color' do mode = described_class.new('TERM' => 'xterm-256color') expect(mode.from_term).to eq(256) end it 'infers mode for iTerm.app' do mode = described_class.new('TERM' => 'iTerm.app') expect(mode.from_term).to eq(256) end it 'infers mode for iTerm 2.app' do mode = described_class.new('TERM' => 'iTerm 2.app') expect(mode.from_term).to eq(256) end it 'infers mode from terminal environment' do mode = described_class.new('TERM' => 'amiga-8bit') expect(mode.from_term).to eq(256) end it 'infers mode for wy730' do mode = described_class.new('TERM' => 'wy370-105k') expect(mode.from_term).to eq(64) end it 'infers mode for d430-unix-ccc' do mode = described_class.new('TERM' => 'd430-unix-ccc') expect(mode.from_term).to eq(52) end it 'infers mode for d430-unix-s-ccc' do mode = described_class.new('TERM' => 'd430c-unix-s-ccc') expect(mode.from_term).to eq(52) end it 'infers mode for nsterm-bce' do mode = described_class.new('TERM' => 'nsterm-bce') expect(mode.from_term).to eq(16) end it 'infers mode for d430-c' do mode = described_class.new('TERM' => 'd430c-dg') expect(mode.from_term).to eq(16) end it 'infers mode for d430-unix-w' do mode = described_class.new('TERM' => 'd430-unix-w') expect(mode.from_term).to eq(16) end it 'infers mode for vt100' do mode = described_class.new('TERM' => 'konsole-vt100') expect(mode.from_term).to eq(8) end it 'infers mode for xnuppc' do mode = described_class.new('TERM' => 'xnuppc+basic') expect(mode.from_term).to eq(8) end it 'infers mode fro dummy terminal' do mode = described_class.new('TERM' => 'dummy') expect(mode.from_term).to eq(0) 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 utilty" do mode = described_class.new({}) cmd = "tput colors" allow(TTY::Color).to receive(:command?).with(cmd).and_return(nil) expect(mode.from_tput).to eq(TTY::Color::NoValue) end end end tty-color-0.5.1/spec/unit/support_spec.rb000066400000000000000000000105531361214621100204360ustar00rootroot00000000000000# 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 "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 '#form_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) 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({}) cmd = "tput colors" allow(TTY::Color).to receive(:command?).with(cmd).and_return(nil) 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.5.1/tasks/000077500000000000000000000000001361214621100145735ustar00rootroot00000000000000tty-color-0.5.1/tasks/console.rake000066400000000000000000000003251361214621100171010ustar00rootroot00000000000000# encoding: utf-8 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.5.1/tasks/coverage.rake000066400000000000000000000003221361214621100172270ustar00rootroot00000000000000# encoding: utf-8 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.5.1/tasks/spec.rake000066400000000000000000000012551361214621100163740ustar00rootroot00000000000000# encoding: utf-8 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.5.1/tty-color.gemspec000066400000000000000000000024671361214621100167600ustar00rootroot00000000000000require_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-prompt/issues", "changelog_uri" => "https://github.com/piotrmurach/tty-prompt/blob/master/CHANGELOG.md", "documentation_uri" => "https://www.rubydoc.info/gems/tty-prompt", "homepage_uri" => spec.homepage, "source_code_uri" => "https://github.com/piotrmurach/tty-prompt" } end spec.files = Dir["lib/**/*", "README.md", "CHANGELOG.md", "LICENSE.txt"] spec.extra_rdoc_files = ["README.md", "CHANGELOG.md"] spec.bindir = "exe" spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.0.0" spec.add_development_dependency "bundler", ">= 1.5.0" spec.add_development_dependency "rspec", "~> 3.1" spec.add_development_dependency "rake" end