Module: Lucid::Formatter::ANSIColor
Overview
Defines aliases for colored output. You don’t invoke any methods from this module directly, but you can change the output colors by defining a LUCID_COLORS
variable in your shell, very much like how you can tweak the familiar POSIX command ls
with $LS_COLORS.
The colors that you can change are:
-
undefined
- defaults toyellow
-
pending
- defaults toyellow
-
pending_param
- defaults toyellow,bold
-
failed
- defaults tored
-
failed_param
- defaults tored,bold
-
passed
- defaults togreen
-
passed_param
- defaults togreen,bold
-
outline
- defaults tocyan
-
outline_param
- defaults tocyan,bold
-
skipped
- defaults tocyan
-
skipped_param
- defaults tocyan,bold
-
comment
- defaults togrey
-
tag
- defaults tocyan
For instance, if your shell has a black background and a green font (like the “Homebrew” settings for OS X’ Terminal.app), you may want to override passed steps to be white instead of green.
Although not listed, you can also use grey
.
Examples: (On Windows, use SET instead of export.)
export LUCID_COLORS="passed=white"
export LUCID_COLORS="passed=white,bold:passed_param=white,bold,underline"
To see what colors and effects are available, just run this in your shell:
ruby -e "require 'rubygems'; require 'term/ansicolor'; puts Lucid::Term::ANSIColor.attributes"
Constant Summary collapse
- ALIASES =
Hash.new do |h,k| if k.to_s =~ /(.*)_param/ h[$1] + ',bold' end end.merge({ 'undefined' => 'yellow', 'pending' => 'yellow', 'failed' => 'red', 'passed' => 'green', 'outline' => 'cyan', 'skipped' => 'cyan', 'comment' => 'grey', 'tag' => 'cyan' })
Constants included from Term::ANSIColor
Term::ANSIColor::ATTRIBUTES, Term::ANSIColor::ATTRIBUTE_NAMES, Term::ANSIColor::COLORED_REGEXP
Class Method Summary collapse
Instance Method Summary collapse
- #green_lucid(n) ⇒ Object
- #grey(string) ⇒ Object
- #lucid(n) ⇒ Object
- #red_lucid(n) ⇒ Object
- #yellow_lucid(n) ⇒ Object
Methods included from Term::ANSIColor
attributes, coloring=, coloring?, included, #uncolored
Class Method Details
.define_grey ⇒ Object
:nodoc:
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/lucid/formatter/ansicolor.rb', line 111 def self.define_grey #:nodoc: begin gem 'genki-ruby-terminfo' require 'terminfo' case TermInfo.default_object.tigetnum('colors') when 0 raise "Your terminal doesn't support colors." when 1 ::Lucid::Term::ANSIColor.coloring = false alias grey white when 2..8 alias grey white else define_real_grey end rescue Exception => e if e.class.name == 'TermInfo::TermInfoError' STDERR.puts '*** WARNING ***' STDERR.puts "You have the genki-ruby-terminfo gem installed, but you haven't set your TERM variable." STDERR.puts 'Try setting it to TERM=xterm-256color to get color in output.' STDERR.puts "\n" alias grey white else define_real_grey end end end |
Instance Method Details
#green_lucid(n) ⇒ Object
155 156 157 |
# File 'lib/lucid/formatter/ansicolor.rb', line 155 def green_lucid(n) blink(green(lucid(n))) end |
#grey(string) ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/lucid/formatter/ansicolor.rb', line 140 def grey(string) if ::Lucid::Term::ANSIColor.coloring? "\e[90m#{string}\e[0m" else string end end |
#lucid(n) ⇒ Object
151 152 153 |
# File 'lib/lucid/formatter/ansicolor.rb', line 151 def lucid(n) ('(::) ' * n).strip end |
#red_lucid(n) ⇒ Object
159 160 161 |
# File 'lib/lucid/formatter/ansicolor.rb', line 159 def red_lucid(n) blink(red(lucid(n))) end |
#yellow_lucid(n) ⇒ Object
163 164 165 |
# File 'lib/lucid/formatter/ansicolor.rb', line 163 def yellow_lucid(n) blink(yellow(lucid(n))) end |