Repository: Textualize/rich

Issue:
[BUG] inconsistent coloring of complex numbers
Not sure if I should report this as a bug or as a feature request, but there is a very minor issue when printing complex numbers: the decimal part of the imaginary number is uncolored.

try for example:

```python
>>> from rich import pretty
>>> pretty.install()
>>> 3.05 + 2.06j
(3.05+2.06j)
```

![image](https://user-images.githubusercontent.com/15832886/164705103-eca06cf1-a1c3-41ed-973c-0a02d70c8249.png)

I tried this on Linux, rich version 12.2.0. This "bug" appears both in the terminal (alacritty in my case) as well as in jupyter notebooks, which makes me believe it is platform independent.


Discussion:
Rich doesn't have any explicit supports for complex numbers. If you're adept with regexes, you could add it to highlighter.py
Thanks will, I'll try that.

However, respectfully, complex numbers are natively supported by python so in my opinion they should also be natively supported by the rich pretty printer. Having to specify the same regex over and over in interactive sessions (which many scientific exploratory notebooks are for example) is not really user friendly...

Like I said, it's a very minor issue and I understand that adding this feature might yield unnecessary overhead on your side. If that's the case just disregard it, but I think as rich will become more popular in the scientific community you might get this question again.
I was actually suggesting that you could contribute this to highlighter.py in the repo, if you could come up with the regex. I'm happy to add it.
Sure! I'll give it a shot 🙂

Resolving patch:
diff --git a/rich/default_styles.py b/rich/default_styles.py
--- a/rich/default_styles.py
+++ b/rich/default_styles.py
@@ -78,6 +78,7 @@
     "repr.attrib_equal": Style(bold=True),
     "repr.attrib_value": Style(color="magenta", italic=False),
     "repr.number": Style(color="cyan", bold=True, italic=False),
+    "repr.number_complex": Style(color="cyan", bold=True, italic=False),  # same
     "repr.bool_true": Style(color="bright_green", italic=True),
     "repr.bool_false": Style(color="bright_red", italic=True),
     "repr.none": Style(color="magenta", italic=True),
diff --git a/rich/highlighter.py b/rich/highlighter.py
--- a/rich/highlighter.py
+++ b/rich/highlighter.py
@@ -94,6 +94,7 @@ class ReprHighlighter(RegexHighlighter):
             r"(?P<call>[\w.]*?)\(",
             r"\b(?P<bool_true>True)\b|\b(?P<bool_false>False)\b|\b(?P<none>None)\b",
             r"(?P<ellipsis>\.\.\.)",
+            r"(?P<number_complex>(?<!\w)(?:\-?[0-9]+\.?[0-9]*(?:e[-+]?\d+?)?)(?:[-+](?:[0-9]+\.?[0-9]*(?:e[-+]?\d+)?))?j)",
             r"(?P<number>(?<!\w)\-?[0-9]+\.?[0-9]*(e[-+]?\d+?)?\b|0x[0-9a-fA-F]*)",
             r"(?P<path>\B(/[-\w._+]+)*\/)(?P<filename>[-\w._+]*)?",
             r"(?<![\\\w])(?P<str>b?'''.*?(?<!\\)'''|b?'.*?(?<!\\)'|b?\"\"\".*?(?<!\\)\"\"\"|b?\".*?(?<!\\)\")",


Test patch:
diff --git a/tests/test_highlighter.py b/tests/test_highlighter.py
--- a/tests/test_highlighter.py
+++ b/tests/test_highlighter.py
@@ -59,6 +59,40 @@ def test_wrong_type():
     (" 1.2 ", [Span(1, 4, "repr.number")]),
     (" 0xff ", [Span(1, 5, "repr.number")]),
     (" 1e10 ", [Span(1, 5, "repr.number")]),
+    (" 1j ", [Span(1, 3, "repr.number_complex")]),
+    (" 3.14j ", [Span(1, 6, "repr.number_complex")]),
+    (
+        " (3.14+2.06j) ",
+        [
+            Span(1, 2, "repr.brace"),
+            Span(12, 13, "repr.brace"),
+            Span(2, 12, "repr.number_complex"),
+        ],
+    ),
+    (
+        " (3+2j) ",
+        [
+            Span(1, 2, "repr.brace"),
+            Span(6, 7, "repr.brace"),
+            Span(2, 6, "repr.number_complex"),
+        ],
+    ),
+    (
+        " (123456.4321-1234.5678j) ",
+        [
+            Span(1, 2, "repr.brace"),
+            Span(24, 25, "repr.brace"),
+            Span(2, 24, "repr.number_complex"),
+        ],
+    ),
+    (
+        " (-123123-2.1312342342423422e+25j) ",
+        [
+            Span(1, 2, "repr.brace"),
+            Span(33, 34, "repr.brace"),
+            Span(2, 33, "repr.number_complex"),
+        ],
+    ),
     (" /foo ", [Span(1, 2, "repr.path"), Span(2, 5, "repr.filename")]),
     (" /foo/bar.html ", [Span(1, 6, "repr.path"), Span(6, 14, "repr.filename")]),
     ("01-23-45-67-89-AB", [Span(0, 17, "repr.eui48")]),  # 6x2 hyphen