Created
August 12, 2025 14:42
-
-
Save ChaelCodes/bffc821e92d439b2c79c36e1fa450264 to your computer and use it in GitHub Desktop.
Demo of setting CLI colors in Ruby using ANSI escape codes
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
# frozen_string_literal: true | |
# colors.rb | |
# ANSI color codes for foreground text | |
COLORS = { | |
black: "\e[30m", | |
red: "\e[31m", | |
green: "\e[32m", | |
yellow: "\e[33m", | |
blue: "\e[34m", | |
magenta: "\e[35m", | |
cyan: "\e[36m", | |
white: "\e[37m" | |
}.freeze | |
# Reset code to clear formatting | |
RESET = "\e[0m" | |
# Print "Hello World" in each color | |
COLORS.each do |color_name, color_code| | |
puts "#{color_code}Hello World#{RESET} (#{color_name})" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment