Module: Ops::Console
Constant Summary collapse
- OPTIONS =
{ :bold => 1, :underline => 4 }
- COLORS =
{ :black => 30, :red => 31, :green => 32, :yellow => 33, :blue => 34, :magenta => 35, :cyan => 36, :white => 37 }
- BG_COLORS =
{ :black => 40, :red => 41, :green => 42, :yellow => 43, :blue => 44, :magenta => 45, :cyan => 46, :white => 47 }
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.bash_exec!(cmd) ⇒ Object
22 23 24 25 |
# File 'lib/ops/console.rb', line 22 def self.bash_exec!( cmd ) bash = `which bash`.strip `#{ bash } -c #{ cmd }"` end |
.is_bash? ⇒ Boolean
17 18 19 20 |
# File 'lib/ops/console.rb', line 17 def self.is_bash? `which bash` ( $? == 0 ) ? true : false end |
.reload! ⇒ Object
13 14 15 |
# File 'lib/ops/console.rb', line 13 def self.reload! end |
Instance Method Details
#print(string, opts = []) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/ops/console.rb', line 27 def print( string, opts = [] ) c = [] opts.each { | o | c << COLORS[ o ] if COLORS.has_key?( o ) } opts.each { | o | c << OPTIONS[ o ] if OPTIONS.has_key?( o ) } "\033[#{ c.join( ";" ) }m#{ string }\033[0m" end |
#random_color ⇒ Object
35 36 37 38 39 |
# File 'lib/ops/console.rb', line 35 def random_color colors = COLORS.keys + BG_COLORS.keys colors.reject!{ | c | [ :white, :black ].include? c } colors.sample end |