当前位置: 首页>>代码示例>>Python>>正文


Python colorama.AnsiToWin32方法代码示例

本文整理汇总了Python中colorama.AnsiToWin32方法的典型用法代码示例。如果您正苦于以下问题:Python colorama.AnsiToWin32方法的具体用法?Python colorama.AnsiToWin32怎么用?Python colorama.AnsiToWin32使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在colorama的用法示例。


在下文中一共展示了colorama.AnsiToWin32方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: colored

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def colored(self):
        """
        Cek jika pesan bisa di warnai
        """

        _ = self.stream
        if isinstance(_, AnsiToWin32):
            _ = _.wrapped

        if hasattr(_, "isatty") and _.isatty():
            return True

        if os.getenv("TERM", "").lower() == "ansi":
            return True

        return False 
开发者ID:brutemap-dev,项目名称:brutemap,代码行数:18,代码来源:logger.py

示例2: __init__

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def __init__(self, file=None, stringio=False, encoding=None):
        if file is None:
            if stringio:
                self.stringio = file = py.io.TextIO()
            else:
                from sys import stdout as file
        elif py.builtin.callable(file) and not (
             hasattr(file, "write") and hasattr(file, "flush")):
            file = WriteFile(file, encoding=encoding)
        if hasattr(file, "isatty") and file.isatty() and colorama:
            file = colorama.AnsiToWin32(file).stream
        self.encoding = encoding or getattr(file, 'encoding', "utf-8")
        self._file = file
        self.hasmarkup = should_do_markup(file)
        self._lastlen = 0
        self._chars_on_current_line = 0
        self._width_of_current_line = 0 
开发者ID:pytest-dev,项目名称:py,代码行数:19,代码来源:terminalwriter.py

示例3: _wrap_for_color

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def _wrap_for_color(stream, color=None):
            try:
                cached = _color_stream_cache.get(stream)
            except KeyError:
                cached = None
            if cached is not None:
                return cached
            strip = not _can_use_color(stream, color)
            _color_wrapper = colorama.AnsiToWin32(stream, strip=strip)
            result = _color_wrapper.stream
            _write = result.write

            def _write_with_color(s):
                try:
                    return _write(s)
                except Exception:
                    _color_wrapper.reset_all()
                    raise

            result.write = _write_with_color
            try:
                _color_stream_cache[stream] = result
            except Exception:
                pass
            return result 
开发者ID:pypa,项目名称:pipenv,代码行数:27,代码来源:misc.py

示例4: __init__

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def __init__(self, file: Optional[TextIO] = None) -> None:
        if file is None:
            file = sys.stdout
        if hasattr(file, "isatty") and file.isatty() and sys.platform == "win32":
            try:
                import colorama
            except ImportError:
                pass
            else:
                file = colorama.AnsiToWin32(file).stream
                assert file is not None
        self._file = file
        self.hasmarkup = should_do_markup(file)
        self._current_line = ""
        self._terminal_width = None  # type: Optional[int]
        self.code_highlight = True 
开发者ID:pytest-dev,项目名称:pytest,代码行数:18,代码来源:terminalwriter.py

示例5: __init__

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def __init__(self, stream):
        logging.StreamHandler.__init__(self, stream)

        if IS_WINDOWS:
            stream = AnsiToWin32(stream)

        self.stream = stream
        self.record = None 
开发者ID:brutemap-dev,项目名称:brutemap,代码行数:10,代码来源:logger.py

示例6: _init_handlers

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def _init_handlers(
        level: int,
        color: bool,
        force_color: bool,
        json_logging: bool,
        ram_capacity: int
) -> typing.Tuple[logging.StreamHandler, typing.Optional['RAMHandler']]:
    """Init log handlers.

    Args:
        level: The numeric logging level.
        color: Whether to use color if available.
        force_color: Force colored output.
        json_logging: Output log lines in JSON (this disables all colors).
    """
    global ram_handler
    global console_handler
    console_fmt, ram_fmt, html_fmt, use_colorama = _init_formatters(
        level, color, force_color, json_logging)

    if sys.stderr is None:
        console_handler = None  # type: ignore[unreachable]
    else:
        strip = False if force_color else None
        if use_colorama:
            stream = colorama.AnsiToWin32(sys.stderr, strip=strip)
        else:
            stream = sys.stderr
        console_handler = logging.StreamHandler(stream)
        console_handler.setLevel(level)
        console_handler.setFormatter(console_fmt)

    if ram_capacity == 0:
        ram_handler = None
    else:
        ram_handler = RAMHandler(capacity=ram_capacity)
        ram_handler.setLevel(logging.DEBUG)
        ram_handler.setFormatter(ram_fmt)
        ram_handler.html_formatter = html_fmt

    return console_handler, ram_handler 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:43,代码来源:log.py

示例7: __init__

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def __init__(self, output=None, color_mapping=None):
        TextReporter.__init__(self, output)
        self.color_mapping = color_mapping or \
                             dict(ColorizedTextReporter.COLOR_MAPPING)
        ansi_terms = ['xterm-16color', 'xterm-256color']
        if os.environ.get('TERM') not in ansi_terms:
            if sys.platform == 'win32':
                import colorama
                self.out = colorama.AnsiToWin32(self.out) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:11,代码来源:text.py

