class TTY::Color::Mode
Constants
- METHODS
- TERM_16
- TERM_24BIT
- TERM_256
- TERM_52
- TERM_64
- TERM_8
- TRUECOLORS
Public Class Methods
Public Instance Methods
Source
# File lib/tty/color/mode.rb, line 57 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
Check TERM environment for colors
@return [NoValue, Integer]
@api private
Source
# File lib/tty/color/mode.rb, line 77 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
Shell out to tput to check color support
@return [NoValue, Integer]
@api private
Source
# File lib/tty/color/mode.rb, line 41 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
Detect supported colors
@return [Integer]
out of 0, 8, 16, 52, 66, 256, 2^24
@api public