Skip to content

Commit 0b3e1ec

Browse files
committed
repr highlighter improvements
1 parent c12443e commit 0b3e1ec

File tree

5 files changed

+31
-8
lines changed

5 files changed

+31
-8
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.8.5] - 2020-03-29
9+
10+
### Changed
11+
12+
- Smarter number parsing regex for repr highlighter
13+
14+
### Added
15+
16+
- uuid highlighter for repr
17+
818
## [0.8.4] - 2020-03-28
919

1020
### Added

poetry.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "rich"
33
homepage = "https://github.com/willmcgugan/rich"
44
documentation = "https://rich.readthedocs.io/en/latest/"
5-
version = "0.8.4"
5+
version = "0.8.5"
66
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
77
authors = ["Will McGugan <willmcgugan@gmail.com>"]
88
license = "MIT"

rich/default_styles.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
"repr.bool_false": Style(color="bright_red", italic=True),
6666
"repr.none": Style(color="magenta", italic=True),
6767
"repr.url": Style(underline=True, color="bright_blue", bold=False),
68+
"repr.uuid": Style(color="bright_yellow", bold=False),
6869
"rule.line": Style(color="bright_green"),
6970
"rule.text": Style(),
7071
"repr.path": Style(color="magenta"),

rich/highlighter.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ class ReprHighlighter(RegexHighlighter):
8282
r"(?P<tag_start>\<)(?P<tag_name>\w*)(?P<tag_contents>.*?)(?P<tag_end>\>)",
8383
r"(?P<attrib_name>\w+?)=(?P<attrib_value>\"?\w+\"?)",
8484
r"(?P<bool_true>True)|(?P<bool_false>False)|(?P<none>None)",
85-
r"(?P<number>\-?[0-9]+\.?[0-9]*)",
85+
r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*\b)",
8686
r"(?P<number>0x[0-9a-f]*)",
8787
r"(?P<path>(\/\w+)+\/)",
8888
r"(?P<filename>\/\w*\..{3,4})\s",
89-
r"(?P<str>b?\'\'\'.*?\'\'\'|b?\'.*?\'|b?\"\"\".*?\"\"\"|b?\".*?\")",
89+
r"(?<!\\)(?P<str>b?\'\'\'.*?(?<!\\)\'\'\'|b?\'.*?(?<!\\)\'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",
9090
r"(?P<url>https?:\/\/\S*)",
91+
r"(?P<uuid>[a-fA-F0-9]{8}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{4}\-[a-fA-F0-9]{12})",
9192
]
9293

9394

@@ -104,6 +105,17 @@ class ReprHighlighter(RegexHighlighter):
104105
)
105106
)
106107

108+
console.print(highlighter(r'"Hello \"World!\"!"'))
109+
console.print(highlighter("b34a234-c3d42ef-3241"))
110+
console.print(highlighter("234234"))
111+
console.print(highlighter("0x234234"))
112+
console.print(highlighter("234234"))
113+
console.print(highlighter("234234 + 234234+-123"))
114+
115+
from uuid import uuid4
116+
117+
console.print(highlighter(str(uuid4())))
118+
107119
from .default_styles import MARKDOWN_STYLES
108120
from pprint import PrettyPrinter
109121

0 commit comments

Comments
 (0)