Create a gist now

Instantly share code, notes, and snippets.

Colorize logcat output
#!/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