Last active
November 3, 2018 17:54
-
-
Save Al-un/6de71b20585d70b6b38a9d1f267ba1a4 to your computer and use it in GitHub Desktop.
Testing colours printing on various console. Colours source: https://github.com/TwP/logging/blob/master/lib/logging/color_scheme.rb#L211
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Testing colours printing on VisualStudio console and PowerShell to check how | |
# colours are represented. This is for choosing color scheme of logging library | |
# Constants source: https://github.com/TwP/logging/blob/master/lib/logging/color_scheme.rb | |
module Color | |
# Miscellaneous stuff | |
module Misc | |
# Embed in a String to clear all previous ANSI sequences. This *MUST* be | |
# done before the program exits! | |
CLEAR = "\e[0m".freeze | |
RESET = CLEAR # An alias for CLEAR. | |
ERASE_LINE = "\e[K".freeze # Erase the current line of terminal output. | |
ERASE_CHAR = "\e[P".freeze # Erase the character under the cursor. | |
BOLD = "\e[1m".freeze # The start of an ANSI bold sequence. | |
DARK = "\e[2m".freeze # The start of an ANSI dark sequence. (Terminal support uncommon.) | |
UNDERLINE = "\e[4m".freeze # The start of an ANSI underline sequence. | |
UNDERSCORE = UNDERLINE # An alias for UNDERLINE. | |
BLINK = "\e[5m".freeze # The start of an ANSI blink sequence. (Terminal support uncommon.) | |
REVERSE = "\e[7m".freeze # The start of an ANSI reverse sequence. | |
CONCEALED = "\e[8m".freeze # The start of an ANSI concealed sequence. (Terminal support uncommon.) | |
end | |
# Font colors | |
module Font | |
BLACK = "\e[30m".freeze # Set the terminal's foreground ANSI color to black. | |
RED = "\e[31m".freeze # Set the terminal's foreground ANSI color to red. | |
GREEN = "\e[32m".freeze # Set the terminal's foreground ANSI color to green. | |
YELLOW = "\e[33m".freeze # Set the terminal's foreground ANSI color to yellow. | |
BLUE = "\e[34m".freeze # Set the terminal's foreground ANSI color to blue. | |
MAGENTA = "\e[35m".freeze # Set the terminal's foreground ANSI color to magenta. | |
CYAN = "\e[36m".freeze # Set the terminal's foreground ANSI color to cyan. | |
WHITE = "\e[37m".freeze # Set the terminal's foreground ANSI color to white. | |
BRIGHT_RED = "\e[1;31m".freeze # Set the terminal's foreground ANSI color to bright red. | |
BRIGHT_GREEN = "\e[1;32m".freeze # Set the terminal's foreground ANSI color to bright green. | |
BRIGHT_YELLOW = "\e[1;33m".freeze # Set the terminal's foreground ANSI color to bright yellow. | |
BRIGHT_BLUE = "\e[1;34m".freeze # Set the terminal's foreground ANSI color to bright blue. | |
BRIGHT_MAGENTA = "\e[1;35m".freeze # Set the terminal's foreground ANSI color to bright magenta. | |
BRIGHT_CYAN = "\e[1;36m".freeze # Set the terminal's foreground ANSI color to bright cyan. | |
BRIGHT_WHITE = "\e[1;37m".freeze # Set the terminal's foreground ANSI color to bright white. | |
end | |
# Background color | |
module Back | |
ON_BLACK = "\e[40m".freeze # Set the terminal's background ANSI color to black. | |
ON_RED = "\e[41m".freeze # Set the terminal's background ANSI color to red. | |
ON_GREEN = "\e[42m".freeze # Set the terminal's background ANSI color to green. | |
ON_YELLOW = "\e[43m".freeze # Set the terminal's background ANSI color to yellow. | |
ON_BLUE = "\e[44m".freeze # Set the terminal's background ANSI color to blue. | |
ON_MAGENTA = "\e[45m".freeze # Set the terminal's background ANSI color to magenta. | |
ON_CYAN = "\e[46m".freeze # Set the terminal's background ANSI color to cyan. | |
ON_WHITE = "\e[47m".freeze # Set the terminal's background ANSI color to white. | |
ON_BRIGHT_RED = "\e[1;41m".freeze # Set the terminal's background ANSI color to bright red. | |
ON_BRIGHT_GREEN = "\e[1;42m".freeze # Set the terminal's background ANSI color to bright green. | |
ON_BRIGHT_YELLOW = "\e[1;43m".freeze # Set the terminal's background ANSI color to bright yellow. | |
ON_BRIGHT_BLUE = "\e[1;44m".freeze # Set the terminal's background ANSI color to bright blue. | |
ON_BRIGHT_MAGENTA = "\e[1;45m".freeze # Set the terminal's background ANSI color to bright magenta. | |
ON_BRIGHT_CYAN = "\e[1;46m".freeze # Set the terminal's background ANSI color to bright cyan. | |
ON_BRIGHT_WHITE = "\e[1;47m".freeze # Set the terminal's background ANSI color to bright white. | |
end | |
end | |
def color_text(text, color) | |
color_tag = Color::Font.const_get(color.to_s.upcase) | |
color_tag + text + Color::Misc::CLEAR | |
end | |
def color_back(text, color) | |
color_tag = Color::Back.const_get(color.to_s.upcase) | |
color_tag + text + Color::Misc::CLEAR | |
end | |
# Loop through font colours | |
Color::Font.constants.each do |c| | |
text = "This is a long long long text in #{c}" | |
puts color_text(text, c) | |
end | |
puts "" | |
# Loop through background colours | |
Color::Back.constants.each do |b| | |
text_white = "#{Color::Font::WHITE}This is a long long long text in white over #{b}#{Color::Misc::CLEAR}" | |
puts color_back(text_white, b) | |
end | |
puts "" | |
Color::Back.constants.each do |b| | |
text_black = "#{Color::Font::BLACK}TThis is a long long long text in black over #{b}#{Color::Misc::CLEAR}" | |
puts color_back(text_black, b) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment