Colorize an output line by highlighting the status and error code.
(self, error: str)
| 785 | return new_messages |
| 786 | |
| 787 | def colorize(self, error: str) -> str: |
| 788 | """Colorize an output line by highlighting the status and error code.""" |
| 789 | # TODO: detecting source code highlights through an indent can be surprising. |
| 790 | if error.startswith(CODE_START): |
| 791 | if not self.is_marker_line(error): |
| 792 | return self.style(error, "none", dim=True) |
| 793 | return self.style(error, "red") |
| 794 | elif ": error:" in error: |
| 795 | loc, msg = error.split("error:", maxsplit=1) |
| 796 | if self.hide_error_codes: |
| 797 | return ( |
| 798 | loc + self.style("error:", "red", bold=True) + self.highlight_quote_groups(msg) |
| 799 | ) |
| 800 | codepos = msg.rfind("[") |
| 801 | if codepos != -1: |
| 802 | code = msg[codepos:] |
| 803 | msg = msg[:codepos] |
| 804 | else: |
| 805 | code = "" # no error code specified |
| 806 | return ( |
| 807 | loc |
| 808 | + self.style("error:", "red", bold=True) |
| 809 | + self.highlight_quote_groups(msg) |
| 810 | + self.style(code, "yellow") |
| 811 | ) |
| 812 | elif ": note:" in error: |
| 813 | loc, msg = error.split("note:", maxsplit=1) |
| 814 | formatted = self.highlight_quote_groups(self.underline_link(msg)) |
| 815 | return loc + self.style("note:", "blue") + formatted |
| 816 | else: |
| 817 | return error |
| 818 | |
| 819 | def highlight_quote_groups(self, msg: str) -> str: |
| 820 | """Make groups quoted with double quotes bold (including quotes). |
no test coverage detected