public
Created

Colorize logcat output

  • Download Gist
adb_colorize
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.