Skip to content

Instantly share code, notes, and snippets.

@mebens
Created April 20, 2011 23:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mebens/933311 to your computer and use it in GitHub Desktop.
Save mebens/933311 to your computer and use it in GitHub Desktop.
Simple module for colour output to the terminal.
module ColorOutput
RED = 31
GREEN = 32
YELLOW = 33
BLUE = 34
MAGENTA = 35
CYAN = 36
def self.wrap(s, start_code, end_code = nil)
end_code = start_code - (start_code % 10) + 9 if end_code.nil?
"\x1b[#{start_code}m#{s}\x1b[#{end_code}m"
end
def self.bold(s)
wrap(s, 1, 22)
end
end
puts ColorOutput.wrap("Warning! Uh... something's going wrong... don't know what though.", ColorOutput::RED)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment