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


Python console.ansiformat方法代码示例

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


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

示例1: _format_unencoded_with_lineno

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def _format_unencoded_with_lineno(self, tokensource, outfile):
        self._write_lineno(outfile)

        for ttype, value in tokensource:
            if value.endswith("\n"):
                self._write_lineno(outfile)
                value = value[:-1]
            color = self.colorscheme.get(ttype)
            while color is None:
                ttype = ttype[:-1]
                color = self.colorscheme.get(ttype)
            if color:
                color = color[self.darkbg]
                spl = value.split('\n')
                for line in spl[:-1]:
                    self._write_lineno(outfile)
                    if line:
                        outfile.write(ansiformat(color, line[:-1]))
                if spl[-1]:
                    outfile.write(ansiformat(color, spl[-1]))
            else:
                outfile.write(value)

        outfile.write("\n") 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:26,代码来源:terminal.py

示例2: format_unencoded

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def format_unencoded(self, tokensource, outfile):
        if self.linenos:
            self._format_unencoded_with_lineno(tokensource, outfile)
            return

        for ttype, value in tokensource:
            color = self.colorscheme.get(ttype)
            while color is None:
                ttype = ttype[:-1]
                color = self.colorscheme.get(ttype)
            if color:
                color = color[self.darkbg]
                spl = value.split('\n')
                for line in spl[:-1]:
                    if line:
                        outfile.write(ansiformat(color, line))
                    outfile.write('\n')
                if spl[-1]:
                    outfile.write(ansiformat(color, spl[-1]))
            else:
                outfile.write(value) 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:23,代码来源:terminal.py

示例3: format_unencoded

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def format_unencoded(self, tokensource, outfile):
        if self.linenos:
            self._write_lineno(outfile)

        for ttype, value in tokensource:
            color = self._get_color(ttype)

            for line in value.splitlines(True):
                if color:
                    outfile.write(ansiformat(color, line.rstrip('\n')))
                else:
                    outfile.write(line.rstrip('\n'))
                if line.endswith('\n'):
                    if self.linenos:
                        self._write_lineno(outfile)
                    else:
                        outfile.write('\n')

        if self.linenos:
            outfile.write("\n") 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:22,代码来源:terminal.py

示例4: show_requested

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def show_requested(self):
        """ Show the components you've worked with so far. """
        results = []
        for name, comp in sorted(self._requested):
            results.append(
                ansiformat(
                    self._get_color(comp), "{} {}".format(name, dr.get_name(comp))
                )
            )
        IPython.core.page.page(six.u(os.linesep.join(results))) 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:12,代码来源:shell.py

示例5: show_source

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def show_source(self, comp):
        """
        Show source for the given module, class, or function. Also accepts
        the string names, with the side effect that the component will be
        imported.
        """
        try:
            if isinstance(comp, six.string_types):
                comp = self.get(comp) or dr.get_component(comp) or importlib.import_module(comp)
            comp = inspect.getmodule(comp)
            ip = IPython.get_ipython()
            if self._cov:
                path, runnable, excluded, not_run, _ = self._cov.analysis2(comp)
                runnable, not_run = set(runnable), set(not_run)
                src = ip.pycolorize(inspect.getsource(comp)).splitlines()
                width = len(str(len(src)))
                template = "{0:>%s}" % width
                results = []
                file_line = "{} {}".format(
                    ansiformat("red", "File:"), os.path.realpath(path)
                )
                explain_line = "{} numbered lines have executed. python standard libs are excluded.".format(
                    ansiformat("*brightgreen*", "Green")
                )
                results.append(file_line)
                results.append(explain_line)
                results.append("")
                for i, line in enumerate(src, start=1):
                    prefix = template.format(i)
                    if i in runnable and i not in not_run:
                        color = "*brightgreen*"
                    else:
                        color = "gray"
                    results.append("{} {}".format(ansiformat(color, prefix), line))
                IPython.core.page.page(six.u(os.linesep.join(results)))
            else:
                ip.inspector.pinfo(comp, detail_level=1)
        except:
            traceback.print_exc() 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:41,代码来源:shell.py

示例6: _get_rule_value

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def _get_rule_value(self, comp):
        try:
            val = self._broker[comp]
            if plugins.is_rule(comp):
                _type = val.__class__.__name__
                kind = self._get_rule_value_kind(val)
                color = RULE_COLORS.get(kind, "")
                return ansiformat(color, " [{}]".format(_type))
        except:
            pass
        return "" 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:13,代码来源:shell.py

示例7: _show_datasource

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def _show_datasource(self, d, v, indent=""):
        try:
            filtered = "filtered" if dr.DELEGATES[d].filterable else "unfiltered"
            mode = "bytes" if dr.DELEGATES[d].raw else "lines"
        except:
            filtered = "unknown"
            mode = "unknown"

        desc = "{n} ({f} / {m})".format(n=dr.get_name(d), f=filtered, m=mode)
        color = self._get_color(d)

        results = []
        results.append(indent + ansiformat(color, desc))

        if not v:
            return results
        if not isinstance(v, list):
            v = [v]

        for i in v:
            if isinstance(i, ContentProvider):
                s = ansiformat(color, str(i))
            else:
                s = ansiformat(color, "<intermediate value>")
            results.append("{}\u250A\u254C\u254C\u254C\u254C\u254C{}".format(indent, s))
        return results 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:28,代码来源:shell.py

示例8: _show_tree

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def _show_tree(self, node, indent="", depth=None, dep_getter=dr.get_dependencies):
        if depth is not None and depth == 0:
            return []

        results = []
        color = self._get_color(node)
        if plugins.is_datasource(node):
            results.extend(
                self._show_datasource(node, self._broker.get(node), indent=indent)
            )
        else:
            _type = self._get_type_name(node)
            name = dr.get_name(node)
            suffix = self._get_rule_value(node)
            desc = ansiformat(color, "{n} ({t}".format(n=name, t=_type))
            results.append(indent + desc + suffix + ansiformat(color, ")"))

        dashes = "\u250A\u254C\u254C\u254C\u254C\u254C"
        if node in self._broker.exceptions:
            for ex in self._broker.exceptions[node]:
                results.append(indent + dashes + ansiformat(color, str(ex)))

        deps = dep_getter(node)
        next_indent = indent + "\u250A   "
        for d in deps:
            results.extend(
                self._show_tree(
                    d, next_indent, depth=depth if depth is None else depth - 1, dep_getter=dep_getter
                )
            )
        return results 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:33,代码来源:shell.py

示例9: _show_exceptions

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def _show_exceptions(self, comp):
        name = dr.get_name(comp)
        results = [ansiformat("*brightred*", name)]
        results.append(ansiformat("*brightred*", "-" * len(name)))
        for e in self._broker.exceptions.get(comp, []):
            t = self._broker.tracebacks.get(e)
            if t:
                results.append(t)
        return results 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:11,代码来源:shell.py

示例10: show_rule_report

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def show_rule_report(self, match=None, ignore=None):
        """
        Print a rule report for the matching rules.
        """
        match, ignore = self._desugar_match_ignore(match, ignore)
        results = defaultdict(dict)

        for comp, val in self._broker.items():
            name = dr.get_name(comp)
            if plugins.is_rule(comp) and match.test(name) and not ignore.test(name):
                kind = self._get_rule_value_kind(val)

                if kind:
                    body = render(comp, val)
                    links = render_links(comp)
                    results[kind][name] = os.linesep.join([body, "", links])

        report = []
        for kind in ["info", "pass", "fail"]:
            color = RULE_COLORS.get(kind, "")
            hits = results.get(kind, {})
            for name in sorted(hits):
                report.append(ansiformat(color, name))
                report.append(ansiformat(color, "-" * len(name)))
                report.append(hits[name])
                report.append("")
        IPython.core.page.page(six.u(os.linesep.join(report))) 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:29,代码来源:shell.py

示例11: show_timings

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def show_timings(self, match=None, ignore="spec", group=dr.GROUPS.single):
        """
        Show timings for components that have successfully evaluated.

        Args:
            match (str, optional): regular expression for matching against
                the fully qualified name of components to keep.
            ignore (str, optional): regular expression for searching against
                the fully qualified name of components to ignore.
        """
        match, ignore = self._desugar_match_ignore(match, ignore)

        results = []
        total = 0.0
        for comp in dr.COMPONENTS[group]:
            name = dr.get_name(comp)
            if comp in self._broker.exec_times and match.test(name) and not ignore.test(name):
                color = self._get_color(comp)
                t = self._broker.exec_times[comp]
                total += t
                results.append((t, name, color))

        report = [ansiformat("brightmagenta", "Total: {:.10f} seconds".format(total)), ""]
        for timing, name, color in sorted(results, reverse=True):
            report.append(ansiformat(color, "{:.10f}: {}".format(timing, name)))

        IPython.core.page.page(six.u(os.linesep.join(report))) 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:29,代码来源:shell.py

示例12: find

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def find(self, match=None, ignore=None):
        """
        Find components that might be available based on the data being
        analyzed.

        Args:
            match (str, optional): regular expression for matching against
                the fully qualified name of components to keep.
            ignore (str, optional): regular expression for searching against
                the fully qualified name of components to ignore.
        """
        match, ignore = self._desugar_match_ignore(match, ignore)
        mid_dashes = "\u250A\u254C\u254C"
        bottom_dashes = "\u2514\u254C\u254C"
        results = []
        for p in sorted(self, key=str.lower):
            comp = self[p]
            name = dr.get_name(comp)
            if match.test(name) and not ignore.test(name):
                color = self._get_color(comp)
                _type = self._get_type_name(comp)
                suffix = self._get_rule_value(comp)
                desc = ansiformat(color, "{p} ({n}, {t}".format(p=p, n=name, t=_type))
                results.append(desc + suffix + ansiformat(color, ")"))
                if comp in self._broker.exceptions:
                    exes = self._broker.exceptions[comp]
                    last = len(exes) - 1
                    for i, ex in enumerate(exes):
                        dashes = bottom_dashes if i == last else mid_dashes
                        results.append(ansiformat(color, dashes + str(ex)))
        IPython.core.page.page(six.u(os.linesep.join(results))) 
开发者ID:RedHatInsights,项目名称:insights-core,代码行数:33,代码来源:shell.py

示例13: test_console_ansiformat

# 需要导入模块: from pygments import console [as 别名]
# 或者: from pygments.console import ansiformat [as 别名]
def test_console_ansiformat():
    f = console.ansiformat
    c = console.codes
    all_attrs = f('+*_blue_*+', 'text')
    assert c['blue'] in all_attrs and c['blink'] in all_attrs
    assert c['bold'] in all_attrs and c['underline'] in all_attrs
    assert c['reset'] in all_attrs
    assert raises(KeyError, f, '*mauve*', 'text') 
开发者ID:pygments,项目名称:pygments,代码行数:10,代码来源:test_util.py


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