Module: Command::Results::Formatter::Styler
- Included in:
- StrategyFormatter::FormatStrategy
- Defined in:
- lib/command-set/formatter/base.rb
Constant Summary collapse
- Foregrounds =
{ 'black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37 }
- Backgrounds =
{}
- Extras =
{ 'clear' => 0, 'bold' => 1, 'underline' => 4, 'reversed' => 7 }
Instance Method Summary collapse
Instance Method Details
#code_for(kind, name) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/command-set/formatter/base.rb', line 51 def code_for(kind, name) if kind.has_key?(name.to_s) "\e[#{kind[name.to_s]}m" else "" end end |
#style(text, options) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/command-set/formatter/base.rb', line 34 def style(text, ) ||= {} if .key? :format_advice = .merge([:format_advice]) end aliased = { :foreground => [:color], :extra => [:text_style] } = aliased.merge() markup = code_for(Foregrounds, [:foreground]) + code_for(Backgrounds, [:background]) + code_for(Extras, [:extra]) return text if markup.empty? return markup + text + code_for(Extras, "clear") end |