From b1f66ee0d6a975dfe4fa3c80cc01af19dbf93282 Mon Sep 17 00:00:00 2001 From: geg347 Date: Wed, 29 Jun 2022 18:37:19 +0200 Subject: [PATCH 1/2] Fixing colorama global init in print_result --- nornir_utils/plugins/functions/print_result.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nornir_utils/plugins/functions/print_result.py b/nornir_utils/plugins/functions/print_result.py index 0211394..e7c5eda 100644 --- a/nornir_utils/plugins/functions/print_result.py +++ b/nornir_utils/plugins/functions/print_result.py @@ -5,7 +5,7 @@ from collections import OrderedDict import json -from colorama import Fore, Style, init +from colorama import Fore, Style, init, deinit from nornir.core.task import AggregatedResult, MultiResult, Result @@ -13,9 +13,6 @@ LOCK = threading.Lock() -init(autoreset=True, strip=False) - - def print_title(title: str) -> None: """ Helper function to print a title. @@ -138,7 +135,9 @@ def print_result( severity_level: Print only errors with this severity level or higher """ LOCK.acquire() + init(autoreset=True, strip=False) try: _print_result(result, vars, failed, severity_level, print_host=True) finally: + deinit() LOCK.release() From 1ab4271da2be44f5f036a5d867dfebb71470e614 Mon Sep 17 00:00:00 2001 From: geg347 Date: Thu, 30 Jun 2022 09:05:13 +0200 Subject: [PATCH 2/2] Adding Colorama global init fix to print_title --- nornir_utils/plugins/functions/print_result.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nornir_utils/plugins/functions/print_result.py b/nornir_utils/plugins/functions/print_result.py index e7c5eda..1060896 100644 --- a/nornir_utils/plugins/functions/print_result.py +++ b/nornir_utils/plugins/functions/print_result.py @@ -17,8 +17,10 @@ def print_title(title: str) -> None: """ Helper function to print a title. """ + init(autoreset=True, strip=False) msg = "**** {} ".format(title) print("{}{}{}{}".format(Style.BRIGHT, Fore.GREEN, msg, "*" * (80 - len(msg)))) + deinit() def _get_color(result: Result, failed: bool) -> str: