Skip to content

Instantly share code, notes, and snippets.

@ChaelCodes
Created August 12, 2025 14:42
Show Gist options
  • Save ChaelCodes/bffc821e92d439b2c79c36e1fa450264 to your computer and use it in GitHub Desktop.
Save ChaelCodes/bffc821e92d439b2c79c36e1fa450264 to your computer and use it in GitHub Desktop.
Demo of setting CLI colors in Ruby using ANSI escape codes
# 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