Source code for crossbar.shell.util
###############################################################################
#
# Crossbar.io Shell
# Copyright (c) typedef int GmbH. Licensed under EUPLv1.2.
#
###############################################################################
import locale
import os
import sys
import time
import click
import six
[docs]
_HAS_COLOR_TERM = False
try:
import colorama
# https://github.com/tartley/colorama/issues/48
if sys.platform == "win32" and "TERM" in os.environ:
term = os.environ.pop("TERM")
colorama.init()
_HAS_COLOR_TERM = True
if term:
os.environ["TERM"] = term
except ImportError:
pass
[docs]
def hl(text, bold=False):
if not isinstance(text, six.text_type):
text = "{}".format(text)
return click.style(text, fg="yellow", bold=bold)
[docs]
def style_crossbar(text):
if _HAS_COLOR_TERM:
return click.style(text, fg="yellow", bold=True)
else:
return text
[docs]
def style_finished_line(text):
if _HAS_COLOR_TERM:
return click.style(text, fg="yellow")
else:
return text
[docs]
def style_error(text):
if _HAS_COLOR_TERM:
return click.style(text, fg="red", bold=True)
else:
return text
[docs]
def style_ok(text):
if _HAS_COLOR_TERM:
return click.style(text, fg="green", bold=True)
else:
return text
[docs]
def localnow():
return time.strftime(locale.nl_langinfo(locale.D_T_FMT), time.localtime())