teeworlds_network/lib/string.rb

82 lines
955 B
Ruby
Raw Normal View History

# frozen_string_literal: true
AVAILABLE_COLORS = %i[
2022-11-17 13:57:39 +00:00
red green yellow pink magenta blue cyan white
bg_red bg_green bg_yellow bg_pink bg_magenta bg_blue bg_cyan bg_white
].freeze
# String color
class String
def colorize(color_code)
"\e[#{color_code}m#{self}\e[0m"
end
2022-11-17 13:57:39 +00:00
# foreground
def red
colorize(31)
end
def green
colorize(32)
end
def yellow
colorize(33)
end
2022-11-17 13:57:39 +00:00
def blue
colorize(34)
end
def pink
colorize(35)
end
2022-11-17 13:57:39 +00:00
# keklul pink alias
def magenta
colorize(35)
end
def cyan
colorize(36)
end
def white
colorize(37)
end
# background
def bg_red
colorize(41)
end
def bg_green
colorize(42)
end
def bg_yellow
colorize(43)
end
def bg_blue
colorize(44)
end
def bg_pink
colorize(45)
end
# keklul pink alias
def bg_magenta
colorize(45)
end
def bg_cyan
colorize(46)
end
def bg_white
colorize(47)
end
end