From cf1debbf3ce9f04cfd34239b876bef77d8741920 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 12 Apr 2021 15:36:08 -0400 Subject: [PATCH 1/2] Make verbose output prettier with terminal colors --- cli/onionshare_cli/common.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cli/onionshare_cli/common.py b/cli/onionshare_cli/common.py index 4cfe83ae..e812aa98 100644 --- a/cli/onionshare_cli/common.py +++ b/cli/onionshare_cli/common.py @@ -43,6 +43,10 @@ class Common: The Common object is shared amongst all parts of OnionShare. """ + C_RESET = "\033[0m" + C_LIGHTGRAY = "\033[37m" + C_DARKGRAY = "\033[90m" + def __init__(self, verbose=False): self.verbose = verbose @@ -68,10 +72,9 @@ class Common: """ if self.verbose: timestamp = time.strftime("%b %d %Y %X") - - final_msg = f"[{timestamp}] {module}.{func}" + final_msg = f"{self.C_DARKGRAY}[{timestamp}]{self.C_RESET} {self.C_LIGHTGRAY}{module}.{func}{self.C_RESET}" if msg: - final_msg = f"{final_msg}: {msg}" + final_msg = f"{final_msg}{self.C_LIGHTGRAY}: {msg}{self.C_RESET}" print(final_msg) def get_resource_path(self, filename): From 5cf8ef180eed6fa2cf49502eb3ccd6d308269ae4 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Mon, 12 Apr 2021 15:42:16 -0400 Subject: [PATCH 2/2] Fix log tests --- cli/tests/test_cli_common.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/tests/test_cli_common.py b/cli/tests/test_cli_common.py index 96838c95..ef4732be 100644 --- a/cli/tests/test_cli_common.py +++ b/cli/tests/test_cli_common.py @@ -241,5 +241,11 @@ class TestLog: output = buf.getvalue() line_one, line_two, _ = output.split("\n") - assert line_one == "[Jun 06 2013 11:05:00] TestModule.dummy_func" - assert line_two == "[Jun 06 2013 11:05:00] TestModule.dummy_func: TEST_MSG" + assert ( + "[Jun 06 2013 11:05:00]" in line_one and "TestModule.dummy_func" in line_one + ) + assert ( + "[Jun 06 2013 11:05:00]" in line_two + and "TestModule.dummy_func" in line_two + and "TEST_MSG" in line_two + )