示例8: auto_wrap_for_ansi

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def auto_wrap_for_ansi(stream, color=None):
            """This function wraps a stream so that calls through colorama
            are issued to the win32 console API to recolor on demand.  It
            also ensures to reset the colors if a write call is interrupted
            to not destroy the console afterwards.
            """
            try:
                cached = _ansi_stream_wrappers.get(stream)
            except Exception:
                cached = None
            if cached is not None:
                return cached
            strip = should_strip_ansi(stream, color)
            ansi_wrapper = colorama.AnsiToWin32(stream, strip=strip)
            rv = ansi_wrapper.stream
            _write = rv.write

            def _safe_write(s):
                try:
                    return _write(s)
                except:
                    ansi_wrapper.reset_all()
                    raise

            rv.write = _safe_write
            try:
                _ansi_stream_wrappers[stream] = rv
            except Exception:
                pass
            return rv 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:32,代码来源:_compat.py

示例9: __init__

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def __init__(self, output=None, color_mapping=None):
        TextReporter.__init__(self, output)
        self.color_mapping = color_mapping or dict(ColorizedTextReporter.COLOR_MAPPING)
        ansi_terms = ["xterm-16color", "xterm-256color"]
        if os.environ.get("TERM") not in ansi_terms:
            if sys.platform == "win32":
                # pylint: disable=import-error
                import colorama

                self.out = colorama.AnsiToWin32(self.out) 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:12,代码来源:text.py

示例10: bprint

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def bprint(msgStr, msgType=None, vbCur=1, vbTs=1):
    '''
    print function with:
        1. diffrent message type with different color:
            info - default color
            warning - yellow
            error - red
            ok - green
        2. verbose level control.
    args:
        msgStr - the message string.
        msgType - message type(info/warning/error/ok).
        vbCur - current verbose level.
        vbTs - verbose threshold to print the message.
    '''
    if vbCur >= vbTs:
        # deprecated, because colorama.init() disables the auto-completion
        # of cmd2, although it works very well in platform auto-detection.
        #colorama.init(autoreset=True)

        if platform.system().lower() == 'windows':
            stream = colorama.AnsiToWin32(sys.stdout)
        else:
            stream = sys.stdout

        print(msgTypeColor[msgType][0] + \
                  colorama.Style.BRIGHT + \
                  msgStr + \
                  colorama.Fore.RESET + \
                  colorama.Style.RESET_ALL,
              file=stream) 
开发者ID:n0tr00t,项目名称:Beehive,代码行数:33,代码来源:io.py

示例11: bprintPrefix

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def bprintPrefix(msgStr, msgType=None, vbCur=1, vbTs=1):
    '''
    print function with:
        1. diffrent message type with different color:
            info - default color
            warning - yellow
            error - red
            ok - green
        2. verbose level control.
    args:
        msgStr - the message string.
        msgType - message type(info/warning/error/ok).
        vbCur - current verbose level.
        vbTs - verbose threshold to print the message.
    '''
    if vbCur >= vbTs:
        # deprecated, because colorama.init() disables the auto-completion
        # of cmd2, although it works very well in platform auto-detection.
        #colorama.init(autoreset=True)

        if platform.system().lower() == 'windows':
            stream = colorama.AnsiToWin32(sys.stdout)
        else:
            stream = sys.stdout

        print(msgTypeColor[msgType][0] + \
                  colorama.Style.BRIGHT + \
                  msgTypeColor[msgType][1] + \
                  colorama.Fore.RESET + \
                  colorama.Style.RESET_ALL,
              end='',
              file=stream)
        print(msgStr,
              file=stream) 
开发者ID:n0tr00t,项目名称:Beehive,代码行数:36,代码来源:io.py

示例12: _is_wrapped_for_color

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def _is_wrapped_for_color(stream):
            return isinstance(
                stream, (colorama.AnsiToWin32, colorama.ansitowin32.StreamWrapper)
            ) 
开发者ID:pypa,项目名称:pipenv,代码行数:6,代码来源:misc.py

示例13: stream

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def stream(self):
        try:
            import colorama
            return colorama.AnsiToWin32(sys.stderr)
        except ImportError:
            return sys.stderr 
开发者ID:staticshock,项目名称:colored-traceback.py,代码行数:8,代码来源:colored_traceback.py

示例14: __init__

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import AnsiToWin32 [as 别名]
def __init__(self, file=None, stringio=False, encoding=None):
        if file is None:
            if stringio:
                self.stringio = file = py.io.TextIO()
            else:
                file = py.std.sys.stdout
        elif py.builtin.callable(file) and not (
             hasattr(file, "write") and hasattr(file, "flush")):
            file = WriteFile(file, encoding=encoding)
        if hasattr(file, "isatty") and file.isatty() and colorama:
            file = colorama.AnsiToWin32(file).stream
        self.encoding = encoding or getattr(file, 'encoding', "utf-8")
        self._file = file
        self.hasmarkup = should_do_markup(file)
        self._lastlen = 0 
开发者ID:acaceres2176,项目名称:scylla,代码行数:17,代码来源:terminalwriter.py


注:本文中的colorama.AnsiToWin32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。