Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for enum.Flag in ReprHighlighter
enum.Flag allows more than one bit to be set, and its repr will show
something like <Permission.READ|WRITE: 3>.

For this to display correctly, we need to add the pipe symbol to the
tag regex.
  • Loading branch information
brakhane committed Feb 5, 2022
commit eb6b5ef87a762a2480981b616a49cf0bba617daf
2 changes: 1 addition & 1 deletion rich/highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ReprHighlighter(RegexHighlighter):

base_style = "repr."
highlights = [
r"(?P<tag_start>\<)(?P<tag_name>[\w\-\.\:]*)(?P<tag_contents>[\w\W]*?)(?P<tag_end>\>)",
r"(?P<tag_start>\<)(?P<tag_name>[\w\-\.\:\|]*)(?P<tag_contents>[\w\W]*?)(?P<tag_end>\>)",
r"(?P<attrib_name>[\w_]{1,50})=(?P<attrib_value>\"?[\w_]+\"?)?",
r"(?P<brace>[\{\[\(\)\]\}])",
_combine_regex(
Expand Down
10 changes: 10 additions & 0 deletions tests/test_highlighter.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ def test_wrong_type():
Span(4, 9, "repr.str"),
],
),
(
"<Permission.WRITE|READ: 3>",
[
Span(0, 1, "repr.tag_start"),
Span(1, 23, "repr.tag_name"),
Span(23, 25, "repr.tag_contents"),
Span(25, 26, "repr.tag_end"),
Span(24, 25, "repr.number"),
],
),
("( )", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
("[ ]", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
("{ }", [Span(0, 1, "repr.brace"), Span(2, 3, "repr.brace")]),
Expand Down