From 385c2303765c0a1ae20c70d1700e5887aea07772 Mon Sep 17 00:00:00 2001 From: Andris Raugulis Date: Tue, 25 Oct 2016 11:50:12 +0300 Subject: [PATCH] Add colors support for Microsoft Windows via optional colorama dependency. --- ssh-audit.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ssh-audit.py b/ssh-audit.py index b88e512..b89e8da 100755 --- a/ssh-audit.py +++ b/ssh-audit.py @@ -42,6 +42,11 @@ try: from typing import List, Tuple, Optional, Callable, Union, Any except ImportError: pass +try: + from colorama import init as colorama_init + colorama_init() +except ImportError: + pass def usage(err=None): @@ -177,6 +182,11 @@ class Output(object): if not self.batch: print() + @property + def colors_supported(self): + # type: () -> bool + return 'colorama' in sys.modules or os.name == 'posix' + @staticmethod def _colorized(color): # type: (str) -> Callable[[text_type], None] @@ -188,7 +198,7 @@ class Output(object): return lambda x: None if not self.getlevel(name) >= self.__minlevel: return lambda x: None - if self.colors and os.name == 'posix' and name in self.COLORS: + if self.colors and self.colors_supported and name in self.COLORS: color = '\033[0;{0}m'.format(self.COLORS[name]) return self._colorized(color) else: