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 =
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
"\e[90m"
- BRIGHT_RED =
ANSI color code for red
"\e[91m"
- BRIGHT_GREEN =
ANSI color code for green
"\e[92m"
- BRIGHT_YELLOW =
ANSI color code for yellow
"\e[93m"
- BRIGHT_BLUE =
ANSI color code for blue
"\e[94m"
- BRIGHT_MAGENTA =
ANSI color code for magenta
"\e[95m"
- BRIGHT_CYAN =
ANSI color code for cyan
"\e[96m"
- BRIGHT_WHITE =
ANSI color code for white
"\e[97m"
- RESET_FG =
ANSI color for the default foreground color
"\e[39m"
- RESET_COLOR =
RESET_FG
- ON_BLACK =
ANSI color code for background color black
"\e[40m"
- ON_RED =
ANSI color code for background color red
"\e[41m"
- ON_GREEN =
ANSI color code for background color green
"\e[42m"
- ON_YELLOW =
ANSI color code for background color yellow
"\e[43m"
- ON_BLUE =
ANSI color code for background color blue
"\e[44m"
- ON_MAGENTA =
ANSI color code for background color magenta
"\e[45m"
- ON_CYAN =
ANSI color code for background color cyan
"\e[46m"
- ON_WHITE =
ANSI color code for background color white
"\e[47m"
- ON_BRIGHT_BLACK =
ANSI color code for background color bright black
"\e[100m"
- ON_BRIGHT_RED =
ANSI color code for background color bright red
"\e[101m"
- ON_BRIGHT_GREEN =
ANSI color code for background color bright green
"\e[102m"
- ON_BRIGHT_YELLOW =
ANSI color code for background color bright yellow
"\e[103m"
- ON_BRIGHT_BLUE =
ANSI color code for background color bright blue
"\e[104m"
- ON_BRIGHT_MAGENTA =
ANSI color code for background color bright magenta
"\e[105m"
- ON_BRIGHT_CYAN =
ANSI color code for background color bright cyan
"\e[106m"
- ON_BRIGHT_WHITE =
ANSI color code for background color bright white
"\e[107m"
- RESET_BG =
ANSI color for the default background color
"\e[49m"
Styling Methods collapse
-
.bold(string = nil) ⇒ String, BOLD
Bolds the text.
- .clear ⇒ Object
-
.reset ⇒ RESET
Resets text formatting.
Foreground Color Methods collapse
-
.black(string = nil) ⇒ String, BLACK
Sets the text color to black.
-
.blue(string = nil) ⇒ String, BLUE
Sets the text color to blue.
-
.bright_black(string = nil) ⇒ String, BRIGHT_BLACK
Sets the text color to bright black (gray).
-
.bright_blue(string = nil) ⇒ String, BRIGHT_BLUE
Sets the text color to bright blue.
-
.bright_cyan(string = nil) ⇒ String, BRIGHT_CYAN
Sets the text color to bright cyan.
-
.bright_green(string = nil) ⇒ String, BRIGHT_GREEN
Sets the text color to bright green.
-
.bright_magenta(string = nil) ⇒ String, BRIGHT_MAGENTA
Sets the text color to bright magenta.
-
.bright_red(string = nil) ⇒ String, BRIGHT_RED
Sets the text color to bright red.
-
.bright_white(string = nil) ⇒ String, BRIGHT_WHITE
Sets the text color to bright white.
-
.bright_yellow(string = nil) ⇒ String, BRIGHT_YELLOW
Sets the text color to bright yellow.
-
.cyan(string = nil) ⇒ String, CYAN
Sets the text color to cyan.
-
.gray(string = nil) ⇒ Object
Sets the text color to gray.
-
.green(string = nil) ⇒ String, GREEN
Sets the text color to green.
-
.magenta(string = nil) ⇒ String, MAGENTA
Sets the text color to magenta.
-
.red(string = nil) ⇒ String, RED
Sets the text color to red.
-
.white(string = nil) ⇒ String, WHITE
Sets the text color to white.
-
.yellow(string = nil) ⇒ String, YELLOW
Sets the text color to yellow.
Background Color Methods collapse
-
.on_black(string = nil) ⇒ String, ON_BLACK
Sets the background color to black.
-
.on_blue(string = nil) ⇒ String, ON_BLUE
Sets the background color to blue.
-
.on_bright_black(string = nil) ⇒ String, ON_BRIGHT_BLACK
Sets the background color to bright black.
-
.on_bright_blue(string = nil) ⇒ String, ON_BRIGHT_BLUE
Sets the background color to bright blue.
-
.on_bright_cyan(string = nil) ⇒ String, ON_BRIGHT_CYAN
Sets the background color to bright cyan.
-
.on_bright_green(string = nil) ⇒ String, ON_BRIGHT_GREEN
Sets the background color to bright green.
-
.on_bright_magenta(string = nil) ⇒ String, ON_BRIGHT_MAGENTA
Sets the background color to bright magenta.
-
.on_bright_red(string = nil) ⇒ String, ON_BRIGHT_RED
Sets the background color to bright red.
-
.on_bright_white(string = nil) ⇒ String, ON_BRIGHT_WHITE
Sets the background color to bright white.
-
.on_bright_yellow(string = nil) ⇒ String, ON_BRIGHT_YELLOW
Sets the background color to bright yellow.
-
.on_cyan(string = nil) ⇒ String, ON_CYAN
Sets the background color to cyan.
- .on_gray(string = nil) ⇒ Object
-
.on_green(string = nil) ⇒ String, ON_GREEN
Sets the background color to green.
-
.on_magenta(string = nil) ⇒ String, ON_MAGENTA
Sets the background color to magenta.
-
.on_red(string = nil) ⇒ String, ON_RED
Sets the background color to red.
-
.on_white(string = nil) ⇒ String, ON_WHITE
Sets the background color to white.
-
.on_yellow(string = nil) ⇒ String, ON_YELLOW
Sets the background color to yellow.
Class Method Details
.black(string = nil) ⇒ String, BLACK
Sets the text color to black.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
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 |
.clear ⇒ Object
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
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.
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.
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.
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.
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.
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.
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 |
.reset ⇒ RESET
Resets text formatting.
227 228 229 |
# File 'lib/command_kit/colors.rb', line 227 def reset RESET end |