From 956b3c605396f64badba64b69e8b94759c756a28 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Wed, 23 Mar 2022 14:38:15 -0700 Subject: [PATCH] Handle the case in which colorama is not installed. --- voussoirkit/betterhelp.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/voussoirkit/betterhelp.py b/voussoirkit/betterhelp.py index 0333ce0..ac00644 100644 --- a/voussoirkit/betterhelp.py +++ b/voussoirkit/betterhelp.py @@ -1,5 +1,8 @@ import argparse -import colorama +try: + import colorama +except ImportError: + colorama = None import io import os import re @@ -131,7 +134,7 @@ def make_helptext( # Even though this text is going out on stderr, we only colorize it if # both stdout and stderr are tty because as soon as pipe buffers are # involved, even on stdout, things start to get weird. - if do_colors and pipeable.stdout_tty() and pipeable.stderr_tty(): + if do_colors and colorama and pipeable.stdout_tty() and pipeable.stderr_tty(): colorama.init() color = dotdict.DotDict( positional=colorama.Style.BRIGHT + colorama.Fore.CYAN, @@ -148,7 +151,7 @@ def make_helptext( flag='', command='', reset='', - required_asterisk=colorama.Style.BRIGHT + colorama.Fore.RED + '(*)' + colorama.Style.RESET_ALL, + required_asterisk='(*)', ) if program_name is None: