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 magenta

"\e[35m"
CYAN =

ANSI color code for cyan

"\e[36m"
WHITE =

ANSI color code for white

"\e[37m"
BRIGHT_BLACK =

ANSI color code for black

Since:

  • 0.3.0

"\e[90m"
BRIGHT_RED =

ANSI color code for red

Since:

  • 0.3.0

"\e[91m"
BRIGHT_GREEN =

ANSI color code for green

Since:

  • 0.3.0

"\e[92m"
BRIGHT_YELLOW =

ANSI color code for yellow

Since:

  • 0.3.0

"\e[93m"
BRIGHT_BLUE =

ANSI color code for blue

Since:

  • 0.3.0

"\e[94m"
BRIGHT_MAGENTA =

ANSI color code for magenta

Since:

  • 0.3.0

"\e[95m"
BRIGHT_CYAN =

ANSI color code for cyan

Since:

  • 0.3.0

"\e[96m"
BRIGHT_WHITE =

ANSI color code for white

Since:

  • 0.3.0

"\e[97m"
RESET_FG =

ANSI color for the default foreground color

Since:

  • 0.3.0

"\e[39m"
RESET_COLOR =

See Also:

RESET_FG
ON_BLACK =

ANSI color code for background color black

Since:

  • 0.2.0

"\e[40m"
ON_RED =

ANSI color code for background color red

Since:

  • 0.2.0

"\e[41m"
ON_GREEN =

ANSI color code for background color green

Since:

  • 0.2.0

"\e[42m"
ON_YELLOW =

ANSI color code for background color yellow

Since:

  • 0.2.0

"\e[43m"
ON_BLUE =

ANSI color code for background color blue

Since:

  • 0.2.0

"\e[44m"
ON_MAGENTA =

ANSI color code for background color magenta

Since:

  • 0.2.0

"\e[45m"
ON_CYAN =

ANSI color code for background color cyan

Since:

  • 0.2.0

"\e[46m"
ON_WHITE =

ANSI color code for background color white

Since:

  • 0.2.0

"\e[47m"
ON_BRIGHT_BLACK =

ANSI color code for background color bright black

Since:

  • 0.3.0

"\e[100m"
ON_BRIGHT_RED =

ANSI color code for background color bright red

Since:

  • 0.3.0

"\e[101m"
ON_BRIGHT_GREEN =

ANSI color code for background color bright green

Since:

  • 0.3.0

"\e[102m"
ON_BRIGHT_YELLOW =

ANSI color code for background color bright yellow

Since:

  • 0.3.0

"\e[103m"
ON_BRIGHT_BLUE =

ANSI color code for background color bright blue

Since:

  • 0.3.0

"\e[104m"
ON_BRIGHT_MAGENTA =

ANSI color code for background color bright magenta

Since:

  • 0.3.0

"\e[105m"
ON_BRIGHT_CYAN =

ANSI color code for background color bright cyan

Since:

  • 0.3.0

"\e[106m"
ON_BRIGHT_WHITE =

ANSI color code for background color bright white

Since:

  • 0.3.0

"\e[107m"
RESET_BG =

ANSI color for the default background color

Since:

  • 0.2.0

"\e[49m"

Styling Methods collapse

Foreground Color Methods collapse

Background Color Methods 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:



276
277
278
279
280
# File 'lib/command_kit/colors.rb', line 276

def black(string=nil)
  if string then "#{BLACK}#{string}#{RESET_FG}"
  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:



352
353
354
355
356
# File 'lib/command_kit/colors.rb', line 352

def blue(string=nil)
  if string then "#{BLUE}#{string}#{RESET_FG}"
  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:



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

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

.bright_black(string = nil) ⇒ String, BRIGHT_BLACK

Sets the text color to bright black (gray).

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



431
432
433
434
435
# File 'lib/command_kit/colors.rb', line 431

def bright_black(string=nil)
  if string then "#{BRIGHT_BLACK}#{string}#{RESET_FG}"
  else           BRIGHT_BLACK
  end
end

.bright_blue(string = nil) ⇒ String, BRIGHT_BLUE

Sets the text color to bright blue.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



530
531
532
533
534
# File 'lib/command_kit/colors.rb', line 530

def bright_blue(string=nil)
  if string then "#{BRIGHT_BLUE}#{string}#{RESET_FG}"
  else           BRIGHT_BLUE
  end
end

.bright_cyan(string = nil) ⇒ String, BRIGHT_CYAN

Sets the text color to bright cyan.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



573
574
575
576
577
# File 'lib/command_kit/colors.rb', line 573

def bright_cyan(string=nil)
  if string then "#{BRIGHT_CYAN}#{string}#{RESET_FG}"
  else           BRIGHT_CYAN
  end
end

.bright_green(string = nil) ⇒ String, BRIGHT_GREEN

Sets the text color to bright green.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



487
488
489
490
491
# File 'lib/command_kit/colors.rb', line 487

def bright_green(string=nil)
  if string then "#{BRIGHT_GREEN}#{string}#{RESET_FG}"
  else           BRIGHT_GREEN
  end
end

.bright_magenta(string = nil) ⇒ String, BRIGHT_MAGENTA

Sets the text color to bright magenta.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



552
553
554
555
556
# File 'lib/command_kit/colors.rb', line 552

def bright_magenta(string=nil)
  if string then "#{BRIGHT_MAGENTA}#{string}#{RESET_FG}"
  else           BRIGHT_MAGENTA
  end
end

.bright_red(string = nil) ⇒ String, BRIGHT_RED

Sets the text color to bright red.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



465
466
467
468
469
# File 'lib/command_kit/colors.rb', line 465

def bright_red(string=nil)
  if string then "#{BRIGHT_RED}#{string}#{RESET_FG}"
  else           BRIGHT_RED
  end
end

.bright_white(string = nil) ⇒ String, BRIGHT_WHITE

Sets the text color to bright white.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



595
596
597
598
599
# File 'lib/command_kit/colors.rb', line 595

def bright_white(string=nil)
  if string then "#{BRIGHT_WHITE}#{string}#{RESET_FG}"
  else           BRIGHT_WHITE
  end
end

.bright_yellow(string = nil) ⇒ String, BRIGHT_YELLOW

Sets the text color to bright yellow.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



509
510
511
512
513
# File 'lib/command_kit/colors.rb', line 509

def bright_yellow(string=nil)
  if string then "#{BRIGHT_YELLOW}#{string}#{RESET_FG}"
  else           BRIGHT_YELLOW
  end
end

.clearObject

See Also:



236
237
238
# File 'lib/command_kit/colors.rb', line 236

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:



390
391
392
393
394
# File 'lib/command_kit/colors.rb', line 390

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

.gray(string = nil) ⇒ Object

Sets the text color to gray.

See Also:

  • #bright_black

Since:

  • 0.3.0



446
447
448
# File 'lib/command_kit/colors.rb', line 446

def gray(string=nil)
  bright_black(string)
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:



314
315
316
317
318
# File 'lib/command_kit/colors.rb', line 314

def green(string=nil)
  if string then "#{GREEN}#{string}#{RESET_FG}"
  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:



371
372
373
374
375
# File 'lib/command_kit/colors.rb', line 371

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

.on_black(string = nil) ⇒ String, ON_BLACK

Sets the background color to black.

Parameters:

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

    An optional string.

Returns:

  • (String, ON_BLACK)

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

See Also:

Since:

  • 0.2.0



620
621
622
623
624
# File 'lib/command_kit/colors.rb', line 620

def on_black(string=nil)
  if string then "#{ON_BLACK}#{string}#{RESET_BG}"
  else           ON_BLACK
  end
end

.on_blue(string = nil) ⇒ String, ON_BLUE

Sets the background color to blue.

Parameters:

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

    An optional string.

Returns:

  • (String, ON_BLUE)

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

See Also:

Since:

  • 0.2.0



704
705
706
707
708
# File 'lib/command_kit/colors.rb', line 704

def on_blue(string=nil)
  if string then "#{ON_BLUE}#{string}#{RESET_BG}"
  else           ON_BLUE
  end
end

.on_bright_black(string = nil) ⇒ String, ON_BRIGHT_BLACK

Sets the background color to bright black.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



789
790
791
792
793
# File 'lib/command_kit/colors.rb', line 789

def on_bright_black(string=nil)
  if string then "#{ON_BRIGHT_BLACK}#{string}#{RESET_BG}"
  else           ON_BRIGHT_BLACK
  end
end

.on_bright_blue(string = nil) ⇒ String, ON_BRIGHT_BLUE

Sets the background color to bright blue.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



888
889
890
891
892
# File 'lib/command_kit/colors.rb', line 888

def on_bright_blue(string=nil)
  if string then "#{ON_BRIGHT_BLUE}#{string}#{RESET_BG}"
  else           ON_BRIGHT_BLUE
  end
end

.on_bright_cyan(string = nil) ⇒ String, ON_BRIGHT_CYAN

Sets the background color to bright cyan.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



932
933
934
935
936
# File 'lib/command_kit/colors.rb', line 932

def on_bright_cyan(string=nil)
  if string then "#{ON_BRIGHT_CYAN}#{string}#{RESET_BG}"
  else           ON_BRIGHT_CYAN
  end
end

.on_bright_green(string = nil) ⇒ String, ON_BRIGHT_GREEN

Sets the background color to bright green.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



844
845
846
847
848
# File 'lib/command_kit/colors.rb', line 844

def on_bright_green(string=nil)
  if string then "#{ON_BRIGHT_GREEN}#{string}#{RESET_BG}"
  else           ON_BRIGHT_GREEN
  end
end

.on_bright_magenta(string = nil) ⇒ String, ON_BRIGHT_MAGENTA

