Created
          December 17, 2009 08:06 
        
      - 
      
- 
        Save nas/258614 to your computer and use it in GitHub Desktop. 
    Colour strings
  
        
  
    
      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
    
  
  
    
  | # taken and modified from http://www.andrewmcdonough.com/2009/10/20/colorized-logs-in-ruby | |
| def colorify(string, color, options = {}) | |
| offsets = ["gray","red", "green", "yellow", "blue", "magenta", "cyan","white"] | |
| # I don't think below LOC is quite right due to the fact that xx and underline strings | |
| # are appearing multiple times; will fix it when I am about to use this script. | |
| styles = ["normal","bold","dark","italic","underline","xx","xx","underline","xx","strikethrough"] | |
| start = options[:bg] ? 40 : 30 | |
| color_code = start + offsets.index(color) | |
| style_code = styles.index(options[:style]) || 0 | |
| "\e[#{style_code};#{color_code}m#{string}\e[0m" | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment