Module: TuiTui::ColorDepth
- Defined in:
- lib/tui_tui/color_depth.rb
Overview
Resolves the color depth the renderer may safely emit.
Constant Summary collapse
- TRUECOLOR =
%w[truecolor 24bit].freeze
- MODES =
%i[none basic16 ansi256 truecolor].freeze
Class Method Summary collapse
Class Method Details
.detect(env = ENV) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/tui_tui/color_depth.rb', line 9 def self.detect(env = ENV) return :none if disabled?(env) return :truecolor if TRUECOLOR.include?(env["COLORTERM"]) :ansi256 end |
.disabled?(env) ⇒ Boolean
32 33 34 35 36 37 |
# File 'lib/tui_tui/color_depth.rb', line 32 def self.disabled?(env) return true if env.key?("NO_COLOR") term = env["TERM"] term.nil? || term.empty? || term == "dumb" end |
.from(name, env = ENV) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tui_tui/color_depth.rb', line 16 def self.from(name, env = ENV) # Unknown overrides fall back to auto-detection instead of failing startup. case name.to_s.downcase when "none", "no", "off", "0" :none when "16", "basic", "basic16", "ansi16" :basic16 when "256", "ansi256" :ansi256 when "truecolor", "24bit", "full" :truecolor else detect(env) end end |