Created
December 7, 2011 21:06
-
-
Save spudtrooper/1444660 to your computer and use it in GitHub Desktop.
Colorize logcat output
This file contains 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
#!/usr/bin/env ruby | |
# | |
# Colorizes adb output, e.g. | |
# | |
# adb logcat | adb_colorize | |
# | |
ESC = "\033" | |
CLOSE = ESC + '[0m' | |
def color(c) | |
"#{ESC}[0;#{c}m" | |
end | |
BLACK = color 30 | |
RED = color 31 | |
GREEN = color 32 | |
YELLOW = color 33 | |
BLUE = color 34 | |
MAGENTA = color 35 | |
CYAN = color 36 | |
WHITE = color 37 | |
levels2colors = { | |
/^V\// => RED, | |
/^D\// => CYAN, | |
/^I\// => GREEN, | |
/^W\// => YELLOW, | |
/^E\// => MAGENTA, | |
/^F\// => WHITE, | |
} | |
ARGF.each do |line| | |
levels2colors.each do |re,color| | |
if line =~ re | |
line = color + line + CLOSE | |
break | |
end | |
end | |
print line | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment