From ef831d17e010ae8d4ed1504651e81baa08154921 Mon Sep 17 00:00:00 2001 From: Joe Testa Date: Fri, 5 Feb 2021 21:45:56 -0500 Subject: [PATCH] When -n/--no-colors is used, strip out color from Windows man page. --- src/ssh_audit/ssh_audit.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/ssh_audit/ssh_audit.py b/src/ssh_audit/ssh_audit.py index d188d42..0988d41 100755 --- a/src/ssh_audit/ssh_audit.py +++ b/src/ssh_audit/ssh_audit.py @@ -28,6 +28,7 @@ import copy import getopt import json import os +import re import sys import traceback @@ -603,6 +604,7 @@ def process_commandline(out: OutputBuffer, args: List[str], usage_cb: Callable[. aconf.client_audit = True elif o in ('-n', '--no-colors'): aconf.colors = False + out.use_colors = False elif o in ('-j', '--json'): aconf.json = True elif o in ('-v', '--verbose'): @@ -1007,7 +1009,12 @@ def windows_manual(out: OutputBuffer) -> int: retval = exitcodes.FAILURE return retval - out.info(WINDOWS_MAN_PAGE) + # If colors are disabled, strip the ANSI color codes from the man page. + windows_man_page = WINDOWS_MAN_PAGE + if not out.use_colors: + windows_man_page = re.sub(r'\x1b\[\d+?m', '', windows_man_page) + + out.info(windows_man_page) return retval