How to use the wasabi.util.supports_ansi function in wasabi

To help you get started, we’ve selected a few wasabi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ines / wasabi / tests / test_printer.py View on Github external
def test_printer_custom():
    colors = {"yellow": 220, "purple": 99}
    icons = {"warn": "\u26a0\ufe0f", "question": "?"}
    p = Printer(no_print=True, colors=colors, icons=icons)
    text = "This is a test."
    purple_question = p.text(text, color="purple", icon="question")
    warning = p.warn(text)
    if supports_ansi():
        assert purple_question == "\x1b[38;5;99m? This is a test.\x1b[0m"
        assert warning == "\x1b[38;5;3m\u26a0\ufe0f This is a test.\x1b[0m"
    else:
        assert purple_question == "{} {}".format(icons["question"], text)
        assert warning == text
github ines / wasabi / tests / test_printer.py View on Github external
def test_printer():
    p = Printer(no_print=True)
    text = "This is a test."
    if supports_ansi():
        assert p.good(text) == "\x1b[38;5;2m\u2714 This is a test.\x1b[0m"
        assert p.fail(text) == "\x1b[38;5;1m\u2718 This is a test.\x1b[0m"
        assert p.warn(text) == "\x1b[38;5;3m\u26a0 This is a test.\x1b[0m"
        assert p.info(text) == "\x1b[38;5;4m\u2139 This is a test.\x1b[0m"
        assert p.text(text) == text
    else:
        assert p.good(text) == text
        assert p.fail(text) == text
        assert p.warn(text) == text
        assert p.info(text) == text
        assert p.text(text) == text
github ines / wasabi / tests / test_printer.py View on Github external
def test_printer_log_friendly():
    text = "This is a test."
    ENV_LOG_FRIENDLY = "WASABI_LOG_FRIENDLY"
    os.environ[ENV_LOG_FRIENDLY] = "True"
    p = Printer(no_print=True)
    if supports_ansi():
        assert p.good(text) == "\u2714 This is a test."
    else:
        assert p.good(text) == text
    del os.environ[ENV_LOG_FRIENDLY]
github ines / wasabi / tests / test_printer.py View on Github external
def test_printer_log_friendly_prefix():
    text = "This is a test."
    ENV_LOG_FRIENDLY = "CUSTOM_LOG_FRIENDLY"
    os.environ[ENV_LOG_FRIENDLY] = "True"
    p = Printer(no_print=True, env_prefix="CUSTOM")
    if supports_ansi():
        assert p.good(text) == "\u2714 This is a test."
    else:
        assert p.good(text) == text
    del os.environ[ENV_LOG_FRIENDLY]
github ines / wasabi / tests / test_util.py View on Github external
def test_locale_escape(text, non_ansi):
    result = locale_escape(text)
    if supports_ansi():
        assert result
    else:
        assert result == non_ansi
github justindujardin / mathy / libraries / mathy_python / mathy / traceback.py View on Github external
the traceback will continue until the last record.
        RETURNS (TracebackPrinter): The traceback printer.
        """
        self.color_error = color_error
        self.color_tb = color_tb
        self.color_highlight = color_highlight
        self.indent = " " * indent
        if tb_base == ".":
            tb_base = f"{os.getcwd()}/"
        elif tb_base is not None:
            tb_base = "/{}/".format(tb_base)
        self.tb_base = tb_base
        self.tb_exclude = tuple(tb_exclude)
        self.tb_range_start = tb_range_start
        self.tb_range_end = tb_range_end
        self.supports_ansi = supports_ansi()
github ines / wasabi / wasabi / traceback_printer.py View on Github external
the traceback will continue until the last record.
        RETURNS (TracebackPrinter): The traceback printer.
        """
        self.color_error = color_error
        self.color_tb = color_tb
        self.color_highlight = color_highlight
        self.indent = " " * indent
        if tb_base == ".":
            tb_base = "{}{}".format(os.getcwd(), os.path.sep)
        elif tb_base is not None:
            tb_base = "/{}/".format(tb_base)
        self.tb_base = tb_base
        self.tb_exclude = tuple(tb_exclude)
        self.tb_range_start = tb_range_start
        self.tb_range_end = tb_range_end
        self.supports_ansi = supports_ansi()
github ines / wasabi / wasabi / printer.py View on Github external
line_max (int): Maximum line length (for divider).
        animation (unicode): Steps of loading animation for loading() method.
        animation_ascii (unicode): Alternative animation for ASCII terminals.
        hide_animation (bool): Don't display animation, e.g. for logs.
        ignore_warnings (bool): Do not output messages of type MESSAGE.WARN.
        env_prefix (unicode): Prefix for environment variables, e.g.
            WASABI_LOG_FRIENDLY.
        timestamp (bool): Print a timestamp (default False).
        RETURNS (Printer): The initialized printer.
        """
        env_log_friendly = os.getenv("{}_LOG_FRIENDLY".format(env_prefix), False)
        env_no_pretty = os.getenv("{}_NO_PRETTY".format(env_prefix), False)
        self._counts = Counter()
        self.pretty = pretty and not env_no_pretty
        self.no_print = no_print
        self.show_color = supports_ansi() and not env_log_friendly
        self.hide_animation = hide_animation or env_log_friendly
        self.ignore_warnings = ignore_warnings
        self.line_max = line_max
        self.colors = dict(COLORS)
        self.icons = dict(ICONS)
        self.timestamp = timestamp
        if colors:
            self.colors.update(colors)
        if icons:
            self.icons.update(icons)
        self.anim = animation if can_render(animation) else animation_ascii