Skip to content

Commit 26a81ea

Browse files
committed
Colorization on Windows using colorama
Added option -f/-force-windows-colors to force colorization if terminal is tty but actually expects windows colors
1 parent 0ef40cc commit 26a81ea

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Log
22
==========
33

4+
Version 2.0.1 *(2015-09-15)*
5+
----------------------------
6+
* New: Fix colors on Windows. Use options `-f` / `--force-windows-colors` to force conversion
7+
in case a terminal appears to be a tty. Requires module `colorama`
8+
49
Version 2.0.0 *(2015-05-25)*
510
----------------------------
611

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ Make sure that `adb` from the [Android SDK][3] is on your PATH. This script will
4141
not work unless this is that case. That means, when you type `adb` and press
4242
enter into your terminal something actually happens.
4343

44+
On Windows, you can do `pip install colorama` if you see weird arrows instead of
45+
colors. In case that does not help, try using option `-f`.
46+
4447
To include `adb` and other android tools on your path:
4548

4649
export PATH=$PATH:<path to Android SDK>/platform-tools

pidcat.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import subprocess
2828
from subprocess import PIPE
2929

30-
__version__ = '2.0.0'
30+
__version__ = '2.0.1'
31+
32+
# importing colorama so that windows users can see colors as well
3133

3234
LOG_LEVELS = 'VDIWEF'
3335
LOG_LEVELS_MAP = dict([(LOG_LEVELS[i], i) for i in range(len(LOG_LEVELS))])
@@ -46,6 +48,7 @@
4648
parser.add_argument('-i', '--ignore-tag', dest='ignored_tag', action='append', help='Filter output by ignoring specified tag(s)')
4749
parser.add_argument('-v', '--version', action='version', version='%(prog)s ' + __version__, help='Print the version number and exit')
4850
parser.add_argument('-a', '--all', dest='all', action='store_true', default=False, help='Print all log messages')
51+
parser.add_argument('-f', '--force-windows-colors', dest='force_windows_colors', action='store_true', default=False, help='Force converting colors to Windows format')
4952

5053
args = parser.parse_args()
5154
min_level = LOG_LEVELS_MAP[args.min_level.upper()]
@@ -86,6 +89,13 @@
8689
except:
8790
pass
8891

92+
try:
93+
import colorama
94+
colorama.init(convert=args.force_windows_colors)
95+
except ImportError:
96+
if args.force_windows_colors:
97+
raise
98+
8999
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
90100

91101
RESET = '\033[0m'

0 commit comments

Comments
 (0)