Skip to content

Instantly share code, notes, and snippets.

@spudtrooper
Created December 7, 2011 21:06
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 spudtrooper/1444660 to your computer and use it in GitHub Desktop.
Save spudtrooper/1444660 to your computer and use it in GitHub Desktop.
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