module Interact::Pretty
Constants
- COLOR_CODES
- DEFAULT_COLORS
- WINDOWS
Private Instance Methods
b(str)
click to toggle source
bold text
# File lib/interact/pretty.rb, line 78 def b(str) return str unless color? code = "\e[1m" "#{code}#{str.to_s.gsub("\e[0m", "\e[0m#{code}")}\e[0m" end
c(str, type)
click to toggle source
colored text
shouldn't use bright colors, as some color themes abuse the bright palette (I'm looking at you, Solarized)
# File lib/interact/pretty.rb, line 61 def c(str, type) return str unless color? bright = false color = user_colors[type] if color.to_s =~ /bright-(.+)/ bright = true color = $1.to_sym end return str unless color code = "\e[#{bright ? 9 : 3}#{COLOR_CODES[color]}m" "#{code}#{str.to_s.gsub("\e[0m", "\e[0m#{code}")}\e[0m" end
color?()
click to toggle source
use colors?
# File lib/interact/pretty.rb, line 48 def color? color_enabled? && !WINDOWS && $stdout.tty? end
color_enabled?()
click to toggle source
override with e.g. option(:color), or whatever toggle you use
# File lib/interact/pretty.rb, line 43 def color_enabled? true end
d(str)
click to toggle source
dim text
# File lib/interact/pretty.rb, line 86 def d(str) return str unless color? code = "\e[2m" "#{code}#{str.to_s.gsub("\e[0m", "\e[0m#{code}")}\e[0m" end
i(str)
click to toggle source
invert text
# File lib/interact/pretty.rb, line 94 def i(str) return str unless color? code = "\e[7m" "#{code}#{str.to_s.gsub("\e[0m", "\e[0m#{code}")}\e[0m" end
user_colors()
click to toggle source
redefine to control the tag -> color settings
# File lib/interact/pretty.rb, line 53 def user_colors DEFAULT_COLORS end