Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
Created July 30, 2010 19:29
Show Gist options
  • Save leandrosilva/73e993f19e8e13963204 to your computer and use it in GitHub Desktop.
Save leandrosilva/73e993f19e8e13963204 to your computer and use it in GitHub Desktop.
Output colorization in Ruby
Code Effect
0 Turn off all attributes
1 Set bright mode
4 Set underline mode
5 Set blink mode
7 Exchange foreground and background colors
8 Hide text (foreground color would be the same as background)
30 Black text
31 Red text
32 Green text
33 Yellow text
34 Blue text
35 Magenta text
36 Cyan text
37 White text
39 Default text color
40 Black background
41 Red background
42 Green background
43 Yellow background
44 Blue background
45 Magenta background
46 Cyan background
47 White background
49 Default background color
def colorize(text, color_code)
"\e[#{color_code}#{text}\e[0m"
end
def print_red(text)
puts colorize(text, "31m")
end
print_read("panic!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment