Created
March 12, 2022 00:52
-
-
Save brand-it/d4af312ec6a301645471578c6361cc8c to your computer and use it in GitHub Desktop.
I don't know who created this origionaly I but I know some one did. I did some googling to find the original but could not.
This file contains hidden or 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
# PrettyString.new('something').blue | |
# PrettyString.new('something').red | |
# PrettyString.new('something').green | |
# PrettyString.new('something').yellow | |
# PrettyString.new('something').magenta | |
# PrettyString.new('something').white | |
class PrettyString < String | |
# https://no-color.org/ | |
NO_COLOR = ENV.key?('NO_COLOR') || `tput colors`.chomp.to_i < 8 | |
ANSI_COLORS = { | |
white: 0, | |
red: 31, | |
green: 32, | |
yellow: 33, | |
blue: 34, | |
magenta: 35 | |
}.freeze | |
ANSI_COLORS.each do |name, code| | |
define_method(name) { NO_COLOR ? self : "\e[#{code}m#{self}\e[0m" } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment