Module: Kolorit::Linux

Included in:
Windows
Defined in:
lib/kolorit/linux.rb

Overview

Color codes for Linux systems. Allow use of color methods in many different ways.

Include methods outside of main module to use them directly on string (or integer, array, hash). This is done when you call ‘require ’kolorit’‘. You can also just include it in class where you want to use it:

Examples:

Include Kolorit::Linux in just one class


class MyClass
  require 'kolorit/linux'
  include Kolorit::Linux
  # rest_of_code
end

Use color named methods


red 'Hello Red Ruby!'
# or
green 'Hello Green Ruby!'

Use colorize/kolorize methods


colorize :red, 'Hello Red Ruby!'
# or
kolorize 'Ruby goes green, again!', :green

Colorize also accept block


# colorize accept color as first argument

colorize(:green) do
  case @var = SomeClass.call_some_method
  when 'some response'
    "do_something_with_response #{@var}"
  else
    # in this situation #red has precedence over #green
    red("Returned Error for #{@var}")
  end
end

# kolorize accept string as first argument

kolorize(@result) { @result.is_a?(String) ? :green : :red }

See Also:

Instance Method Summary collapse

Instance Method Details



97
98
99
# File 'lib/kolorit/linux.rb', line 97

def blink(str = nil)
  kolor(5, str)
end

#blue(str = nil) ⇒ Object



69
70
71
# File 'lib/kolorit/linux.rb', line 69

def blue(str = nil)
  kolor(34, str)
end

#bold(str = nil) ⇒ Object



85
86
87
# File 'lib/kolorit/linux.rb', line 85

def bold(str = nil)
  kolor(1, str)
end

#colorize(color, string = nil, &blk) ⇒ Object



107
108
109
110
111
# File 'lib/kolorit/linux.rb', line 107

def colorize(color, string = nil, &blk)
  string = yield(blk) if block_given?
  color = KOLORS[color.to_sym] unless color.is_a?(Integer)
  kolor color, string
end

#cyan(str = nil) ⇒ Object



77
78
79
# File 'lib/kolorit/linux.rb', line 77

def cyan(str = nil)
  kolor(36, str)
end

#gray(str = nil) ⇒ Object



81
82
83
# File 'lib/kolorit/linux.rb', line 81

def gray(str = nil)
  kolor(37, str)
end

#green(str = nil) ⇒ Object



61
62
63
# File 'lib/kolorit/linux.rb', line 61

def green(str = nil)
  kolor(32, str)
end

#italic(str = nil) ⇒ Object



89
90
91
# File 'lib/kolorit/linux.rb', line 89

def italic(str = nil)
  kolor(3, str)
end

#kolorize(string, color = nil, &blk) ⇒ Object



113
114
115
116
117
# File 'lib/kolorit/linux.rb', line 113

def kolorize(string, color = nil, &blk)
  color = yield(blk) if block_given?
  color = KOLORS[color.to_sym] unless color.is_a?(Integer)
  kolor color, string
end

#pink(str = nil) ⇒ Object



73
74
75
# File 'lib/kolorit/linux.rb', line 73

def pink(str = nil)
  kolor(35, str)
end

#red(str = nil) ⇒ Object



57
58
59
# File 'lib/kolorit/linux.rb', line 57

def red(str = nil)
  kolor(31, str)
end

#reverse_color(str = nil) ⇒ Object Also known as: inverse



101
102
103
# File 'lib/kolorit/linux.rb', line 101

def reverse_color(str = nil)
  kolor(7, str)
end

#underline(str = nil) ⇒ Object



93
94
95
# File 'lib/kolorit/linux.rb', line 93

def underline(str = nil)
  kolor(4, str)
end

#yellow(str = nil) ⇒ Object



65
66
67
# File 'lib/kolorit/linux.rb', line 65

def yellow(str = nil)
  kolor(33, str)
end