module Regtest::Colors
Attributes
mapping[RW]
Color mapping Examples:
Regtest::Colors.mapping[:filename] = :lightblue Regtest::Colors.mapping[:fail] = :@red # '@' prefix means background color Regtest::Colors.mapping[:statistics] = %i(cyan italic) # more than one color code is possible
Public Class Methods
apply(str, *codes)
click to toggle source
Apply color codes to a string
# File lib/regtest/colors.rb, line 26 def apply str, *codes codes.flatten.each do |c| num = @codes[c.to_sym] fail format('Code %s not supported.', c) unless num str = format("\e[%dm%s", num, str) end format("%s\e[0m", str) end
codes()
click to toggle source
Get available color codes
# File lib/regtest/colors.rb, line 36 def codes @codes.keys end
Public Instance Methods
report(*args, type: nil)
click to toggle source
Redefine Regtest.report
# File lib/regtest/colors.rb, line 9 def report *args, type: nil color = Colors.mapping[type] if color && $stdout.tty? args = args.map {|a| Colors.apply(a.to_s, color)} end puts *args end