Sets the background color to bright magenta.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



910
911
912
913
914
# File 'lib/command_kit/colors.rb', line 910

def on_bright_magenta(string=nil)
  if string then "#{ON_BRIGHT_MAGENTA}#{string}#{RESET_BG}"
  else           ON_BRIGHT_MAGENTA
  end
end

.on_bright_red(string = nil) ⇒ String, ON_BRIGHT_RED

Sets the background color to bright red.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



822
823
824
825
826
# File 'lib/command_kit/colors.rb', line 822

def on_bright_red(string=nil)
  if string then "#{ON_BRIGHT_RED}#{string}#{RESET_BG}"
  else           ON_BRIGHT_RED
  end
end

.on_bright_white(string = nil) ⇒ String, ON_BRIGHT_WHITE

Sets the background color to bright white.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



954
955
956
957
958
# File 'lib/command_kit/colors.rb', line 954

def on_bright_white(string=nil)
  if string then "#{ON_BRIGHT_WHITE}#{string}#{RESET_BG}"
  else           ON_BRIGHT_WHITE
  end
end

.on_bright_yellow(string = nil) ⇒ String, ON_BRIGHT_YELLOW

Sets the background color to bright yellow.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.3.0



866
867
868
869
870
# File 'lib/command_kit/colors.rb', line 866

def on_bright_yellow(string=nil)
  if string then "#{ON_BRIGHT_YELLOW}#{string}#{RESET_BG}"
  else           ON_BRIGHT_YELLOW
  end
end

.on_cyan(string = nil) ⇒ String, ON_CYAN

Sets the background color to cyan.

Parameters:

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

    An optional string.

Returns:

  • (String, ON_CYAN)

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

See Also:

Since:

  • 0.2.0



746
747
748
749
750
# File 'lib/command_kit/colors.rb', line 746

def on_cyan(string=nil)
  if string then "#{ON_CYAN}#{string}#{RESET_BG}"
  else           ON_CYAN
  end
end

.on_gray(string = nil) ⇒ Object

See Also:

  • #on_bright_black

Since:

  • 0.3.0



802
803
804
# File 'lib/command_kit/colors.rb', line 802

def on_gray(string=nil)
  on_bright_black(string)
end

.on_green(string = nil) ⇒ String, ON_GREEN

Sets the background color to green.

Parameters:

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

    An optional string.

Returns:

  • (String, ON_GREEN)

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

See Also:

Since:

  • 0.2.0



662
663
664
665
666
# File 'lib/command_kit/colors.rb', line 662

def on_green(string=nil)
  if string then "#{ON_GREEN}#{string}#{RESET_BG}"
  else           ON_GREEN
  end
end

.on_magenta(string = nil) ⇒ String, ON_MAGENTA

Sets the background color to magenta.

Parameters:

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

    An optional string.

Returns:

See Also:

Since:

  • 0.2.0



725
726
727
728
729
# File 'lib/command_kit/colors.rb', line 725

def on_magenta(string=nil)
  if string then "#{ON_MAGENTA}#{string}#{RESET_BG}"
  else           ON_MAGENTA
  end
end

.on_red(string = nil) ⇒ String, ON_RED

Sets the background color to red.

Parameters:

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

    An optional string.

Returns:

  • (String, ON_RED)

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

See Also:

Since:

  • 0.2.0



641
642
643
644
645
# File 'lib/command_kit/colors.rb', line 641

def on_red(string=nil)
  if string then "#{ON_RED}#{string}#{RESET_BG}"
  else           ON_RED
  end
end

.on_white(string = nil) ⇒ String, ON_WHITE

Sets the background color to white.

Parameters:

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

    An optional string.

Returns:

  • (String, ON_WHITE)

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

See Also:

Since:

  • 0.2.0



767
768
769
770
771
# File 'lib/command_kit/colors.rb', line 767

def on_white(string=nil)
  if string then "#{ON_WHITE}#{string}#{RESET_BG}"
  else           ON_WHITE
  end
end

.on_yellow(string = nil) ⇒ String, ON_YELLOW

Sets the background color to yellow.

Parameters:

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

    An optional string.

Returns:

  • (String, ON_YELLOW)

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

See Also:

Since:

  • 0.2.0



683
684
685
686
687
# File 'lib/command_kit/colors.rb', line 683

def on_yellow(string=nil)
  if string then "#{ON_YELLOW}#{string}#{RESET_BG}"
  else           ON_YELLOW
  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:



295
296
297
298
299
# File 'lib/command_kit/colors.rb', line 295

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

.resetRESET

Resets text formatting.

Returns:

See Also:



227
228
229
# File 'lib/command_kit/colors.rb', line 227

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:



409
410
411
412
413
# File 'lib/command_kit/colors.rb', line 409

def white(string=nil)
  if string then "#{WHITE}#{string}#{RESET_FG}"
  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:



333
334
335
336
337
# File 'lib/command_kit/colors.rb', line 333

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