當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。