You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here is a basic example demonstrating how to apply colors and styles to terminal output:
puts"This is a red text.".redputs"This is a yellow text.".color("yellow")puts"This is a text with a blue background.".bg_blueputs"This is a text with a green background.".color(nil,:green)puts"This is a bold text.".boldputs"This is an underlined text.".underline
Available Colors
black
red
green
yellow
blue
magenta
cyan
white
gray
bright_black
bright_red
bright_green
bright_yellow
bright_blue
bright_magenta
bright_cyan
bright_white
default
Available Styles
bold
underline
blink
reverse
invisible
reset
8-bit Color
You can specify 8-bit colors using a number between 0 and 255:
puts"This is a text with 8-bit color.".color(42)
24-bit Color
You can specify 24-bit colors using a hexadecimal color code in the format #RRGGBB:
puts"This is a text with 24-bit color.".color('#FF5733')
Combining Colors and Styles
You can combine multiple styles with colors:
puts"This is a bold and red text.".red.boldputs"This is a text with bold and 8-bit color.".color(42).boldputs"This is a text with underline and 24-bit color.".color('#FF5733').underline
Validating Colors and Modes
You can validate color codes and modes using the following methods:
# Validate if a color code is correct (supports 4-bit, 8-bit, and 24-bit color codes)putsTerminalColor.valid?(:red)# => true for 4-bitputsTerminalColor.valid?(42)# => true for 8-bitputsTerminalColor.valid?('#FF5733')# => true for 24-bitputsTerminalColor.valid?('invalid')# => false# Validate if a mode is correctputsTerminalColor.valid_mode?(:bold)# => trueputsTerminalColor.valid_mode?(:invalid)# => false
C Function
For C language integration, you can use the following function: