#!/usr/bin/env python
# -*- coding: utf-8 -*-

# NEED_SYMLINK

# ***************************************************************************
# *   Copyright (C) 2013, Paul Lutus                                        *
# *                                                                         *
# *   This program is free software; you can redistribute it and/or modify  *
# *   it under the terms of the GNU General Public License as published by  *
# *   the Free Software Foundation; either version 2 of the License, or     *
# *   (at your option) any later version.                                   *
# *                                                                         *
# *   This program is distributed in the hope that it will be useful,       *
# *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
# *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
# *   GNU General Public License for more details.                          *
# *                                                                         *
# *   You should have received a copy of the GNU General Public License     *
# *   along with this program; if not, write to the                         *
# *   Free Software Foundation, Inc.,                                       *
# *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
# ***************************************************************************

# Created on Nov 13, 2013 5:41:26 PM

import re,sys,os

# purpose: syntax-highlight Android logcat listings

# ANSI color scheme: http://en.wikipedia.org/wiki/ANSI_escape_code

# map error codes to colors
  
cmap = {'D':'38;5;75','I':'38;5;40','W':'38;5;166','E':'38;5;196','F':'38;5;201'}

while(True):
  try:
    line = sys.stdin.readline()
    key = re.sub('(?s).*([DIWEF])/.*','\\1',line)
    if(key in cmap):
      line = '\033[{0}m{1}\033[0m'.format(cmap[key],line)
    sys.stdout.write(line)
  except KeyboardInterrupt:
    # restore terminal defaults and exit gracefully
    sys.stdout.write("\033[0m")
    sys.exit(0)