Module: CommandKit::Colors::ANSI

Defined in:
lib/command_kit/colors.rb

Overview

Applies ANSI formatting to text.

Constant Summary collapse

RESET =

ANSI reset code

"\e[0m"
CLEAR =

See Also:

RESET
BOLD =

ANSI code for bold text

"\e[1m"
RESET_INTENSITY =

ANSI code to disable boldness

"\e[22m"
BLACK =

ANSI color code for black

"\e[30m"
RED =

ANSI color code for red

"\e[31m"
GREEN =

ANSI color code for green

"\e[32m"
YELLOW =

ANSI color code for yellow

"\e[33m"
BLUE =

ANSI color code for blue

"\e[34m"
MAGENTA =

ANSI color code for megenta

"\e[35m"
CYAN =

ANSI color code for cyan

"\e[36m"
WHITE =

ANSI color code for white

"\e[37m"
RESET_COLOR =

ANSI color for the default foreground color

"\e[39m"

Class Method Summary collapse

Class Method Details

.black(string = nil) ⇒ String, BLACK

Sets the text color to black.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, BLACK)

    The colorized string or just BLACK if no arguments were given.

See Also:



138
139
140
141
142
# File 'lib/command_kit/colors.rb', line 138

def black(string=nil)
  if string then "#{BLACK}#{string}#{RESET_COLOR}"
  else           BLACK
  end
end

.blue(string = nil) ⇒ String, BLUE

Sets the text color to blue.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, BLUE)

    The colorized string or just BLUE if no arguments were given.

See Also:



214
215
216
217
218
# File 'lib/command_kit/colors.rb', line 214

def blue(string=nil)
  if string then "#{BLUE}#{string}#{RESET_COLOR}"
  else           BLUE
  end
end

.bold(string = nil) ⇒ String, BOLD

Bolds the text.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, BOLD)

    The bolded string or just BOLD if no arguments were given.

See Also:



119
120
121
122
123
# File 'lib/command_kit/colors.rb', line 119

def bold(string=nil)
  if string then "#{BOLD}#{string}#{RESET_INTENSITY}"
  else           BOLD
  end
end

.clearObject

See Also:



102
103
104
# File 'lib/command_kit/colors.rb', line 102

def clear
  reset
end

.cyan(string = nil) ⇒ String, CYAN

Sets the text color to cyan.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, CYAN)

    The colorized string or just CYAN if no arguments were given.

See Also:



252
253
254
255
256
# File 'lib/command_kit/colors.rb', line 252

def cyan(string=nil)
  if string then "#{CYAN}#{string}#{RESET_COLOR}"
  else           CYAN
  end
end

.green(string = nil) ⇒ String, GREEN

Sets the text color to green.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, GREEN)

    The colorized string or just GREEN if no arguments were given.

See Also:



176
177
178
179
180
# File 'lib/command_kit/colors.rb', line 176

def green(string=nil)
  if string then "#{GREEN}#{string}#{RESET_COLOR}"
  else           GREEN
  end
end

.magenta(string = nil) ⇒ String, MAGENTA

Sets the text color to magenta.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, MAGENTA)

    The colorized string or just MAGENTA if no arguments were given.

See Also:



233
234
235
236
237
# File 'lib/command_kit/colors.rb', line 233

def magenta(string=nil)
  if string then "#{MAGENTA}#{string}#{RESET_COLOR}"
  else           MAGENTA
  end
end

.red(string = nil) ⇒ String, RED

Sets the text color to red.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, RED)

    The colorized string or just RED if no arguments were given.

See Also:



157
158
159
160
161
# File 'lib/command_kit/colors.rb', line 157

def red(string=nil)
  if string then "#{RED}#{string}#{RESET_COLOR}"
  else           RED
  end
end

.resetRESET

Resets text formatting.

Returns:

See Also:



93
94
95
# File 'lib/command_kit/colors.rb', line 93

def reset
  RESET
end

.white(string = nil) ⇒ String, WHITE

Sets the text color to white.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, WHITE)

    The colorized string or just WHITE if no arguments were given.

See Also:



271
272
273
274
275
# File 'lib/command_kit/colors.rb', line 271

def white(string=nil)
  if string then "#{WHITE}#{string}#{RESET_COLOR}"
  else           WHITE
  end
end

.yellow(string = nil) ⇒ String, YELLOW

Sets the text color to yellow.

Parameters:

  • string (String, nil) (defaults to: nil)

    An optional string.

Returns:

  • (String, YELLOW)

    The colorized string or just YELLOW if no arguments were given.

See Also:



195
196
197
198
199
# File 'lib/command_kit/colors.rb', line 195

def yellow(string=nil)
  if string then "#{YELLOW}#{string}#{RESET_COLOR}"
  else           YELLOW
  end
end