4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

pidcatをwindowsでも使いたい

Last updated at Posted at 2015-07-07

adb logcatをカラー表示してくれるpidcatですが、
WindowsだとANSIカラーのエスケープコードがそのまま表示されてしまい使えません。

そこで、ペロっとGo言語で書いてみました。
github.com/nocd5/crz
他にもエスケープコードがそのまま表示されるプログラムがたまにあるので、そういう場合にも使えるかも。

使い方

python -u pidcat.py | crz

-uオプションは出力のバッファを無効にするオプションです。
これがないとバッファがたまるまで表示されないため、ログが逐次表示されません。
参考:Python で stdout/stderr のバッファを無効にするオプション

pidcatの調整

これは好みですが、コンソールで表示できる色数が少ないWindowsでは色が付かない部分があったので少し調整しました。

pidcat.win.patch
diff --git a/pidcat.py b/pidcat.py
index da15682..60cc2b7 100755
--- a/pidcat.py
+++ b/pidcat.py
@@ -89,7 +89,7 @@ RESET = '\033[0m'
 def termcolor(fg=None, bg=None):
   codes = []
   if fg is not None: codes.append('3%d' % fg)
-  if bg is not None: codes.append('10%d' % bg)
+  if bg is not None: codes.append('4%d' % bg)
   return '\033[%sm' % ';'.join(codes) if codes else ''
 
 def colorize(message, fg=None, bg=None):
@@ -153,11 +153,11 @@ if args.color_gc:
 
 TAGTYPES = {
   'V': colorize(' V ', fg=WHITE, bg=BLACK),
-  'D': colorize(' D ', fg=BLACK, bg=BLUE),
-  'I': colorize(' I ', fg=BLACK, bg=GREEN),
-  'W': colorize(' W ', fg=BLACK, bg=YELLOW),
-  'E': colorize(' E ', fg=BLACK, bg=RED),
-  'F': colorize(' F ', fg=BLACK, bg=RED),
+  'D': colorize(' D ', fg=WHITE, bg=BLUE),
+  'I': colorize(' I ', fg=WHITE, bg=GREEN),
+  'W': colorize(' W ', fg=WHITE, bg=YELLOW),
+  'E': colorize(' E ', fg=WHITE, bg=RED),
+  'F': colorize(' F ', fg=WHITE, bg=RED),
 }
 
 PID_LINE = re.compile(r'^\w+\s+(\w+)\s+\w+\s+\w+\s+\w+\s+\w+\s+\w+\s+\w\s([\w|\.]+)$')
4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?