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


Python colorama.Style方法代码示例

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


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

示例1: settings

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def settings(self):
        """
        Show the server's currently configured settings

        """
        text_color = [color for color in filter(str.isupper, dir(colorama.Fore)) if color == self._text_color][0]
        text_style = [style for style in filter(str.isupper, dir(colorama.Style)) if style == self._text_style][0]
        prompt_color = [color for color in filter(str.isupper, dir(colorama.Fore)) if color == self._prompt_color][0]
        prompt_style = [style for style in filter(str.isupper, dir(colorama.Style)) if style == self._prompt_style][0]
        util.display('\n\t    OPTIONS', color='white', style='bright')
        util.display('text color/style: ', color='white', style='normal', end=' ')
        util.display('/'.join((self._text_color.title(), self._text_style.title())), color=self._text_color, style=self._text_style)
        util.display('prompt color/style: ', color='white', style='normal', end=' ')
        util.display('/'.join((self._prompt_color.title(), self._prompt_style.title())), color=self._prompt_color, style=self._prompt_style)
        util.display('debug: ', color='white', style='normal', end=' ')
        util.display('True\n' if globals()['debug'] else 'False\n', color='green' if globals()['debug'] else 'red', style='normal') 
开发者ID:malwaredllc,项目名称:byob,代码行数:18,代码来源:server.py

示例2: colorize

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def colorize(text, fg=None, bg=None, attrs=None):
    if os.getenv("ANSI_COLORS_DISABLED") is None:
        style = "NORMAL"
        if attrs is not None and not isinstance(attrs, list):
            _attrs = []
            if isinstance(attrs, six.string_types):
                _attrs.append(attrs)
            else:
                _attrs = list(attrs)
            attrs = _attrs
        if attrs and "bold" in attrs:
            style = "BRIGHT"
            attrs.remove("bold")
        if fg is not None:
            fg = fg.upper()
            text = to_native_string("%s%s%s%s%s") % (
                to_native_string(getattr(colorama.Fore, fg)),
                to_native_string(getattr(colorama.Style, style)),
                to_native_string(text),
                to_native_string(colorama.Fore.RESET),
                to_native_string(colorama.Style.NORMAL),
            )

        if bg is not None:
            bg = bg.upper()
            text = to_native_string("%s%s%s%s") % (
                to_native_string(getattr(colorama.Back, bg)),
                to_native_string(text),
                to_native_string(colorama.Back.RESET),
                to_native_string(colorama.Style.NORMAL),
            )

        if attrs is not None:
            fmt_str = to_native_string("%s[%%dm%%s%s[9m") % (chr(27), chr(27))
            for attr in attrs:
                text = fmt_str % (ATTRIBUTES[attr], text)

        text += RESET
    else:
        text = ANSI_REMOVAL_RE.sub("", text)
    return text 
开发者ID:pypa,项目名称:pipenv,代码行数:43,代码来源:termcolors.py

示例3: format

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def format(self, record):
        if hasattr(record, 'formatted') and record.formatted:
            return record.formatted

        # save the formatted, for all handlers
        record.msg = str(record.msg)
        if '\n' in record.msg:
            record.tails = []
            msgs = record.msg.splitlines()
            record.msg = msgs[0]
            for msg in msgs[1:]:
                rec = copy(record)
                rec.msg = msg
                self.format(rec)
                record.tails.append(rec)

        proc = record.proc
        proc += (': '
                 if hasattr(record, 'proc') and record.proc
                 else '')
        jobs = ('' if record.jobidx is None
                else '[{ji}/{jt}] '.format(
                    ji=str(record.jobidx + 1).zfill(len(str(record.joblen))),
                    jt=record.joblen
                ))
        color = self.theme.get_color(record.mylevel)
        record.msg = (f" {color}{record.plugin:>7s}."
                      f"{record.mylevel:>7s}{colorama.Style.RESET_ALL}] "
                      f"{color}{proc}{jobs}{record.msg}"
                      f"{colorama.Style.RESET_ALL}")

        setattr(record, 'formatted', logging.Formatter.format(self, record))
        return record.formatted 
开发者ID:pwwang,项目名称:PyPPL,代码行数:35,代码来源:logger.py

示例4: _style

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def _style(self):
        if self.allow_terminal_colors:
            import colorama
            return colorama.Style
        else:
            return _ColoramaStub() 
开发者ID:inducer,项目名称:loopy,代码行数:8,代码来源:options.py

示例5: display

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def display(output, color=None, style=None, end='\n', event=None, lock=None):
    """
    Display output in the console

    `Required`
    :param str output:    text to display

    `Optional`
    :param str color:     red, green, cyan, magenta, blue, white
    :param str style:     normal, bright, dim
    :param str end:       __future__.print_function keyword arg
    :param lock:          threading.Lock object
    :param event:         threading.Event object

    """
    # if isinstance(output, bytes):
    #     output = output.decode('utf-8')
    # else:
    #     output = str(output)
    # _color = ''
    # if color:
    #     _color = getattr(colorama.Fore, color.upper())
    # _style = ''
    # if style:
    #     _style = getattr(colorama.Style, style.upper())
    # exec("""print(_color + _style + output + colorama.Style.RESET_ALL, end="{}")""".format(end))
    print(output) 
开发者ID:malwaredllc,项目名称:byob,代码行数:29,代码来源:util.py

示例6: _get_prompt

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def _get_prompt(self, data):
        with self._lock:
            return raw_input(getattr(colorama.Fore, self._prompt_color) + getattr(colorama.Style, self._prompt_style) + data.rstrip()) 
