Handle the case in which colorama is not installed.

master
voussoir 2022-03-23 14:38:15 -07:00
parent 5ddc83e3ff
commit 956b3c6053
No known key found for this signature in database
GPG Key ID: 5F7554F8C26DACCB
1 changed files with 6 additions and 3 deletions

View File

@ -1,5 +1,8 @@
import argparse import argparse
try:
import colorama import colorama
except ImportError:
colorama = None
import io import io
import os import os
import re import re
@ -131,7 +134,7 @@ def make_helptext(
# Even though this text is going out on stderr, we only colorize it if # 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 # both stdout and stderr are tty because as soon as pipe buffers are
# involved, even on stdout, things start to get weird. # 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() colorama.init()
color = dotdict.DotDict( color = dotdict.DotDict(
positional=colorama.Style.BRIGHT + colorama.Fore.CYAN, positional=colorama.Style.BRIGHT + colorama.Fore.CYAN,
@ -148,7 +151,7 @@ def make_helptext(
flag='', flag='',
command='', command='',
reset='', reset='',
required_asterisk=colorama.Style.BRIGHT + colorama.Fore.RED + '(*)' + colorama.Style.RESET_ALL, required_asterisk='(*)',
) )
if program_name is None: if program_name is None: