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


Python SpacingHelper.yield_tab_lengths方法代码示例

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


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

示例1: test_print_spaces_tabs_in_unicode

# 需要导入模块: from coalib.bearlib.spacing.SpacingHelper import SpacingHelper [as 别名]
# 或者: from coalib.bearlib.spacing.SpacingHelper.SpacingHelper import yield_tab_lengths [as 别名]
    def test_print_spaces_tabs_in_unicode(self):
        printer = StringPrinter()

        sh = SpacingHelper(4)

        test_string = "\the\tllo world   "
        print_spaces_tabs_in_unicode(
            printer,
            test_string,
            dict(sh.yield_tab_lengths(test_string)),
            "red")
        self.assertEqual(printer.string, "--->he->llo•world•••")

        # Test the case when the bullet can't be printed because of encoding
        # problems.
        def hijack_print(text, *args, **kwargs):
            if "•" in text:
                raise UnicodeEncodeError("test-codec", "", 0, 1, "")
            else:
                return StringPrinter.print(printer, text, *args, **kwargs)

        printer.print = hijack_print

        printer.clear()
        test_string = " he\tllo  world "
        print_spaces_tabs_in_unicode(printer,
                                     test_string,
                                     dict(sh.yield_tab_lengths(test_string)),
                                     "red")
        self.assertEqual(printer.string, ".he>llo..world.")
开发者ID:BigDproject,项目名称:coala,代码行数:32,代码来源:ConsoleInteractionTest.py

示例2: print_lines

# 需要导入模块: from coalib.bearlib.spacing.SpacingHelper import SpacingHelper [as 别名]
# 或者: from coalib.bearlib.spacing.SpacingHelper.SpacingHelper import yield_tab_lengths [as 别名]
def print_lines(console_printer,
                file_dict,
                section,
                sourcerange):
    """
    Prints the lines between the current and the result line. If needed
    they will be shortened.

    :param console_printer: Object to print messages on the console.
    :param file_dict:       A dictionary containing all files as values with
                            filenames as key.
    :param sourcerange:     The SourceRange object referring to the related
                            lines to print.
    """
    for i in range(sourcerange.start.line, sourcerange.end.line + 1):
        console_printer.print(format_lines(lines='', line_nr=i),
                              color=FILE_LINES_COLOR,
                              end='')
        line = file_dict[sourcerange.file][i - 1].rstrip("\n")
        tab_width = int(section.get('tab_width', 4))
        s = SpacingHelper(tab_width)
        tab_dict = dict(s.yield_tab_lengths(line))
        printed_chars = 0
        if i == sourcerange.start.line and sourcerange.start.column:
            print_spaces_tabs_in_unicode(
                console_printer, line[:sourcerange.start.column-1],
                tab_dict, FILE_LINES_COLOR)

            printed_chars = sourcerange.start.column-1

        if i == sourcerange.end.line and sourcerange.end.column:
            print_spaces_tabs_in_unicode(
                console_printer, line[printed_chars:sourcerange.end.column-1],
                tab_dict, HIGHLIGHTED_CODE_COLOR, printed_chars)

            print_spaces_tabs_in_unicode(
                console_printer, line[sourcerange.end.column-1:],
                tab_dict, FILE_LINES_COLOR, sourcerange.end.column)
            console_printer.print("")
        else:
            print_spaces_tabs_in_unicode(
                console_printer, line[printed_chars:], tab_dict,
                HIGHLIGHTED_CODE_COLOR, printed_chars)
            console_printer.print("")
开发者ID:djkonro,项目名称:coala,代码行数:46,代码来源:ConsoleInteraction.py


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