output all_lines[lineno] along with carets
(lineno)
| 654 | significant_lines.discard(len(all_lines)) |
| 655 | |
| 656 | def output_line(lineno): |
| 657 | """output all_lines[lineno] along with carets""" |
| 658 | result.append(all_lines[lineno] + "\n") |
| 659 | if not show_carets: |
| 660 | return |
| 661 | num_spaces = len(all_lines[lineno]) - len(all_lines[lineno].lstrip()) |
| 662 | carets = [] |
| 663 | num_carets = dp_end_offset if lineno == len(all_lines) - 1 else _display_width(all_lines[lineno]) |
| 664 | # compute caret character for each position |
| 665 | for col in range(num_carets): |
| 666 | if col < num_spaces or (lineno == 0 and col < dp_start_offset): |
| 667 | # before first non-ws char of the line, or before start of instruction |
| 668 | carets.append(' ') |
| 669 | elif anchors and ( |
| 670 | lineno > anchors.left_end_lineno or |
| 671 | (lineno == anchors.left_end_lineno and col >= anchors_left_end_offset) |
| 672 | ) and ( |
| 673 | lineno < anchors.right_start_lineno or |
| 674 | (lineno == anchors.right_start_lineno and col < anchors_right_start_offset) |
| 675 | ): |
| 676 | # within anchors |
| 677 | carets.append(secondary_char) |
| 678 | else: |
| 679 | carets.append(primary_char) |
| 680 | if colorize: |
| 681 | # Replace the previous line with a red version of it only in the parts covered |
| 682 | # by the carets. |
| 683 | line = result[-1] |
| 684 | colorized_line_parts = [] |
| 685 | colorized_carets_parts = [] |
| 686 | |
| 687 | for color, group in itertools.groupby(itertools.zip_longest(line, carets, fillvalue=""), key=lambda x: x[1]): |
| 688 | caret_group = list(group) |
| 689 | if color == "^": |
| 690 | colorized_line_parts.append(theme.error_highlight + "".join(char for char, _ in caret_group) + theme.reset) |
| 691 | colorized_carets_parts.append(theme.error_highlight + "".join(caret for _, caret in caret_group) + theme.reset) |
| 692 | elif color == "~": |
| 693 | colorized_line_parts.append(theme.error_range + "".join(char for char, _ in caret_group) + theme.reset) |
| 694 | colorized_carets_parts.append(theme.error_range + "".join(caret for _, caret in caret_group) + theme.reset) |
| 695 | else: |
| 696 | colorized_line_parts.append("".join(char for char, _ in caret_group)) |
| 697 | colorized_carets_parts.append("".join(caret for _, caret in caret_group)) |
| 698 | |
| 699 | colorized_line = "".join(colorized_line_parts) |
| 700 | colorized_carets = "".join(colorized_carets_parts) |
| 701 | result[-1] = colorized_line |
| 702 | result.append(colorized_carets + "\n") |
| 703 | else: |
| 704 | result.append("".join(carets) + "\n") |
| 705 | |
| 706 | # display significant lines |
| 707 | sig_lines_list = sorted(significant_lines) |