Sha256: 3533648bc91c453eb841b5c5a8c0476f09d3637d8679f45ccb832201dfc82f11

Contents?: true

Size: 1.24 KB

Versions: 7

Compression:

Stored size: 1.24 KB

Contents

# 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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
pokedex-terminal-0.2.8 vendor/bundle/ruby/2.7.0/gems/tty-color-0.5.1/lib/tty/color.rb
pokedex-terminal-0.2.7 vendor/bundle/ruby/2.7.0/gems/tty-color-0.5.1/lib/tty/color.rb
pokedex-terminal-0.2.6 vendor/bundle/ruby/2.7.0/gems/tty-color-0.5.1/lib/tty/color.rb
pokedex-terminal-0.2.5 vendor/bundle/ruby/2.7.0/gems/tty-color-0.5.1/lib/tty/color.rb
pokedex-terminal-0.2.4 vendor/bundle/ruby/2.7.0/gems/tty-color-0.5.1/lib/tty/color.rb
tty-color-0.5.1 lib/tty/color.rb
tty-color-0.5.0 lib/tty/color.rb