Module: TTY::Color

Extended by:
Color
Included in:
Color
Defined in:
lib/tty/color.rb,
lib/tty/color/mode.rb,
lib/tty/color/support.rb,
lib/tty/color/version.rb

Overview

Responsible for checking terminal color support

Defined Under Namespace

Classes: Mode, Support

Constant Summary collapse

NoValue =
Module.new
VERSION =
"0.6.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outputObject



20
21
22
# File 'lib/tty/color.rb', line 20

def output
  @output
end

#verboseObject



20
21
22
# File 'lib/tty/color.rb', line 20

def verbose
  @verbose
end

Instance Method Details

#command?(cmd) ⇒ Boolean

Check if command can be run

Returns:

  • (Boolean)


67
68
69
# File 'lib/tty/color.rb', line 67

def command?(cmd)
  !!system(cmd, out: ::File::NULL, err: ::File::NULL)
end

#disabled?Boolean

Detect if color support has been disabled with NO_COLOR ENV var.

Returns:

  • (Boolean)

    true when terminal color support has been disabled, false otherwise



40
41
42
# File 'lib/tty/color.rb', line 40

def disabled?
  Support.new(ENV, verbose: verbose).disabled?
end

#modeInteger

Check how many colors this terminal supports

Returns:

  • (Integer)


49
50
51
# File 'lib/tty/color.rb', line 49

def mode
  Mode.new(ENV).mode
end

#support?Boolean Also known as: supports?, color?, supports_color?

Check if terminal supports colors

Returns:

  • (Boolean)


27
28
29
# File 'lib/tty/color.rb', line 27

def support?
  Support.new(ENV, verbose: verbose).support?
end

#tty?Boolean

Check if output is linked with terminal

Returns:

  • (Boolean)


58
59
60
# File 'lib/tty/color.rb', line 58

def tty?
  output.respond_to?(:tty?) && output.tty?
end

#windows?Boolean

Check if Windowz

Returns:

  • (Boolean)


76
77
78
# File 'lib/tty/color.rb', line 76

def windows?
  ::File::ALT_SEPARATOR == "\\"
end