开发者ID:malwaredllc,项目名称:byob,代码行数:5,代码来源:server.py

示例7: display

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def display(output, color=None, style=None, end='\\n', event=None, lock=None):
    """
    Display output in the console

    `Required`
    :param str output:    text to display

    `Optional`
    :param str color:     red, green, cyan, magenta, blue, white
    :param str style:     normal, bright, dim
    :param str end:       __future__.print_function keyword arg
    :param lock:          threading.Lock object
    :param event:         threading.Event object

    """
    if isinstance(output, bytes):
        output = output.decode('utf-8')
    else:
        output = str(output)
    _color = ''
    if color:
        _color = getattr(colorama.Fore, color.upper())
    _style = ''
    if style:
        _style = getattr(colorama.Style, style.upper())
    exec("""print(_color + _style + output + colorama.Style.RESET_ALL, end="{}")""".format(end)) 
开发者ID:malwaredllc,项目名称:byob,代码行数:28,代码来源:util.py

示例8: __repr__

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def __repr__(self):
        if self._color_spec:
            return '{schema}{str}{reset}'.format(
                schema=self._color_spec, str=safe_str(self._str), reset=Colors.Style.RESET_ALL)
        return self._str 
开发者ID:apache,项目名称:incubator-ariatosca,代码行数:7,代码来源:color.py

示例9: highlight

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def highlight(self, pattern, schema):
        if pattern is None:
            return
        for match in set(re.findall(re.compile(pattern), self._str)):
            self.replace(match, schema + match + Colors.Style.RESET_ALL + self._color_spec) 
开发者ID:apache,项目名称:incubator-ariatosca,代码行数:7,代码来源:color.py

示例10: ok

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def ok(text, end='\n'):
        """
        Print a success status message
        """
        IO.print('{}OK{}   {}'.format(IO.Style.BRIGHT + IO.Fore.LIGHTGREEN_EX, IO.Style.RESET_ALL, text), end=end) 
开发者ID:bitbrute,项目名称:evillimiter,代码行数:7,代码来源:io.py

示例11: error

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def error(text):
        """
        Print an error status message
        """
        IO.print('{}ERR{}  {}'.format(IO.Style.BRIGHT + IO.Fore.LIGHTRED_EX, IO.Style.RESET_ALL, text)) 
开发者ID:bitbrute,项目名称:evillimiter,代码行数:7,代码来源:io.py

示例12: color_str

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def color_str(self):
        style = 'BRIGHT' if self.bold else 'NORMAL'
        c = '%s%s%s%s%s' % (getattr(colorama.Fore, self.color),
                            getattr(colorama.Style, style),
                            self.s,
                            colorama.Fore.RESET,
                            colorama.Style.NORMAL)

        if self.always_color:
            return c
        elif sys.stdout.isatty() and not DISABLE_COLOR:
            return c
        else:
            return self.s 
开发者ID:MasterOdin,项目名称:crayons,代码行数:16,代码来源:crayons.py

示例13: set

# 需要导入模块: import colorama [as 别名]
# 或者: from colorama import Style [as 别名]
def set(self, args=None):
        """
        Set display settings for the command & control console

        Usage: `set [setting] [option]=[value]`

            :setting text:      text displayed in console
            :setting prompt:    prompt displayed in shells

            :option color:      color attribute of a setting
            :option style:      style attribute of a setting

            :values color:      red, green, cyan, yellow, magenta
            :values style:      normal, bright, dim

        Example 1:         `set text color=green style=normal`
        Example 2:         `set prompt color=white style=bright`

        """
        if args:
            arguments = self._get_arguments(args)
            args, kwargs = arguments.args, arguments.kwargs
            if arguments.args:
                target = args[0]
                args = args[1:]
                if target in ('debug','debugging'):
                    if args:
                        setting = args[0]
                        if setting.lower() in ('0','off','false','disable'):
                            globals()['debug'] = False
                        elif setting.lower() in ('1','on','true','enable'):
                            globals()['debug'] = True
                        util.display("\n[+]" if globals()['debug'] else "\n[-]", color='green' if globals()['debug'] else 'red', style='normal', end=' ')
                        util.display("Debug: {}\n".format("ON" if globals()['debug'] else "OFF"), color='white', style='bright')
                        return
                for setting, option in arguments.kwargs.items():
                    option = option.upper()
                    if target == 'prompt':
                        if setting == 'color':
                            if hasattr(colorama.Fore, option):
                                self._prompt_color = option
                        elif setting == 'style':
                            if hasattr(colorama.Style, option):
                                self._prompt_style = option
                        util.display("\nprompt color/style changed to ", color='white', style='bright', end=' ')
                        util.display(option + '\n', color=self._prompt_color, style=self._prompt_style)
                        return
                    elif target == 'text':
                        if setting == 'color':
                            if hasattr(colorama.Fore, option):
                                self._text_color = option
                        elif setting == 'style':
                            if hasattr(colorama.Style, option):
                                self._text_style = option
                        util.display("\ntext color/style changed to ", color='white', style='bright', end=' ')
                        util.display(option + '\n', color=self._text_color, style=self._text_style)
                        return
        util.display("\nusage: set [setting] [option]=[value]\n\n    colors:   white/black/red/yellow/green/cyan/magenta\n    styles:   dim/normal/bright\n", color=self._text_color, style=self._text_style) 
开发者ID:malwaredllc,项目名称:byob,代码行数:60,代码来源:server.py


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